summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xmpv-test.py41
-rw-r--r--mpv.py2
-rw-r--r--test.srt9
3 files changed, 44 insertions, 8 deletions
diff --git a/mpv-test.py b/mpv-test.py
index b9a3d65..031b806 100755
--- a/mpv-test.py
+++ b/mpv-test.py
@@ -544,6 +544,8 @@ class TestLifecycle(unittest.TestCase):
def test_log_handler(self):
handler = mock.Mock()
+ self.disp = Xvfb()
+ self.disp.start()
m = mpv.MPV(video=False, log_handler=handler)
m.play(TESTVID)
m.wait_for_playback()
@@ -554,6 +556,32 @@ class TestLifecycle(unittest.TestCase):
break
else:
self.fail('"Playing: foo..." call not found in log handler calls: '+','.join(repr(call) for call in handler.mock_calls))
+ self.disp.stop()
+
+
+class CommandTests(MpvTestCase):
+
+ def test_loadfile_with_subtitles(self):
+ handler = mock.Mock()
+ self.m.property_observer('sub-text')(handler)
+
+ self.m.loadfile(TESTVID, sub_file='test.srt')
+
+ self.m.wait_for_playback()
+ handler.assert_any_call('sub-text', 'This is\na subtitle test.')
+ handler.assert_any_call('sub-text', 'This is the second subtitle line.')
+
+ def test_sub_add(self):
+ handler = mock.Mock()
+ self.m.property_observer('sub-text')(handler)
+
+ self.m.loadfile(TESTVID)
+ self.m.wait_for_property('core-idle', lambda x: not x)
+ self.m.sub_add('test.srt')
+
+ self.m.wait_for_playback()
+ handler.assert_any_call('sub-text', 'This is\na subtitle test.')
+ handler.assert_any_call('sub-text', 'This is the second subtitle line.')
class RegressionTests(MpvTestCase):
@@ -591,20 +619,19 @@ class RegressionTests(MpvTestCase):
t = T()
m.loop = 'inf'
+ time.sleep(0.5)
m.observe_property('loop', t.t)
+ time.sleep(0.5)
m.loop = False
- self.assertEqual(m.loop, False)
- # Wait for tick. AFAICT property events are only generated at regular
- # intervals, and if we change a property too fast we don't get any
- # events. This is a limitation of the upstream API.
- time.sleep(0.01)
+ time.sleep(0.5)
+
m.loop = 'inf'
- self.assertEqual(m.loop, True)
+ time.sleep(0.5)
- time.sleep(0.02)
m.unobserve_property('loop', t.t)
+ time.sleep(0.5)
m.loop = False
m.loop = 'inf'
diff --git a/mpv.py b/mpv.py
index b0d6917..988e360 100644
--- a/mpv.py
+++ b/mpv.py
@@ -921,7 +921,7 @@ class MPV(object):
@staticmethod
def _encode_options(options):
- return ','.join('{}={}'.format(str(key), str(val)) for key, val in options.items())
+ return ','.join('{}={}'.format(_py_to_mpv(str(key)), str(val)) for key, val in options.items())
def loadfile(self, filename, mode='replace', **options):
"""Mapped mpv loadfile command, see man mpv(1)."""
diff --git a/test.srt b/test.srt
new file mode 100644
index 0000000..e6f36e0
--- /dev/null
+++ b/test.srt
@@ -0,0 +1,9 @@
+1
+00:00:00,500 --> 00:00:01,000
+This is
+a subtitle test.
+
+2
+00:00:01,000 --> 00:00:02,000
+This is the second subtitle line.
+