From a80f638732cdcd6837b3a8818ab7822993bd42b4 Mon Sep 17 00:00:00 2001 From: jaseg Date: Mon, 3 Jul 2017 13:13:50 +0200 Subject: Make compatible with libmpv 0.22.0 --- mpv-test.py | 15 +++++++++------ mpv.py | 17 +++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/mpv-test.py b/mpv-test.py index 10561d5..613280a 100755 --- a/mpv-test.py +++ b/mpv-test.py @@ -64,7 +64,8 @@ class TestProperties(unittest.TestCase): continue # Property seems to be an aliased option if prop in ('ad-spdif-dtshd', 'softvol', 'heartbeat-cmd', 'input-x11-keyboard', 'vo-vdpau-queuetime-windowed', 'demuxer-max-packets', '3dlut-size', 'right-alt-gr', - 'mkv-subtitle-preroll', 'dtshd', 'softvol-max'): + 'mkv-subtitle-preroll', 'dtshd', 'softvol-max', 'pulse-sink', + 'alsa-device', 'oss-device', 'ao-defaults', 'vo-defaults'): continue # Property seems to be an aliased option that was forgotten in MPV.options prop = prop.replace('-', '_') self.assertTrue(prop in ledir, 'Property {} not found'.format(prop)) @@ -100,13 +101,15 @@ class TestProperties(unittest.TestCase): mpv.ErrorCode.PROPERTY_FORMAT, mpv.ErrorCode.PROPERTY_NOT_FOUND]): # This is due to a bug with option-mapped properties in mpv 0.18.1 if ptype == int: - setattr(self.m, name, 0) + setattr(self.m, name, 100) setattr(self.m, name, 1) + setattr(self.m, name, 0) setattr(self.m, name, -1) elif ptype == float: - setattr(self.m, name, 0.0) + # Some properties have range checks done on their values setattr(self.m, name, 1) setattr(self.m, name, 1.0) + setattr(self.m, name, 0.0) setattr(self.m, name, -1.0) setattr(self.m, name, float('nan')) elif ptype == str: @@ -158,7 +161,7 @@ class ObservePropertyTest(unittest.TestCase): 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')]) + handler.assert_has_calls([mock.call('loop', False), mock.call('loop', 'inf')]) def test_property_observer_decorator(self): handler = mock.Mock() @@ -186,7 +189,7 @@ class ObservePropertyTest(unittest.TestCase): # which these properties were previously accessed. Thus, any_order. handler.assert_has_calls([ mock.call('mute', False), - mock.call('loop', 'no')], + mock.call('loop', False)], any_order=True) handler.reset_mock() @@ -318,7 +321,7 @@ class RegressionTests(unittest.TestCase): 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')]) + handler.assert_has_calls([mock.call('loop', False), mock.call('loop', 'inf')]) if __name__ == '__main__': diff --git a/mpv.py b/mpv.py index 723c519..7a7c1a2 100644 --- a/mpv.py +++ b/mpv.py @@ -971,17 +971,14 @@ class MPV(object): def _set_property(self, name, value, proptype=str): ename = name.encode('utf-8') - try: - if proptype is MpvFormat.NODE: - if isinstance(value, (list, set, dict)): - _1, _2, _3, pointer = _make_node_str_list(value) - _mpv_set_property(self.handle, ename, MpvFormat.NODE, pointer) - else: - _mpv_set_property_string(self.handle, ename, _mpv_coax_proptype(value, str)) + if proptype is MpvFormat.NODE: + if isinstance(value, (list, set, dict)): + _1, _2, _3, pointer = _make_node_str_list(value) + _mpv_set_property(self.handle, ename, MpvFormat.NODE, pointer) else: - _mpv_set_property_string(self.handle, ename, _mpv_coax_proptype(value, proptype)) - except TypeError as e: - raise TypeError("Error setting MPV {} property {}".format(proptype, name)) from e + _mpv_set_property_string(self.handle, ename, _mpv_coax_proptype(value, str)) + else: + _mpv_set_property_string(self.handle, ename, _mpv_coax_proptype(value, proptype)) # Dict-like option access def __getitem__(self, name, file_local=False): -- cgit