From: Iker Pedrosa Date: Mon, 1 Sep 2025 13:08:53 +0000 (+0200) Subject: tests/system/framework/: fix Python linter issues X-Git-Tag: 4.19.0-rc1~158 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=458700b5d6701099c6a99627b100a8256ed25962;p=thirdparty%2Fshadow.git tests/system/framework/: fix Python linter issues Fix issues reported by flake8, pycodestyle, isort, black and mypy. Signed-off-by: Iker Pedrosa --- diff --git a/tests/system/framework/hosts/shadow.py b/tests/system/framework/hosts/shadow.py index 2a0ca3e5d..29e385a7f 100644 --- a/tests/system/framework/hosts/shadow.py +++ b/tests/system/framework/hosts/shadow.py @@ -34,7 +34,7 @@ class ShadowHost(BaseHost, BaseLinuxHost): self._backup_path: PurePosixPath | None = None """Path to backup files.""" - self._verify_files: [dict[str, str]] = [ + self._verify_files: list[dict[str, str]] = [ {"origin": "/etc/passwd", "backup": "passwd"}, {"origin": "/etc/shadow", "backup": "shadow"}, {"origin": "/etc/group", "backup": "group"}, @@ -42,9 +42,6 @@ class ShadowHost(BaseHost, BaseLinuxHost): ] """Files to verify for mismatch.""" - self._features: dict[str, bool] | None = None - """Features supported by the host.""" - def pytest_setup(self) -> None: super().pytest_setup() diff --git a/tests/system/framework/roles/shadow.py b/tests/system/framework/roles/shadow.py index e67b19256..39cbb35b7 100644 --- a/tests/system/framework/roles/shadow.py +++ b/tests/system/framework/roles/shadow.py @@ -133,7 +133,9 @@ class Shadow(BaseLinuxRole[ShadowHost]): Change user password expiry information. """ args_dict = self._parse_args(args) - self.logger.info(f'Changing user password expiry information on user "{args_dict["name"]}" on {self.host.hostname}') + self.logger.info( + f'Changing user password expiry information on user "{args_dict["name"]}" on {self.host.hostname}' + ) cmd = self.host.conn.run("chage " + args[0], log_level=ProcessLogLevel.Error) self.host.discard_file("/etc/passwd") diff --git a/tests/system/framework/utils/tools.py b/tests/system/framework/utils/tools.py index c03091c4c..a2c85cba4 100644 --- a/tests/system/framework/utils/tools.py +++ b/tests/system/framework/utils/tools.py @@ -16,7 +16,7 @@ __all__ = [ "PasswdEntry", "ShadowEntry", "GroupEntry", - "GShadowEntry" + "GShadowEntry", "InitgroupsEntry", "LinuxToolsUtils", "KillCommand", @@ -157,7 +157,16 @@ class PasswdEntry(object): Result of ``getent passwd`` """ - def __init__(self, name: str, password: str, uid: int, gid: int, gecos: str, home: str, shell: str) -> None: + def __init__( + self, + name: str | None, + password: str | None, + uid: int | None, + gid: int | None, + gecos: str | None, + home: str | None, + shell: str | None, + ) -> None: self.name: str | None = name """ User name. @@ -168,12 +177,12 @@ class PasswdEntry(object): User password. """ - self.uid: int = uid + self.uid: int | None = uid """ User id. """ - self.gid: int = gid + self.gid: int | None = gid """ Group id. """ @@ -231,14 +240,14 @@ class ShadowEntry(object): def __init__( self, - name: str, - password: str, - last_changed: int, - min_days: int, - max_days: int, - warn_days: int, - inactivity_days: int, - expiration_date: int, + name: str | None, + password: str | None, + last_changed: int | None, + min_days: int | None, + max_days: int | None, + warn_days: int | None, + inactivity_days: int | None, + expiration_date: int | None, ) -> None: self.name: str | None = name """ @@ -250,22 +259,22 @@ class ShadowEntry(object): User password. """ - self.last_changed: int = last_changed + self.last_changed: int | None = last_changed """ Last password change. """ - self.min_days: int = min_days + self.min_days: int | None = min_days """ Minimum number of days before a password change is allowed. """ - self.max_days: int = max_days + self.max_days: int | None = max_days """ Maximum number of days a password is valid. """ - self.warn_days: int = warn_days + self.warn_days: int | None = warn_days """ Number of days to warn the user before the password expires. """ @@ -321,7 +330,7 @@ class GroupEntry(object): Result of ``getent group`` """ - def __init__(self, name: str, password: str, gid: int, members: list[str]) -> None: + def __init__(self, name: str | None, password: str | None, gid: int | None, members: list[str]) -> None: self.name: str | None = name """ Group name. @@ -332,7 +341,7 @@ class GroupEntry(object): Group password. """ - self.gid: int = gid + self.gid: int | None = gid """ Group id. """ @@ -377,10 +386,10 @@ class GShadowEntry(object): def __init__( self, - name: str, - password: str, - administrators: str, - members: str, + name: str | None, + password: str | None, + administrators: str | None, + members: str | None, ) -> None: self.name: str | None = name """ @@ -392,21 +401,18 @@ class GShadowEntry(object): Group password. """ - self.administrators: int = administrators + self.administrators: str | None = administrators """ Group administrators. """ - self.members: int = members + self.members: str | None = members """ Group members. """ def __str__(self) -> str: - return ( - f"({self.name}:{self.password}:{self.administrators}:" - f"{self.members})" - ) + return f"({self.name}:{self.password}:{self.administrators}:" f"{self.members})" def __repr__(self) -> str: return str(self)