mirror of
https://github.com/ChristianLight/tutor.git
synced 2024-06-02 06:10:47 +00:00
fix: unit tests when run as root
GitHub Actions sometimes runs `make tests` as root; e.g: in the release script. There were unit tests that were breaking in that scenario. I have no idea why tests were not breaking in the test.yml workflow.
This commit is contained in:
parent
31df4da136
commit
3b6d2404e5
|
@ -30,6 +30,7 @@ class TestCommandMixin:
|
||||||
"TUTOR_ROOT": root,
|
"TUTOR_ROOT": root,
|
||||||
"TUTOR_IGNORE_ENTRYPOINT_PLUGINS": "1",
|
"TUTOR_IGNORE_ENTRYPOINT_PLUGINS": "1",
|
||||||
"TUTOR_IGNORE_DICT_PLUGINS": "1",
|
"TUTOR_IGNORE_DICT_PLUGINS": "1",
|
||||||
}
|
},
|
||||||
|
mix_stderr=False,
|
||||||
)
|
)
|
||||||
return runner.invoke(cli, args, obj=TestContext(root))
|
return runner.invoke(cli, args, obj=TestContext(root))
|
||||||
|
|
|
@ -70,8 +70,17 @@ class UtilsTests(unittest.TestCase):
|
||||||
self.assertIsNotNone(imported.q)
|
self.assertIsNotNone(imported.q)
|
||||||
|
|
||||||
def test_is_root(self) -> None:
|
def test_is_root(self) -> None:
|
||||||
result = utils.is_root()
|
with patch("sys.platform", "win32"):
|
||||||
self.assertFalse(result)
|
with patch.object(utils, "get_user_id", return_value=42):
|
||||||
|
self.assertFalse(utils.is_root())
|
||||||
|
with patch.object(utils, "get_user_id", return_value=0):
|
||||||
|
self.assertFalse(utils.is_root())
|
||||||
|
|
||||||
|
with patch("sys.platform", "linux"):
|
||||||
|
with patch.object(utils, "get_user_id", return_value=42):
|
||||||
|
self.assertFalse(utils.is_root())
|
||||||
|
with patch.object(utils, "get_user_id", return_value=0):
|
||||||
|
self.assertTrue(utils.is_root())
|
||||||
|
|
||||||
@patch("sys.platform", "win32")
|
@patch("sys.platform", "win32")
|
||||||
def test_is_root_win32(self) -> None:
|
def test_is_root_win32(self) -> None:
|
||||||
|
@ -79,11 +88,11 @@ class UtilsTests(unittest.TestCase):
|
||||||
self.assertFalse(result)
|
self.assertFalse(result)
|
||||||
|
|
||||||
def test_get_user_id(self) -> None:
|
def test_get_user_id(self) -> None:
|
||||||
result = utils.get_user_id()
|
with patch("os.getuid", return_value=42):
|
||||||
if sys.platform == "win32":
|
self.assertEqual(42, utils.get_user_id())
|
||||||
self.assertEqual(0, result)
|
|
||||||
else:
|
with patch("sys.platform", new="win32"):
|
||||||
self.assertNotEqual(0, result)
|
self.assertEqual(0, utils.get_user_id())
|
||||||
|
|
||||||
@patch("sys.platform", "win32")
|
@patch("sys.platform", "win32")
|
||||||
def test_get_user_id_win32(self) -> None:
|
def test_get_user_id_win32(self) -> None:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user