diff options
author | jaseg <code@jaseg.net> | 2016-08-24 11:42:17 +0200 |
---|---|---|
committer | jaseg <code@jaseg.net> | 2016-08-24 11:42:17 +0200 |
commit | b71e8a4a55ce68f4594043120fd52e536509bf1e (patch) | |
tree | e9e1f3000f24b1ae2bda207b8db365568cfcf36f | |
parent | 1ee4361bdd41e8ae0a6d0d9570d75e85a44d19ff (diff) | |
download | python-mpv-b71e8a4a55ce68f4594043120fd52e536509bf1e.tar.gz python-mpv-b71e8a4a55ce68f4594043120fd52e536509bf1e.tar.bz2 python-mpv-b71e8a4a55ce68f4594043120fd52e536509bf1e.zip |
Small refactoring of with usage in tests
-rwxr-xr-x | mpv-test.py | 68 |
1 files changed, 31 insertions, 37 deletions
diff --git a/mpv-test.py b/mpv-test.py index f35f160..14a28a7 100755 --- a/mpv-test.py +++ b/mpv-test.py @@ -62,14 +62,12 @@ class TestProperties(unittest.TestCase): for name, (ptype, access, *_args) in sorted(mpv.ALL_PROPERTIES.items()): if 'r' in access: name = name.replace('-', '_') - with self.subTest(property_name=name): - with self.swallow_mpv_errors([ - mpv.ErrorCode.PROPERTY_UNAVAILABLE, - mpv.ErrorCode.PROPERTY_ERROR]): - rv = getattr(self.m, name) - if rv is not None and callable(ptype): - # Technically, any property can return None (even if of type e.g. int) - self.assertEqual(type(rv), type(ptype())) + with self.subTest(property_name=name), self.swallow_mpv_errors([ + mpv.ErrorCode.PROPERTY_UNAVAILABLE, mpv.ErrorCode.PROPERTY_ERROR]): + rv = getattr(self.m, name) + if rv is not None and callable(ptype): + # Technically, any property can return None (even if of type e.g. int) + self.assertEqual(type(rv), type(ptype())) def test_write(self): self.m.loop = 'inf' @@ -79,32 +77,31 @@ class TestProperties(unittest.TestCase): 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([ + with self.subTest(property_name=name), 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) + 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' @@ -112,12 +109,9 @@ class TestProperties(unittest.TestCase): 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_NOT_FOUND, - mpv.ErrorCode.PROPERTY_ERROR]): - self.m[name] + with self.subTest(option_name=name), self.swallow_mpv_errors([ + mpv.ErrorCode.PROPERTY_UNAVAILABLE, mpv.ErrorCode.PROPERTY_NOT_FOUND, mpv.ErrorCode.PROPERTY_ERROR]): + self.m[name] def tearDown(self): |