Skip to content

Commit f641500

Browse files
committed
improve CI/env checks for namespace module
Signed-off-by: Zen <[email protected]>
1 parent f00dc71 commit f641500

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "zenlib"
7-
version = "3.1.2"
7+
version = "3.1.3"
88
authors = [
99
{ name="Desultory", email="[email protected]" },
1010
]

src/zenlib/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from .logging import ColorLognameFormatter, loggify
22
from .types import NoDupFlatList, validatedDataclass
33
from .util import colorize, check_dict, handle_plural, pretty_print, replace_file_line, update_init, walk_dict
4+
from .namespace import nsexec
45

56
__all__ = [
67
"colorize",
78
"ColorLognameFormatter",
89
"loggify",
910
"handle_plural",
11+
"nsexec",
1012
"NoDupFlatList",
1113
"validatedDataclass",
1214
"pretty_print",

src/zenlib/namespace/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
from os import environ
2-
if not environ.get("CI"):
3-
from .nsexec import nsexec
4-
from .namespace import get_id_map
5-
else:
2+
from platform import system
3+
from sys import version_info
4+
5+
if environ.get("CI", "false").lower() == "true" or version_info < (3, 12) or system() != "Linux":
66
nsexec, get_id_map = None, None
7+
else:
8+
from .namespace import get_id_map
9+
from .nsexec import nsexec
710

811
__all__ = [
912
"nsexec",

tests/test_namespace.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
from os import environ
2+
from platform import system
3+
from sys import version_info
24
from unittest import TestCase, main, skipIf
35

46
from zenlib.namespace import nsexec
57

68

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+
724
class TestPassedException(Exception):
825
pass
926

@@ -32,25 +49,21 @@ def test_cwd():
3249
return [p for p in Path("/").rglob("")]
3350

3451

52+
@skipIf(not check_test_compat(), "Skipping test_namespace.py in CI")
3553
class TestNamespace(TestCase):
36-
@skipIf(environ.get("CI") == "true", "Skipping test_namespace.py in CI")
3754
def test_user_namespace_exceptions(self):
3855
with self.assertRaises(TestPassedException):
3956
nsexec(test_exception)
4057

41-
@skipIf(environ.get("CI") == "true", "Skipping test_namespace.py in CI")
4258
def test_user_namespace_func(self):
4359
self.assertEqual(nsexec(test_add_func, 1, 2), 3)
4460

45-
@skipIf(environ.get("CI") == "true", "Skipping test_namespace.py in CI")
4661
def test_user_namespace_kwargs(self):
4762
self.assertEqual(nsexec(test_add_kwargs, 1, 2, add1=3, add2=4), 7)
4863

49-
@skipIf(environ.get("CI") == "true", "Skipping test_namespace.py in CI")
5064
def test_user_namespace_uid_gid(self):
5165
self.assertEqual(nsexec(test_uid_gid), (0, 0))
5266

53-
@skipIf(environ.get("CI") == "true", "Skipping test_namespace.py in CI")
5467
def test_user_namespace_chroot(self):
5568
from pathlib import Path
5669
from tempfile import TemporaryDirectory

0 commit comments

Comments
 (0)