|
1 | 1 | from os import environ |
| 2 | +from platform import system |
| 3 | +from sys import version_info |
2 | 4 | from unittest import TestCase, main, skipIf |
3 | 5 |
|
4 | 6 | from zenlib.namespace import nsexec |
5 | 7 |
|
6 | 8 |
|
| 9 | +def check_test_compat(): |
| 10 | + """Checks if tests are compatible with the current environment""" |
| 11 | + |
| 12 | + if environ.get("CI", "false").lower() == "true": |
| 13 | + return |
| 14 | + |
| 15 | + if system() != "Linux": |
| 16 | + return |
| 17 | + |
| 18 | + if version_info < (3, 12): |
| 19 | + return |
| 20 | + |
| 21 | + return True |
| 22 | + |
| 23 | + |
7 | 24 | class TestPassedException(Exception): |
8 | 25 | pass |
9 | 26 |
|
@@ -32,25 +49,21 @@ def test_cwd(): |
32 | 49 | return [p for p in Path("/").rglob("")] |
33 | 50 |
|
34 | 51 |
|
| 52 | +@skipIf(not check_test_compat(), "Skipping test_namespace.py in CI") |
35 | 53 | class TestNamespace(TestCase): |
36 | | - @skipIf(environ.get("CI") == "true", "Skipping test_namespace.py in CI") |
37 | 54 | def test_user_namespace_exceptions(self): |
38 | 55 | with self.assertRaises(TestPassedException): |
39 | 56 | nsexec(test_exception) |
40 | 57 |
|
41 | | - @skipIf(environ.get("CI") == "true", "Skipping test_namespace.py in CI") |
42 | 58 | def test_user_namespace_func(self): |
43 | 59 | self.assertEqual(nsexec(test_add_func, 1, 2), 3) |
44 | 60 |
|
45 | | - @skipIf(environ.get("CI") == "true", "Skipping test_namespace.py in CI") |
46 | 61 | def test_user_namespace_kwargs(self): |
47 | 62 | self.assertEqual(nsexec(test_add_kwargs, 1, 2, add1=3, add2=4), 7) |
48 | 63 |
|
49 | | - @skipIf(environ.get("CI") == "true", "Skipping test_namespace.py in CI") |
50 | 64 | def test_user_namespace_uid_gid(self): |
51 | 65 | self.assertEqual(nsexec(test_uid_gid), (0, 0)) |
52 | 66 |
|
53 | | - @skipIf(environ.get("CI") == "true", "Skipping test_namespace.py in CI") |
54 | 67 | def test_user_namespace_chroot(self): |
55 | 68 | from pathlib import Path |
56 | 69 | from tempfile import TemporaryDirectory |
|
0 commit comments