mirror of
https://github.com/ChristianLight/tutor.git
synced 2024-11-13 00:36:30 +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_IGNORE_ENTRYPOINT_PLUGINS": "1",
|
||||
"TUTOR_IGNORE_DICT_PLUGINS": "1",
|
||||
}
|
||||
},
|
||||
mix_stderr=False,
|
||||
)
|
||||
return runner.invoke(cli, args, obj=TestContext(root))
|
||||
|
@ -70,8 +70,17 @@ class UtilsTests(unittest.TestCase):
|
||||
self.assertIsNotNone(imported.q)
|
||||
|
||||
def test_is_root(self) -> None:
|
||||
result = utils.is_root()
|
||||
self.assertFalse(result)
|
||||
with patch("sys.platform", "win32"):
|
||||
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")
|
||||
def test_is_root_win32(self) -> None:
|
||||
@ -79,11 +88,11 @@ class UtilsTests(unittest.TestCase):
|
||||
self.assertFalse(result)
|
||||
|
||||
def test_get_user_id(self) -> None:
|
||||
result = utils.get_user_id()
|
||||
if sys.platform == "win32":
|
||||
self.assertEqual(0, result)
|
||||
else:
|
||||
self.assertNotEqual(0, result)
|
||||
with patch("os.getuid", return_value=42):
|
||||
self.assertEqual(42, utils.get_user_id())
|
||||
|
||||
with patch("sys.platform", new="win32"):
|
||||
self.assertEqual(0, utils.get_user_id())
|
||||
|
||||
@patch("sys.platform", "win32")
|
||||
def test_get_user_id_win32(self) -> None:
|
||||
|
Loading…
Reference in New Issue
Block a user