Commit | Line | Data |
---|---|---|
0f9675ba FC |
1 | from pathlib import Path |
2 | import sys | |
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 | |
53ddf3c3 FC |
8 | from ya2.engine.engine import Engine |
9 | from ya2.engine.event import EngineEvent | |
0f9675ba FC |
10 | |
11 | ||
12 | class EngineEventTests(TestCase): | |
13 | ||
14 | def setUp(self): | |
15 | loadPrcFileData('', 'window-type none') | |
16 | loadPrcFileData('', 'audio-library-name null') | |
17 | self.eng = Engine() | |
18 | EngineEvent(self.eng, True) | |
19 | ||
20 | def tearDown(self): self.eng.destroy() | |
21 | ||
22 | def test_init(self): self.assertIsInstance(self.eng.event, EngineEvent) | |
23 | ||
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') | |
31 | ||
32 | def test_desc2key(self): | |
33 | with patch('builtins.base') as patched_base: | |
34 | self.assertEqual(self.eng.event.desc2key('x'), 'x') |