summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <code@jaseg.net>2020-07-16 13:01:52 +0200
committerjaseg <code@jaseg.net>2020-07-16 13:01:52 +0200
commitd177064d125bec1f302b5a05803618824eafce1a (patch)
tree982032d6a88695b75db93361a1e03bfeee9ed39f
parent9c33d0117e5984bff5a2650d8f69202dd7462b06 (diff)
downloadpython-mpv-d177064d125bec1f302b5a05803618824eafce1a.tar.gz
python-mpv-d177064d125bec1f302b5a05803618824eafce1a.tar.bz2
python-mpv-d177064d125bec1f302b5a05803618824eafce1a.zip
tests: improve key binding tests with loopback test
-rwxr-xr-xmpv-test.py34
1 files changed, 24 insertions, 10 deletions
diff --git a/mpv-test.py b/mpv-test.py
index 2a0bc41..aca6952 100755
--- a/mpv-test.py
+++ b/mpv-test.py
@@ -377,7 +377,9 @@ class KeyBindingTest(MpvTestCase):
self.assertIn(b('c'), self.m._key_binding_handlers)
def test_register_simple_decorator_fun_chaining(self):
- b = mpv.MPV._binding_name
+ self.m.loop = 'inf'
+ self.m.play(TESTVID)
+ self.m.wait_for_property('core-idle', lambda idle: not idle)
handler1, handler2 = mock.Mock(), mock.Mock()
@@ -391,25 +393,37 @@ class KeyBindingTest(MpvTestCase):
handler2(*args, **kwargs)
self.assertEqual(reg_test_fun.mpv_key_bindings, ['b', 'a'])
- self.assertIn(b('a'), self.m._key_binding_handlers)
- self.assertIn(b('b'), self.m._key_binding_handlers)
- self.assertIn(b('c'), self.m._key_binding_handlers)
- self.m._key_binding_handlers[b('a')]('p-', 'q', None)
+ def keypress_and_sync(key):
+ self.m.keypress(key)
+ self.m.frame_step()
+ self.m.wait_for_property('pause', lambda paused: paused)
+
+ keypress_and_sync('a')
handler1.assert_has_calls([ mock.call() ])
handler2.assert_has_calls([])
handler1.reset_mock()
- self.m._key_binding_handlers[b('b')]('p-', 'q', None)
+
+ keypress_and_sync('x')
+ keypress_and_sync('X')
+ keypress_and_sync('b')
handler1.assert_has_calls([ mock.call() ])
handler2.assert_has_calls([])
- self.m._key_binding_handlers[b('c')]('p-', 'q', None)
+ handler1.reset_mock()
+
+ keypress_and_sync('c')
+ keypress_and_sync('B')
handler1.assert_has_calls([])
handler2.assert_has_calls([ mock.call() ])
+ handler2.reset_mock()
reg_test_fun.unregister_mpv_key_bindings()
- self.assertNotIn(b('a'), self.m._key_binding_handlers)
- self.assertNotIn(b('b'), self.m._key_binding_handlers)
- self.assertIn(b('c'), self.m._key_binding_handlers)
+ keypress_and_sync('a')
+ keypress_and_sync('c')
+ keypress_and_sync('x')
+ keypress_and_sync('A')
+ handler1.assert_has_calls([])
+ handler2.assert_has_calls([ mock.call() ])
class TestStreams(unittest.TestCase):
@devnull_libmpv()