Skip to content

Commit c607380

Browse files
committed
test: Add util.skip_if_unrecognized_version
Almost all of our tests are going to want this, so make it really easy to apply. I liked the distinct TestBundle.test_root reason string a bit better, but not enough to avoid using the new decorator for that test ;). Signed-off-by: W. Trevor King <wking@tremily.us>
1 parent 78e0365 commit c607380

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

test/test_bundle.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ def test_configuration(self):
3737
self.assertIsNotNone(
3838
util.CONFIG_BYTES, 'unable to read configuration JSON')
3939

40-
@unittest.skipIf(
41-
util.VERSION not in util.VERSIONS,
42-
'cannot test root-filesystem presence with configuration version {}'
43-
.format(util.VERSION))
40+
@util.skip_if_unrecognized_version
4441
@util.skip_unless_path_separator_matches
4542
def test_root(self):
4643
"""The bundle directory MUST contain the root filesystem.

test/test_root.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121

2222

2323
class TestRoot(unittest.TestCase):
24-
@unittest.skipIf(
25-
util.VERSION not in util.VERSIONS,
26-
'cannot validate an unrecognized version')
24+
@util.skip_if_unrecognized_version
2725
@util.skip_unless_path_separator_matches
2826
def test_path(self):
2927
"""path (string, required).
@@ -47,9 +45,7 @@ def test_path(self):
4745
if util.VERSION == '0.5.0':
4846
self.assertFalse(os.path.isabs(path), 'root.path MUST be relative')
4947

50-
@unittest.skipIf(
51-
util.VERSION not in util.VERSIONS,
52-
'cannot validate an unrecognized version')
48+
@util.skip_if_unrecognized_version
5349
def test_readonly(self):
5450
"""readonly (bool, optional).
5551

test/util.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@
5858
PLATFORM_OS = CONFIG_JSON.get('platform', {}).get('os')
5959

6060

61+
def skip_if_unrecognized_version(func):
62+
return unittest.skipIf(
63+
VERSION not in VERSIONS,
64+
'cannot validate an unrecognized version'
65+
)(func)
66+
67+
6168
def skip_unless_path_separator_matches(func):
6269
if not PLATFORM_OS:
6370
return unittest.skip(

0 commit comments

Comments
 (0)