d1e030a827bea113fd66e7bebfddbcbe449a1bdc
1 from pathlib
import Path
3 if '' in sys
.path
: sys
.path
.remove('')
4 sys
.path
.append(str(Path(__file__
).parent
.parent
.parent
))
5 from unittest
import TestCase
6 from unittest
.mock
import patch
, create_autospec
7 from panda3d
.core
import loadPrcFileData
, GraphicsWindow
8 from ya2
.engine
.engine
import Engine
9 from ya2
.engine
.event
import EngineEvent
12 class EngineEventTests(TestCase
):
15 loadPrcFileData('', 'window-type none')
16 loadPrcFileData('', 'audio-library-name null')
18 EngineEvent(self
.eng
, True)
20 def tearDown(self
): self
.eng
.destroy()
22 def test_init(self
): self
.assertIsInstance(self
.eng
.event
, EngineEvent
)
24 def test_key2desc(self
):
25 with
patch('builtins.base') as patched_base
:
26 # we need to patch it to run without base.win
27 self
.assertEqual(str(self
.eng
.event
.key2desc('x')), 'x')
28 base
.win
.get_keyboard_map().get_mapped_button_label
= create_autospec(GraphicsWindow
)
29 base
.win
.get_keyboard_map().get_mapped_button_label
.return_value
= 'x'
30 self
.assertEqual(self
.eng
.event
.key2desc('raw-x'), 'x')
32 def test_desc2key(self
):
33 with
patch('builtins.base') as patched_base
:
34 self
.assertEqual(self
.eng
.event
.desc2key('x'), 'x')