summaryrefslogtreecommitdiff
path: root/mpv-test.py
diff options
context:
space:
mode:
authorjaseg <code@jaseg.net>2016-08-13 19:07:44 +0200
committerjaseg <code@jaseg.net>2016-08-13 19:14:14 +0200
commitde7b6711035a187492f9753fc8808d9c2ad1dd55 (patch)
tree92feb473a2e3b258db1ae7e55465938bb550b49a /mpv-test.py
parent4d6c17d342582827f8989331f8800fd96d735e8b (diff)
downloadpython-mpv-de7b6711035a187492f9753fc8808d9c2ad1dd55.tar.gz
python-mpv-de7b6711035a187492f9753fc8808d9c2ad1dd55.tar.bz2
python-mpv-de7b6711035a187492f9753fc8808d9c2ad1dd55.zip
Finally add node handling, fix ALL THE THINGS
* New node handling * Add remaining properties * Improve property type handling (no more ynbool!) * Add pröper option access * Add a whole bunch of tests
Diffstat (limited to 'mpv-test.py')
-rwxr-xr-xmpv-test.py77
1 files changed, 48 insertions, 29 deletions
diff --git a/mpv-test.py b/mpv-test.py
index f7a80ee..2be2735 100755
--- a/mpv-test.py
+++ b/mpv-test.py
@@ -31,7 +31,7 @@ class TestProperties(unittest.TestCase):
self.m = mpv.MPV()
def test_sanity(self):
- for name, (ptype, access) in mpv.ALL_PROPERTIES.items():
+ for name, (ptype, access, *_args) in mpv.ALL_PROPERTIES.items():
self.assertTrue('r' in access or 'w' in access)
self.assertRegex(name, '^[-0-9a-z]+$')
# Types and MpvFormat values
@@ -59,7 +59,7 @@ class TestProperties(unittest.TestCase):
self.m.play(TESTVID)
while self.m.core_idle:
time.sleep(0.05)
- for name, (ptype, access) in sorted(mpv.ALL_PROPERTIES.items()):
+ for name, (ptype, access, *_args) in sorted(mpv.ALL_PROPERTIES.items()):
if 'r' in access:
name = name.replace('-', '_')
with self.subTest(property_name=name):
@@ -72,34 +72,54 @@ class TestProperties(unittest.TestCase):
self.assertEqual(type(rv), type(ptype()))
def test_write(self):
- for name, (ptype, access) in sorted(mpv.ALL_PROPERTIES.items()):
+ self.m.loop = 'inf'
+ self.m.play(TESTVID)
+ while self.m.core_idle:
+ time.sleep(0.05)
+ for name, (ptype, access, *_args) in sorted(mpv.ALL_PROPERTIES.items()):
if 'w' in access:
name = name.replace('-', '_')
+ with self.subTest(property_name=name):
+ with self.swallow_mpv_errors([
+ mpv.ErrorCode.PROPERTY_UNAVAILABLE,
+ mpv.ErrorCode.PROPERTY_ERROR,
+ mpv.ErrorCode.PROPERTY_FORMAT]): # 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, 1)
+ setattr(self.m, name, -1)
+ elif ptype == float:
+ setattr(self.m, name, 0.0)
+ setattr(self.m, name, 1)
+ setattr(self.m, name, 1.0)
+ setattr(self.m, name, -1.0)
+ setattr(self.m, name, math.nan)
+ elif ptype == str:
+ setattr(self.m, name, 'foo')
+ setattr(self.m, name, '')
+ setattr(self.m, name, 'bazbazbaz'*1000)
+ elif ptype == bytes:
+ setattr(self.m, name, b'foo')
+ setattr(self.m, name, b'')
+ setattr(self.m, name, b'bazbazbaz'*1000)
+ elif ptype == bool:
+ setattr(self.m, name, True)
+ setattr(self.m, name, False)
+
+ def test_option_read(self):
+ self.m.loop = 'inf'
+ self.m.play(TESTVID)
+ while self.m.core_idle:
+ time.sleep(0.05)
+ for name in sorted(self.m):
+ with self.subTest(option_name=name):
with self.swallow_mpv_errors([
mpv.ErrorCode.PROPERTY_UNAVAILABLE,
- mpv.ErrorCode.PROPERTY_ERROR,
- mpv.ErrorCode.PROPERTY_FORMAT]): # 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, 1)
- setattr(self.m, name, -1)
- elif ptype == float:
- setattr(self.m, name, 0.0)
- setattr(self.m, name, 1)
- setattr(self.m, name, 1.0)
- setattr(self.m, name, -1.0)
- setattr(self.m, name, math.nan)
- elif ptype == str:
- setattr(self.m, name, 'foo')
- setattr(self.m, name, '')
- setattr(self.m, name, 'bazbazbaz'*1000)
- elif ptype == bytes:
- setattr(self.m, name, b'foo')
- setattr(self.m, name, b'')
- setattr(self.m, name, b'bazbazbaz'*1000)
- elif ptype == bool:
- setattr(self.m, name, True)
- setattr(self.m, name, False)
+ mpv.ErrorCode.PROPERTY_NOT_FOUND,
+ mpv.ErrorCode.PROPERTY_ERROR]):
+ self.m[name]
+
+
def tearDown(self):
del self.m
@@ -166,7 +186,7 @@ class TestLifecycle(unittest.TestCase):
mock.call({'reply_userdata': 0, 'error': 0, 'event_id': 11, 'event': None}),
mock.call({'reply_userdata': 0, 'error': 0, 'event_id': 1, 'event': None})
], any_order=True)
-
+
def test_log_handler(self):
handler = mock.Mock()
m = mpv.MPV('no-video', log_handler=handler)
@@ -176,8 +196,7 @@ class TestLifecycle(unittest.TestCase):
handler.assert_has_calls([
mock.call('info', 'cplayer', 'Playing: test.webm'),
mock.call('info', 'cplayer', ' Video --vid=1 (*) (vp8)'),
- mock.call('fatal', 'cplayer', 'No video or audio streams selected.'),
- mock.call('info', 'cplayer', '')])
+ mock.call('fatal', 'cplayer', 'No video or audio streams selected.')])
if __name__ == '__main__':