summaryrefslogtreecommitdiff
path: root/mpv-test.py
diff options
context:
space:
mode:
authorjaseg <code@jaseg.net>2017-07-03 12:24:44 +0200
committerjaseg <code@jaseg.net>2017-07-03 12:24:44 +0200
commit34ab0392c83b1b80f712fc3d02da78564a9944c6 (patch)
treebe94059eca025dfa04ed50ababba0d0a6cf226d5 /mpv-test.py
parent1d9fe92e1515dfaa581599fb955c14ea0d791c00 (diff)
downloadpython-mpv-34ab0392c83b1b80f712fc3d02da78564a9944c6.tar.gz
python-mpv-34ab0392c83b1b80f712fc3d02da78564a9944c6.tar.bz2
python-mpv-34ab0392c83b1b80f712fc3d02da78564a9944c6.zip
Fix racy property tests
Diffstat (limited to 'mpv-test.py')
-rwxr-xr-xmpv-test.py27
1 files changed, 24 insertions, 3 deletions
diff --git a/mpv-test.py b/mpv-test.py
index eb3c13f..10561d5 100755
--- a/mpv-test.py
+++ b/mpv-test.py
@@ -144,6 +144,11 @@ class ObservePropertyTest(unittest.TestCase):
m.loop = 'no'
self.assertEqual(m.loop, 'no')
+ # 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)
+
m.loop = 'inf'
self.assertEqual(m.loop, 'inf')
@@ -172,6 +177,19 @@ class ObservePropertyTest(unittest.TestCase):
self.assertEqual(m.mute, False)
self.assertEqual(m.loop, 'no')
+ # 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)
+ # Another API limitation is that the order of property change events on
+ # different properties does not necessarily exactly match the order in
+ # which these properties were previously accessed. Thus, any_order.
+ handler.assert_has_calls([
+ mock.call('mute', False),
+ mock.call('loop', 'no')],
+ any_order=True)
+ handler.reset_mock()
+
m.mute = True
m.loop = 'inf'
self.assertEqual(m.mute, True)
@@ -186,10 +204,9 @@ class ObservePropertyTest(unittest.TestCase):
m.loop = 'inf'
m.terminate() # needed for synchronization of event thread
handler.assert_has_calls([
- mock.call('mute', False),
- mock.call('loop', 'no'),
mock.call('mute', True),
- mock.call('loop', 'inf')])
+ mock.call('loop', 'inf')],
+ any_order=True)
class TestLifecycle(unittest.TestCase):
def test_create_destroy(self):
@@ -288,6 +305,10 @@ class RegressionTests(unittest.TestCase):
m.loop = 'no'
self.assertEqual(m.loop, 'no')
+ # 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)
m.loop = 'inf'
self.assertEqual(m.loop, 'inf')