refactor: remove unnecessary noqa comments in user tests and user entry creation

Signed-off-by: d9pouces <github@19pouces.net>
This commit is contained in:
d9pouces
2026-10-05 22:13:18 +02:00
parent 8e182f6615
commit 6813c86fba
2 changed files with 10 additions and 19 deletions
+9 -18
View File
@@ -43,23 +43,17 @@ def test_parse_passwd_skips_malformed_lines() -> None:
def test_has_login_shell_true_for_regular_shell() -> None:
entry = PasswdEntry(name="alice", uid=1000, home="/home/alice", shell="/bin/bash") # noqa: B604
entry = PasswdEntry(name="alice", uid=1000, home="/home/alice", shell="/bin/bash")
assert entry.has_login_shell is True
def test_has_login_shell_false_for_nologin_sync_or_false() -> None:
nologin = PasswdEntry(
name="daemon",
uid=1,
home="/usr/sbin",
shell="/usr/sbin/nologin", # noqa: B604
name="daemon", uid=1, home="/usr/sbin", shell="/usr/sbin/nologin"
)
sync = PasswdEntry(name="sync", uid=4, home="/bin", shell="/bin/sync") # noqa: B604
sync = PasswdEntry(name="sync", uid=4, home="/bin", shell="/bin/sync")
false_shell = PasswdEntry(
name="nobody",
uid=65534,
home="/nonexistent",
shell="/usr/sbin/false", # noqa: B604
name="nobody", uid=65534, home="/nonexistent", shell="/usr/sbin/false"
)
assert nologin.has_login_shell is False
assert sync.has_login_shell is False
@@ -67,32 +61,29 @@ def test_has_login_shell_false_for_nologin_sync_or_false() -> None:
def test_is_regular_user_true_for_human_account() -> None:
entry = PasswdEntry(name="alice", uid=1000, home="/home/alice", shell="/bin/bash") # noqa: B604
entry = PasswdEntry(name="alice", uid=1000, home="/home/alice", shell="/bin/bash")
assert entry.is_regular_user() is True
def test_is_regular_user_true_for_root_despite_uid_zero() -> None:
entry = PasswdEntry(name="root", uid=0, home="/root", shell="/bin/bash") # noqa: B604
entry = PasswdEntry(name="root", uid=0, home="/root", shell="/bin/bash")
assert entry.is_regular_user() is True
def test_is_regular_user_false_for_root_with_disabled_shell() -> None:
entry = PasswdEntry(name="root", uid=0, home="/root", shell="/usr/sbin/nologin") # noqa: B604
entry = PasswdEntry(name="root", uid=0, home="/root", shell="/usr/sbin/nologin")
assert entry.is_regular_user() is False
def test_is_regular_user_false_for_disabled_shell_despite_high_uid() -> None:
entry = PasswdEntry(
name="nobody",
uid=65534,
home="/nonexistent",
shell="/usr/sbin/false", # noqa: B604
name="nobody", uid=65534, home="/nonexistent", shell="/usr/sbin/false"
)
assert entry.is_regular_user() is False
def test_is_regular_user_honors_custom_uid_min() -> None:
entry = PasswdEntry(name="svc", uid=500, home="/home/svc", shell="/bin/bash") # noqa: B604
entry = PasswdEntry(name="svc", uid=500, home="/home/svc", shell="/bin/bash")
assert entry.is_regular_user(uid_min=1000) is False
assert entry.is_regular_user(uid_min=100) is True