Skip to content

Commit a447b88

Browse files
committed
merges testutils
1 parent d6192cd commit a447b88

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/snippets/testutils.py

+26
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import platform
2+
import sys
3+
14
def assert_raises(expected, *args, _msg=None, **kw):
25
if args:
36
f, f_args = args[0], args[1:]
@@ -67,3 +70,26 @@ def assert_isinstance(obj, klass):
6770

6871
def assert_in(a, b):
6972
_assert_print(lambda: a in b, [a, 'in', b])
73+
74+
def skip_if_unsupported(req_maj_vers, req_min_vers, test_fct):
75+
def exec():
76+
test_fct()
77+
78+
if platform.python_implementation() == 'RustPython':
79+
exec()
80+
elif sys.version_info.major>=req_maj_vers and sys.version_info.minor>=req_min_vers:
81+
exec()
82+
else:
83+
print(f'Skipping test as a higher python version is required. Using {platform.python_implementation()} {platform.python_version()}')
84+
85+
def fail_if_unsupported(req_maj_vers, req_min_vers, test_fct):
86+
def exec():
87+
test_fct()
88+
89+
if platform.python_implementation() == 'RustPython':
90+
exec()
91+
elif sys.version_info.major>=req_maj_vers and sys.version_info.minor>=req_min_vers:
92+
exec()
93+
else:
94+
assert False, f'Test cannot performed on this python version. {platform.python_implementation()} {platform.python_version()}'
95+

0 commit comments

Comments
 (0)