Small refactoring of with usage in tests

This commit is contained in:
jaseg 2016-08-24 11:42:17 +02:00
parent 1ee4361bdd
commit b71e8a4a55

View file

@ -62,10 +62,8 @@ 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]):
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)
@ -79,8 +77,7 @@ 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
@ -112,11 +109,8 @@ 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]):
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]