diff options
author | jaseg <code@jaseg.net> | 2017-05-26 14:07:06 +0200 |
---|---|---|
committer | jaseg <code@jaseg.net> | 2017-05-26 14:07:06 +0200 |
commit | 36404a2a4079a19c3c763535f9e73e46f2f46159 (patch) | |
tree | e1ec3376089bbe842e1ad7382416b3b840ef2f72 | |
parent | 11f534897c83e81bd548fbfbb494e84d8a852b54 (diff) | |
download | python-mpv-36404a2a4079a19c3c763535f9e73e46f2f46159.tar.gz python-mpv-36404a2a4079a19c3c763535f9e73e46f2f46159.tar.bz2 python-mpv-36404a2a4079a19c3c763535f9e73e46f2f46159.zip |
Add regression test for #26
-rwxr-xr-x | mpv-test.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/mpv-test.py b/mpv-test.py index 62eb8fd..eb3c13f 100755 --- a/mpv-test.py +++ b/mpv-test.py @@ -253,7 +253,6 @@ class RegressionTests(unittest.TestCase): `unobserve_property`. """ handler = mock.Mock() - handler.observed_mpv_properties = [] m = mpv.MPV() m.observe_property('loop', handler) @@ -270,6 +269,35 @@ class RegressionTests(unittest.TestCase): finally: m.terminate() + def test_instance_method_property_observer(self): + """ + Ensure that bound method objects can be used as property observers. + See issue #26 + """ + handler = mock.Mock() + m = mpv.MPV() + + class T(object): + def t(self, *args, **kw): + handler(*args, **kw) + t = T() + + m.loop = 'inf' + + m.observe_property('loop', t.t) + + m.loop = 'no' + self.assertEqual(m.loop, 'no') + m.loop = 'inf' + self.assertEqual(m.loop, 'inf') + + time.sleep(0.02) + m.unobserve_property('loop', t.t) + + m.loop = 'no' + m.loop = 'inf' + m.terminate() # needed for synchronization of event thread + handler.assert_has_calls([mock.call('loop', 'no'), mock.call('loop', 'inf')]) if __name__ == '__main__': |