summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Deacalion Stevens <matt@dirtymonkey.co.uk>2017-05-21 10:58:36 +0100
committerMatt Deacalion Stevens <matt@dirtymonkey.co.uk>2017-05-21 10:58:36 +0100
commitb1f81ac56184a172f093b0a640890de9ded405d7 (patch)
tree6e953ac618bdedc656dcfbd09fc83a76fd9417dc
parent5ca3a0250cd52d01e949d7f998c49db32480b1ca (diff)
downloadpython-mpv-b1f81ac56184a172f093b0a640890de9ded405d7.tar.gz
python-mpv-b1f81ac56184a172f093b0a640890de9ded405d7.tar.bz2
python-mpv-b1f81ac56184a172f093b0a640890de9ded405d7.zip
Fix `unobserve_property` RuntimeError
-rwxr-xr-xmpv-test.py27
-rw-r--r--mpv.py11
2 files changed, 36 insertions, 2 deletions
diff --git a/mpv-test.py b/mpv-test.py
index b2bea2e..21cb8cf 100755
--- a/mpv-test.py
+++ b/mpv-test.py
@@ -206,5 +206,32 @@ class TestLifecycle(unittest.TestCase):
handler.assert_any_call('info', 'cplayer', 'Playing: ./test.webm')
+class RegressionTests(unittest.TestCase):
+
+ def test_unobserve_property_runtime_error(self):
+ """
+ Ensure a `RuntimeError` is not thrown within
+ `unobserve_property`.
+ """
+ handler = mock.Mock()
+ handler.observed_mpv_properties = []
+
+ m = mpv.MPV()
+ m.observe_property('loop', handler)
+
+ try:
+ m.unobserve_property('loop', handler)
+ except RuntimeError:
+ self.fail(
+ """
+ "RuntimeError" exception thrown within
+ `unobserve_property`
+ """,
+ )
+ finally:
+ m.terminate()
+
+
+
if __name__ == '__main__':
unittest.main()
diff --git a/mpv.py b/mpv.py
index 600e7c6..0782cec 100644
--- a/mpv.py
+++ b/mpv.py
@@ -681,8 +681,15 @@ class MPV(object):
fmts = self._property_handlers[name]
for fmt, handlers in fmts.items():
handlers.remove(handler)
- if not handlers:
- del fmts[fmt]
+
+ # remove all properties that have no handlers
+ empty_props = [
+ fmt for fmt, handler in fmts.items() if not handler
+ ]
+
+ for fmt in empty_props:
+ del fmts[fmt]
+
if not fmts:
_mpv_unobserve_property(self._event_handle, hash(name)&0xffffffffffffffff)