ya2 · news · projects · code · about

66a8c8395d056971d469500213c55c9d93737f13
[pmachines.git] / tests / ya2 / utils / test_audio.py
1 from panda3d.core import load_prc_file_data
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
21 def test_audio(self):
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)