Commit | Line | Data |
---|---|---|
7ac52030 | 1 | from panda3d.core import load_prc_file_data, AudioSound |
f62d6fc5 FC |
2 | load_prc_file_data('', 'window-type none') |
3 | from pathlib import Path | |
4 | import sys | |
5 | if '' in sys.path: sys.path.remove('') | |
6 | sys.path.append(str(Path(__file__).parent.parent.parent)) | |
7 | from unittest import TestCase | |
8 | from unittest.mock import patch | |
9 | from direct.showbase.ShowBase import ShowBase | |
10 | from ya2.utils.audio import AudioTools | |
11 | ||
12 | ||
13 | class AudioTests(TestCase): | |
14 | ||
15 | def setUp(self): | |
16 | self.__app = ShowBase() | |
17 | ||
18 | def tearDown(self): | |
19 | self.__app.destroy() | |
20 | ||
7ac52030 | 21 | def test_volume(self): |
f62d6fc5 FC |
22 | with (patch.object(base, 'musicManager', autospec=True) as m, |
23 | patch.object(base, 'sfxManagerList', autospec=True) as s): | |
24 | AudioTools.set_volume(.8) | |
25 | m.set_volume.assert_called_once() | |
26 | m_args = m.set_volume.call_args_list[0].args | |
27 | self.assertAlmostEqual(m_args[0], .64, delta=.01) | |
28 | self.assertEqual(len(m_args), 1) | |
29 | s[0].set_volume.assert_called_once() | |
30 | s_args = s[0].set_volume.call_args_list[0].args | |
31 | self.assertAlmostEqual(s_args[0], .8, delta=.01) | |
32 | self.assertEqual(len(s_args), 1) | |
7ac52030 FC |
33 | |
34 | def test_loading(self): | |
35 | s = AudioTools.load_sfx('assets/audio/sfx/rollover.ogg') | |
36 | self.assertIsInstance(s, AudioSound) |