ya2 · news · projects · code · about

renamed lib to ya2
[pmachines.git] / tests / lib / engine / test_event.py
CommitLineData
0f9675ba
FC
1from pathlib import Path
2import sys
3if '' in sys.path: sys.path.remove('')
4sys.path.append(str(Path(__file__).parent.parent.parent))
5from unittest import TestCase
6from unittest.mock import patch, create_autospec
7from panda3d.core import loadPrcFileData, GraphicsWindow
53ddf3c3
FC
8from ya2.engine.engine import Engine
9from ya2.engine.event import EngineEvent
0f9675ba
FC
10
11
12class 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')