From: Iker Pedrosa Date: Mon, 1 Sep 2025 13:12:14 +0000 (+0200) Subject: tests/system/tests/: fix Python linter issues X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f385e3d91558931d07344ca8cb6406f213c7c985;p=thirdparty%2Fshadow.git tests/system/tests/: fix Python linter issues Fix issues reported by flake8, pycodestyle, isort, black and mypy. Signed-off-by: Iker Pedrosa --- diff --git a/tests/system/tests/test_chage.py b/tests/system/tests/test_chage.py index 062c380ee..f6f1c5801 100644 --- a/tests/system/tests/test_chage.py +++ b/tests/system/tests/test_chage.py @@ -5,8 +5,8 @@ Test chage from __future__ import annotations import pytest - from pytest_mh.conn import ProcessError + from framework.misc import days_since_epoch from framework.roles.shadow import Shadow from framework.topology import KnownTopology diff --git a/tests/system/tests/test_groupadd.py b/tests/system/tests/test_groupadd.py index 5e4bea532..a979919de 100644 --- a/tests/system/tests/test_groupadd.py +++ b/tests/system/tests/test_groupadd.py @@ -26,13 +26,13 @@ def test_groupadd__add_group(shadow: Shadow): """ shadow.groupadd("tgroup") - result = shadow.tools.getent.group("tgroup") - assert result is not None, "Group should be found" - assert result.name == "tgroup", "Incorrect groupname" - assert result.gid == 1000, "Incorrect GID" + group_entry = shadow.tools.getent.group("tgroup") + assert group_entry is not None, "Group should be found" + assert group_entry.name == "tgroup", "Incorrect groupname" + assert group_entry.gid == 1000, "Incorrect GID" if shadow.host.features["gshadow"]: - result = shadow.tools.getent.gshadow("tgroup") - assert result is not None, "Group should be found" - assert result.name == "tgroup", "Incorrect groupname" - assert result.password == "!", "Incorrect password" + gshadow_entry = shadow.tools.getent.gshadow("tgroup") + assert gshadow_entry is not None, "Group should be found" + assert gshadow_entry.name == "tgroup", "Incorrect groupname" + assert gshadow_entry.password == "!", "Incorrect password" diff --git a/tests/system/tests/test_groupdel.py b/tests/system/tests/test_groupdel.py index c2ac2a2cc..a020df00c 100644 --- a/tests/system/tests/test_groupdel.py +++ b/tests/system/tests/test_groupdel.py @@ -28,8 +28,8 @@ def test_groupdel__delete_group(shadow: Shadow): shadow.groupadd("tgroup") shadow.groupdel("tgroup") - result = shadow.tools.getent.group("tgroup") - assert result is None, "Group should not be found" + group_entry = shadow.tools.getent.group("tgroup") + assert group_entry is None, "Group should not be found" - result = shadow.tools.getent.gshadow("tgroup") - assert result is None, "Group should not be found" + gshadow_entry = shadow.tools.getent.gshadow("tgroup") + assert gshadow_entry is None, "Group should not be found" diff --git a/tests/system/tests/test_groupmod.py b/tests/system/tests/test_groupmod.py index 37f334f58..999ddc0cb 100644 --- a/tests/system/tests/test_groupmod.py +++ b/tests/system/tests/test_groupmod.py @@ -28,13 +28,13 @@ def test_groupmod__change_gid(shadow: Shadow): shadow.groupadd("tgroup") shadow.groupmod("-g 1001 tgroup") - result = shadow.tools.getent.group("tgroup") - assert result is not None, "Group should be found" - assert result.name == "tgroup", "Incorrect groupname" - assert result.gid == 1001, "Incorrect GID" + group_entry = shadow.tools.getent.group("tgroup") + assert group_entry is not None, "Group should be found" + assert group_entry.name == "tgroup", "Incorrect groupname" + assert group_entry.gid == 1001, "Incorrect GID" if shadow.host.features["gshadow"]: - result = shadow.tools.getent.gshadow("tgroup") - assert result is not None, "Group should be found" - assert result.name == "tgroup", "Incorrect groupname" - assert result.password == "!", "Incorrect password" + gshadow_entry = shadow.tools.getent.gshadow("tgroup") + assert gshadow_entry is not None, "Group should be found" + assert gshadow_entry.name == "tgroup", "Incorrect groupname" + assert gshadow_entry.password == "!", "Incorrect password" diff --git a/tests/system/tests/test_useradd.py b/tests/system/tests/test_useradd.py index 14c714419..82f8cc65f 100644 --- a/tests/system/tests/test_useradd.py +++ b/tests/system/tests/test_useradd.py @@ -5,9 +5,9 @@ Test useradd from __future__ import annotations import pytest +from pytest_mh.conn import ProcessError from framework.misc import days_since_epoch -from pytest_mh.conn import ProcessError from framework.roles.shadow import Shadow from framework.topology import KnownTopology @@ -34,37 +34,37 @@ def test_useradd__add_user(shadow: Shadow): """ shadow.useradd("tuser") - result = shadow.tools.getent.passwd("tuser") - assert result is not None, "User should be found" - assert result.name == "tuser", "Incorrect username" - assert result.password == "x", "Incorrect password" - assert result.uid == 1000, "Incorrect UID" - assert result.gid == 1000, "Incorrect GID" - assert result.home == "/home/tuser", "Incorrect home" + passwd_entry = shadow.tools.getent.passwd("tuser") + assert passwd_entry is not None, "User should be found" + assert passwd_entry.name == "tuser", "Incorrect username" + assert passwd_entry.password == "x", "Incorrect password" + assert passwd_entry.uid == 1000, "Incorrect UID" + assert passwd_entry.gid == 1000, "Incorrect GID" + assert passwd_entry.home == "/home/tuser", "Incorrect home" if "Debian" in shadow.host.distro_name: - assert result.shell == "/bin/sh", "Incorrect shell" + assert passwd_entry.shell == "/bin/sh", "Incorrect shell" else: - assert result.shell == "/bin/bash", "Incorrect shell" - - result = shadow.tools.getent.shadow("tuser") - assert result is not None, "User should be found" - assert result.name == "tuser", "Incorrect username" - assert result.password == "!", "Incorrect password" - assert result.last_changed == days_since_epoch(), "Incorrect last changed" - assert result.min_days == 0, "Incorrect min days" - assert result.max_days == 99999, "Incorrect max days" - assert result.warn_days == 7, "Incorrect warn days" - - result = shadow.tools.getent.group("tuser") - assert result is not None, "Group should be found" - assert result.name == "tuser", "Incorrect groupname" - assert result.gid == 1000, "Incorrect GID" + assert passwd_entry.shell == "/bin/bash", "Incorrect shell" + + shadow_entry = shadow.tools.getent.shadow("tuser") + assert shadow_entry is not None, "User should be found" + assert shadow_entry.name == "tuser", "Incorrect username" + assert shadow_entry.password == "!", "Incorrect password" + assert shadow_entry.last_changed == days_since_epoch(), "Incorrect last changed" + assert shadow_entry.min_days == 0, "Incorrect min days" + assert shadow_entry.max_days == 99999, "Incorrect max days" + assert shadow_entry.warn_days == 7, "Incorrect warn days" + + group_entry = shadow.tools.getent.group("tuser") + assert group_entry is not None, "Group should be found" + assert group_entry.name == "tuser", "Incorrect groupname" + assert group_entry.gid == 1000, "Incorrect GID" if shadow.host.features["gshadow"]: - result = shadow.tools.getent.gshadow("tuser") - assert result is not None, "User should be found" - assert result.name == "tuser", "Incorrect username" - assert result.password == "!", "Incorrect password" + gshadow_entry = shadow.tools.getent.gshadow("tuser") + assert gshadow_entry is not None, "User should be found" + assert gshadow_entry.name == "tuser", "Incorrect username" + assert gshadow_entry.password == "!", "Incorrect password" assert shadow.fs.exists("/home/tuser"), "Home folder should be found" @@ -91,15 +91,15 @@ def test_useradd__recreate_deleted_user(shadow: Shadow): shadow.userdel("tuser") shadow.useradd("tuser") - result = shadow.tools.id("tuser") - assert result is not None, "User should be found" - assert result.user.name == "tuser", "Incorrect username" - assert result.user.id == 1000, "Incorrect UID" + id_entry = shadow.tools.id("tuser") + assert id_entry is not None, "User should be found" + assert id_entry.user.name == "tuser", "Incorrect username" + assert id_entry.user.id == 1000, "Incorrect UID" - result = shadow.tools.getent.group("tuser") - assert result is not None, "Group should be found" - assert result.name == "tuser", "Incorrect groupname" - assert result.gid == 1000, "Incorrect GID" + group_entry = shadow.tools.getent.group("tuser") + assert group_entry is not None, "Group should be found" + assert group_entry.name == "tuser", "Incorrect groupname" + assert group_entry.gid == 1000, "Incorrect GID" assert shadow.fs.exists("/home/tuser"), "Home folder should be found" diff --git a/tests/system/tests/test_userdel.py b/tests/system/tests/test_userdel.py index 78c6bb361..f9af13a7c 100644 --- a/tests/system/tests/test_userdel.py +++ b/tests/system/tests/test_userdel.py @@ -34,16 +34,16 @@ def test_userdel__homedir_removed(shadow: Shadow): shadow.useradd("tuser") shadow.userdel("-r tuser") - result = shadow.tools.getent.passwd("tuser") - assert result is None, "User should not be found" + passwd_entry = shadow.tools.getent.passwd("tuser") + assert passwd_entry is None, "User should not be found" - result = shadow.tools.getent.shadow("tuser") - assert result is None, "User should not be found" + shadow_entry = shadow.tools.getent.shadow("tuser") + assert shadow_entry is None, "User should not be found" - result = shadow.tools.getent.group("tuser") - assert result is None, "Group should not be found" + group_entry = shadow.tools.getent.group("tuser") + assert group_entry is None, "Group should not be found" - result = shadow.tools.getent.gshadow("tuser1") - assert result is None, "User should not be found" + gshadow_entry = shadow.tools.getent.gshadow("tuser1") + assert gshadow_entry is None, "User should not be found" assert not shadow.fs.exists("/home/tuser"), "Home folder should not exist" diff --git a/tests/system/tests/test_usermod.py b/tests/system/tests/test_usermod.py index fa757a053..b7cf2e3e5 100644 --- a/tests/system/tests/test_usermod.py +++ b/tests/system/tests/test_usermod.py @@ -5,8 +5,8 @@ Test usermod from __future__ import annotations import pytest - from pytest_mh.conn import ProcessError + from framework.roles.shadow import Shadow from framework.topology import KnownTopology @@ -35,24 +35,24 @@ def test_usermod__rename_user(shadow: Shadow): shadow.useradd("tuser1") shadow.usermod("-l tuser2 tuser1") - result = shadow.tools.getent.passwd("tuser2") - assert result is not None, "User should be found" - assert result.name == "tuser2", "Incorrect username" - assert result.uid == 1000, "Incorrect UID" + passwd_entry = shadow.tools.getent.passwd("tuser2") + assert passwd_entry is not None, "User should be found" + assert passwd_entry.name == "tuser2", "Incorrect username" + assert passwd_entry.uid == 1000, "Incorrect UID" - result = shadow.tools.getent.shadow("tuser2") - assert result is not None, "User should be found" - assert result.name == "tuser2", "Incorrect username" + shadow_entry = shadow.tools.getent.shadow("tuser2") + assert shadow_entry is not None, "User should be found" + assert shadow_entry.name == "tuser2", "Incorrect username" - result = shadow.tools.getent.group("tuser1") - assert result is not None, "Group should be found" - assert result.name == "tuser1", "Incorrect groupname" - assert result.gid == 1000, "Incorrect GID" + group_entry = shadow.tools.getent.group("tuser1") + assert group_entry is not None, "Group should be found" + assert group_entry.name == "tuser1", "Incorrect groupname" + assert group_entry.gid == 1000, "Incorrect GID" if shadow.host.features["gshadow"]: - result = shadow.tools.getent.gshadow("tuser1") - assert result is not None, "User should be found" - assert result.name == "tuser1", "Incorrect username" + gshadow_entry = shadow.tools.getent.gshadow("tuser1") + assert gshadow_entry is not None, "User should be found" + assert gshadow_entry.name == "tuser1", "Incorrect username" assert shadow.fs.exists("/home/tuser1"), "Home folder should be found"