summaryrefslogtreecommitdiff
path: root/mpv-test.py
diff options
context:
space:
mode:
authorjaseg <code@jaseg.net>2017-08-21 15:36:03 +0200
committerjaseg <code@jaseg.net>2017-08-21 15:36:03 +0200
commit2ca5c7b9c88960994a9b1494f46bd01c0388a21f (patch)
tree9e35987d3ffcf389954cb748b62ca82f88461bce /mpv-test.py
parent14783b2193759ee5a45654634a0bb863576df4d9 (diff)
downloadpython-mpv-2ca5c7b9c88960994a9b1494f46bd01c0388a21f.tar.gz
python-mpv-2ca5c7b9c88960994a9b1494f46bd01c0388a21f.tar.bz2
python-mpv-2ca5c7b9c88960994a9b1494f46bd01c0388a21f.zip
Add on_key_press
Diffstat (limited to 'mpv-test.py')
-rwxr-xr-xmpv-test.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/mpv-test.py b/mpv-test.py
index d829dba..96bf225 100755
--- a/mpv-test.py
+++ b/mpv-test.py
@@ -316,6 +316,41 @@ class KeyBindingTest(MpvTestCase):
self.assertNotIn(b('b'), self.m._key_binding_handlers)
self.assertIn(b('c'), self.m._key_binding_handlers)
+ def test_register_simple_decorator_fun_chaining(self):
+ b = mpv.MPV._binding_name
+
+ handler1, handler2 = mock.Mock(), mock.Mock()
+
+ @self.m.on_key_press('a')
+ @self.m.on_key_press('b')
+ def reg_test_fun(*args, **kwargs):
+ handler1(*args, **kwargs)
+
+ @self.m.on_key_press('c')
+ def reg_test_fun_2_stay_intact(*args, **kwargs):
+ 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')
+ handler1.assert_has_calls([ mock.call() ])
+ handler2.assert_has_calls([])
+ handler1.reset_mock()
+ self.m._key_binding_handlers[b('b')]('p-', 'q')
+ handler1.assert_has_calls([ mock.call() ])
+ handler2.assert_has_calls([])
+ self.m._key_binding_handlers[b('c')]('p-', 'q')
+ handler1.assert_has_calls([])
+ handler2.assert_has_calls([ mock.call() ])
+
+ 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)
+
class TestLifecycle(unittest.TestCase):
def test_create_destroy(self):
thread_names = lambda: [ t.name for t in threading.enumerate() ]