diff --git a/pyproject.toml b/pyproject.toml index ce395bd4..e6b1d96f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,3 +14,102 @@ junit_log_passing_tests = true [tool.pytest_env] RUST_BACKTRACE = {value = "1", skip_if_set = true} + +[tool.ruff] +# Exclude a variety of commonly ignored directories. +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".git-rewrite", + ".hg", + ".mypy_cache", + ".nox", + ".pants.d", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "venv", +] + +line-length = 120 +indent-width = 4 + +[tool.ruff.lint] +select = [ + # flake8-boolean-trap + "FBT", + # flake8-bugbear + "B", + # flake8-builtins + "A", + # flake8-comprehensions + "C4", + # flake8-fixme + "FIX", + # flake8-implicit-str-concat + "ISC", + # flake8-pie + "PIE", + # flake8-print + "T20", + # flake8-pytest-style + "PT", + # flake8-raise + "RSE", + # flake8-return + "RET501", + "RET502", + "RET503", + "RET504", + # flake8-self + "SLF", + # flake8-simplify + "SIM", + # flake8-type-checking + "TC", + # flake8-unused-arguments + "ARG", + # flake8-use-pathlib + "PTH", + + # isort + "I", + + # pycodestyle error + "E", + # Pyflakes + "F", + # pyupgrade + "UP", +] +ignore = ["F401", "PTH123", "ARG002"] + +# Allow fix for all enabled rules (when `--fix`) is provided. +fixable = ["ALL"] +unfixable = [] + +# Allow unused variables when underscore-prefixed. +dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" + +[tool.ruff.format] +# Like Black, use double quotes for strings. +quote-style = "double" + +# Like Black, indent with spaces, rather than tabs. +indent-style = "space" + +# Like Black, respect magic trailing commas. +skip-magic-trailing-comma = false + +# Like Black, automatically detect the appropriate line ending. +line-ending = "auto" diff --git a/tests/test_cases/tests/common.py b/tests/test_cases/tests/common.py index d4dc8aae..e10c56d4 100644 --- a/tests/test_cases/tests/common.py +++ b/tests/test_cases/tests/common.py @@ -63,9 +63,7 @@ def build_tools(self, version: str) -> BuildTools: return BazelTools(option_prefix=version) @pytest.fixture(scope="class") - def temp_dir( - self, tmp_path_factory: pytest.TempPathFactory, version: str - ) -> Generator[Path, None, None]: + def temp_dir(self, tmp_path_factory: pytest.TempPathFactory, version: str) -> Generator[Path, None, None]: yield from temp_dir_common(tmp_path_factory, self.__class__.__name__, version) @pytest.fixture(scope="class") diff --git a/tests/test_cases/tests/conftest.py b/tests/test_cases/tests/conftest.py index a7d5b27f..e51b87ba 100644 --- a/tests/test_cases/tests/conftest.py +++ b/tests/test_cases/tests/conftest.py @@ -161,22 +161,16 @@ def pytest_terminal_summary(terminalreporter): return # Print failed scenarios info terminalreporter.write_sep("=", "Failed tests reproduction info") - terminalreporter.write_line( - "Run failed scenarios from the repo root working directory\n" - ) + terminalreporter.write_line("Run failed scenarios from the repo root working directory\n") for entry in FAILED_CONFIGS: - terminalreporter.write_line( - f"{entry['nodeid']} | Run command:\n{entry['command']}\n" - ) + terminalreporter.write_line(f"{entry['nodeid']} | Run command:\n{entry['command']}\n") def pytest_collection_modifyitems(items: list[pytest.Function]): for item in items: # Automatically mark tests parametrized with 'version' as 'cpp' or 'rust' - if hasattr(item, "callspec") and "version" in getattr( - item.callspec, "params", {} - ): + if hasattr(item, "callspec") and "version" in getattr(item.callspec, "params", {}): version = item.callspec.params["version"] if version == "cpp": item.add_marker(pytest.mark.cpp) diff --git a/tests/test_cases/tests/test_cit_default_values.py b/tests/test_cases/tests/test_cit_default_values.py index 760c5763..8cfa1add 100644 --- a/tests/test_cases/tests/test_cit_default_values.py +++ b/tests/test_cases/tests/test_cit_default_values.py @@ -40,9 +40,7 @@ def create_defaults_json(values: dict[str, TaggedValue]) -> str: return json.dumps(json_value) -def create_defaults_file( - dir_path: Path, instance_id: int, values: dict[str, TaggedValue] -) -> Path: +def create_defaults_file(dir_path: Path, instance_id: int, values: dict[str, TaggedValue]) -> Path: """ Create file containing default values, along with a matching hash file. Returns path to default values file. @@ -84,9 +82,7 @@ def temp_dir( """ Create temporary directory and remove it after test. """ - yield from temp_dir_common( - tmp_path_factory, self.__class__.__name__, version, defaults - ) + yield from temp_dir_common(tmp_path_factory, self.__class__.__name__, version, defaults) @pytest.mark.PartiallyVerifies( @@ -132,9 +128,7 @@ def defaults_file(self, temp_dir: Path, defaults: str) -> Path | None: if defaults == "without": return None - return create_defaults_file( - temp_dir, self.instance_id(), {self.KEY: ("f64", self.VALUE)} - ) + return create_defaults_file(temp_dir, self.instance_id(), {self.KEY: ("f64", self.VALUE)}) def test_valid( self, @@ -144,9 +138,7 @@ def test_valid( version: str, ) -> None: if version == "cpp": - pytest.xfail( - reason="https://github.com/eclipse-score/persistency/issues/182" - ) + pytest.xfail(reason="https://github.com/eclipse-score/persistency/issues/182") assert results.return_code == ResultCode.SUCCESS @@ -216,9 +208,7 @@ def defaults_file(self, temp_dir: Path, defaults: str) -> Path | None: if defaults == "without": return None - return create_defaults_file( - temp_dir, self.instance_id(), {self.KEY: ("f64", self.VALUE)} - ) + return create_defaults_file(temp_dir, self.instance_id(), {self.KEY: ("f64", self.VALUE)}) def test_valid( self, @@ -228,9 +218,7 @@ def test_valid( version: str, ) -> None: if version == "cpp": - pytest.xfail( - reason="https://github.com/eclipse-score/persistency/issues/182" - ) + pytest.xfail(reason="https://github.com/eclipse-score/persistency/issues/182") assert results.return_code == ResultCode.SUCCESS logs = logs_info_level.get_logs("key", value=self.KEY) @@ -273,9 +261,7 @@ def test_valid( ] ) @pytest.mark.FullyVerifies([]) -@pytest.mark.Description( - "Verifies that KVS fails to open when the defaults file contains invalid JSON." -) +@pytest.mark.Description("Verifies that KVS fails to open when the defaults file contains invalid JSON.") @pytest.mark.TestType("requirements-based") @pytest.mark.DerivationTechnique("requirements-based") @pytest.mark.parametrize("defaults", ["optional", "required"], scope="class") @@ -344,9 +330,7 @@ def test_invalid( ] ) @pytest.mark.FullyVerifies([]) -@pytest.mark.Description( - "Verifies that KVS fails to open when the defaults file is missing." -) +@pytest.mark.Description("Verifies that KVS fails to open when the defaults file is missing.") @pytest.mark.TestType("requirements-based") @pytest.mark.DerivationTechnique("requirements-based") @pytest.mark.parametrize("defaults", ["required"], scope="class") @@ -383,9 +367,7 @@ def test_invalid(self, results: ScenarioResult) -> None: ] ) @pytest.mark.FullyVerifies(["comp_req__persistency__value_reset_v2"]) -@pytest.mark.Description( - "Checks that resetting KVS restores all keys to their default values." -) +@pytest.mark.Description("Checks that resetting KVS restores all keys to their default values.") @pytest.mark.TestType("requirements-based") @pytest.mark.DerivationTechnique("requirements-based") @pytest.mark.parametrize("defaults", ["optional", "required"], scope="class") @@ -424,9 +406,7 @@ def test_valid( version: str, ): if version == "cpp": - pytest.xfail( - reason="https://github.com/eclipse-score/persistency/issues/182" - ) + pytest.xfail(reason="https://github.com/eclipse-score/persistency/issues/182") assert defaults_file is not None assert results.return_code == ResultCode.SUCCESS @@ -453,9 +433,7 @@ def test_valid( ] ) @pytest.mark.FullyVerifies([]) -@pytest.mark.Description( - "Checks that resetting single key restores it to its default value." -) +@pytest.mark.Description("Checks that resetting single key restores it to its default value.") @pytest.mark.TestType("requirements-based") @pytest.mark.DerivationTechnique("requirements-based") @pytest.mark.parametrize("defaults", ["optional", "required"], scope="class") @@ -495,9 +473,7 @@ def test_valid( version: str, ): if version == "cpp": - pytest.xfail( - reason="https://github.com/eclipse-score/persistency/issues/182" - ) + pytest.xfail(reason="https://github.com/eclipse-score/persistency/issues/182") assert defaults_file is not None assert results.return_code == ResultCode.SUCCESS @@ -538,9 +514,7 @@ def test_valid( ] ) @pytest.mark.FullyVerifies(["comp_req__persistency__default_val_chksum_v2"]) -@pytest.mark.Description( - "Ensures that a checksum file is created when opening KVS with defaults." -) +@pytest.mark.Description("Ensures that a checksum file is created when opening KVS with defaults.") @pytest.mark.TestType("requirements-based") @pytest.mark.DerivationTechnique("requirements-based") @pytest.mark.parametrize("defaults", ["optional", "required"], scope="class") @@ -568,9 +542,7 @@ def defaults_file(self, temp_dir: Path, defaults: str) -> Path | None: if defaults == "without": return None - return create_defaults_file( - temp_dir, self.instance_id(), {self.KEY: ("f64", self.VALUE)} - ) + return create_defaults_file(temp_dir, self.instance_id(), {self.KEY: ("f64", self.VALUE)}) def test_valid( self, diff --git a/tests/test_cases/tests/test_cit_multiple_kvs.py b/tests/test_cases/tests/test_cit_multiple_kvs.py index 0b609a89..754992d5 100644 --- a/tests/test_cases/tests/test_cit_multiple_kvs.py +++ b/tests/test_cases/tests/test_cit_multiple_kvs.py @@ -40,12 +40,8 @@ def scenario_name(self) -> str: @pytest.fixture(scope="class") def test_config(self, temp_dir: Path) -> dict[str, Any]: return { - "kvs_parameters_1": { - "kvs_parameters": {"instance_id": 1, "dir": str(temp_dir)} - }, - "kvs_parameters_2": { - "kvs_parameters": {"instance_id": 2, "dir": str(temp_dir)} - }, + "kvs_parameters_1": {"kvs_parameters": {"instance_id": 1, "dir": str(temp_dir)}}, + "kvs_parameters_2": {"kvs_parameters": {"instance_id": 2, "dir": str(temp_dir)}}, } def test_ok(self, results: ScenarioResult, logs_info_level: LogContainer): diff --git a/tests/test_cases/tests/test_cit_snapshots.py b/tests/test_cases/tests/test_cit_snapshots.py index e2845b7f..6277988d 100644 --- a/tests/test_cases/tests/test_cit_snapshots.py +++ b/tests/test_cases/tests/test_cit_snapshots.py @@ -35,16 +35,12 @@ def temp_dir( """ Create temporary directory and remove it after test. """ - yield from temp_dir_common( - tmp_path_factory, self.__class__.__name__, version, str(snapshot_max_count) - ) + yield from temp_dir_common(tmp_path_factory, self.__class__.__name__, version, str(snapshot_max_count)) @pytest.mark.PartiallyVerifies(["comp_req__persistency__snapshot_creation_v2"]) @pytest.mark.FullyVerifies([]) -@pytest.mark.Description( - "Verifies that a snapshot is only created after the first flush, and not before." -) +@pytest.mark.Description("Verifies that a snapshot is only created after the first flush, and not before.") @pytest.mark.TestType("requirements-based") @pytest.mark.DerivationTechnique("requirements-based") @pytest.mark.parametrize("snapshot_max_count", [0, 1, 3, 10], scope="class") @@ -90,9 +86,7 @@ def test_ok( @pytest.mark.PartiallyVerifies(["comp_req__persistency__snapshot_creation_v2"]) @pytest.mark.FullyVerifies([]) -@pytest.mark.Description( - "Checks that the snapshot count increases with each flush, up to the maximum allowed count." -) +@pytest.mark.Description("Checks that the snapshot count increases with each flush, up to the maximum allowed count.") @pytest.mark.TestType("requirements-based") @pytest.mark.DerivationTechnique("requirements-based") class TestSnapshotCountFull(TestSnapshotCountFirstFlush): @@ -110,9 +104,7 @@ def test_config(self, temp_dir: Path, snapshot_max_count: int) -> dict[str, Any] @pytest.mark.PartiallyVerifies(["comp_req__persistency__snapshot_max_num_v2"]) @pytest.mark.FullyVerifies([]) -@pytest.mark.Description( - "Verifies that the maximum number of snapshots is a constant value." -) +@pytest.mark.Description("Verifies that the maximum number of snapshots is a constant value.") @pytest.mark.TestType("requirements-based") @pytest.mark.DerivationTechnique("inspection") @pytest.mark.parametrize("snapshot_max_count", [0, 1, 3, 10], scope="class") @@ -143,9 +135,7 @@ def test_ok( reason="https://github.com/eclipse-score/persistency/issues/108", ) assert results.return_code == ResultCode.SUCCESS - assert ( - logs_info_level.find_log("max_count", value=snapshot_max_count) is not None - ) + assert logs_info_level.find_log("max_count", value=snapshot_max_count) is not None @pytest.mark.PartiallyVerifies( @@ -155,9 +145,7 @@ def test_ok( ] ) @pytest.mark.FullyVerifies(["comp_req__persistency__snapshot_restore_v2"]) -@pytest.mark.Description( - "Verifies restoring to a previous snapshot returns the expected value." -) +@pytest.mark.Description("Verifies restoring to a previous snapshot returns the expected value.") @pytest.mark.TestType("requirements-based") @pytest.mark.DerivationTechnique("control-flow-analysis") @pytest.mark.parametrize("snapshot_max_count", [3, 10], scope="class") @@ -196,9 +184,7 @@ def test_ok( @pytest.mark.PartiallyVerifies(["comp_req__persistency__snapshot_creation_v2"]) @pytest.mark.FullyVerifies([]) -@pytest.mark.Description( - "Checks that restoring the current snapshot ID fails with InvalidSnapshotId error." -) +@pytest.mark.Description("Checks that restoring the current snapshot ID fails with InvalidSnapshotId error.") @pytest.mark.TestType("requirements-based") @pytest.mark.DerivationTechnique("fault-injection") class TestSnapshotRestoreCurrent(CommonScenario): @@ -241,9 +227,7 @@ def test_error( ] ) @pytest.mark.FullyVerifies([]) -@pytest.mark.Description( - "Checks that restoring a non-existing snapshot fails with InvalidSnapshotId error." -) +@pytest.mark.Description("Checks that restoring a non-existing snapshot fails with InvalidSnapshotId error.") @pytest.mark.TestType("requirements-based") @pytest.mark.DerivationTechnique("fault-injection") class TestSnapshotRestoreNonexistent(CommonScenario): @@ -262,9 +246,7 @@ def test_config(self, temp_dir: Path) -> dict[str, Any]: def capture_stderr(self) -> bool: return True - def test_error( - self, results: ScenarioResult, logs_info_level: LogContainer, version: str - ): + def test_error(self, results: ScenarioResult, logs_info_level: LogContainer, version: str): assert results.return_code == ResultCode.SUCCESS if version == "rust": @@ -278,9 +260,7 @@ def test_error( @pytest.mark.PartiallyVerifies(["comp_req__persistency__snapshot_creation_v2"]) @pytest.mark.FullyVerifies([]) -@pytest.mark.Description( - "Verifies that the KVS and hash filenames for an existing snapshot is generated correctly." -) +@pytest.mark.Description("Verifies that the KVS and hash filenames for an existing snapshot is generated correctly.") @pytest.mark.TestType("requirements-based") @pytest.mark.DerivationTechnique("interface-test") class TestSnapshotPathsExist(CommonScenario): diff --git a/tests/test_cases/tests/test_cit_supported_datatypes.py b/tests/test_cases/tests/test_cit_supported_datatypes.py index 1da81da1..4598fda4 100644 --- a/tests/test_cases/tests/test_cit_supported_datatypes.py +++ b/tests/test_cases/tests/test_cit_supported_datatypes.py @@ -28,9 +28,7 @@ ] ) @pytest.mark.FullyVerifies([]) -@pytest.mark.Description( - "Verifies that KVS supports UTF-8 string keys for storing and retrieving values." -) +@pytest.mark.Description("Verifies that KVS supports UTF-8 string keys for storing and retrieving values.") @pytest.mark.TestType("requirements-based") @pytest.mark.DerivationTechnique("interface-test") class TestSupportedDatatypesKeys(CommonScenario): @@ -60,9 +58,7 @@ def test_ok(self, results: ScenarioResult, logs_info_level: LogContainer) -> Non ] ) @pytest.mark.FullyVerifies([]) -@pytest.mark.Description( - "Verifies that KVS supports UTF-8 string keys for storing and retrieving values." -) +@pytest.mark.Description("Verifies that KVS supports UTF-8 string keys for storing and retrieving values.") @pytest.mark.TestType("requirements-based") @pytest.mark.DerivationTechnique("interface-test") class TestSupportedDatatypesValues(CommonScenario): diff --git a/tools/qnx_credential_helper.py b/tools/qnx_credential_helper.py index 06ae7951..a6a4261e 100755 --- a/tools/qnx_credential_helper.py +++ b/tools/qnx_credential_helper.py @@ -49,9 +49,7 @@ def eprint(*args, **kwargs): eprint("Failed getting credentials from .netrc") sys.exit(1) - data = urllib.parse.urlencode( - {"userlogin": login, "password": password, "UseCookie": "1"} - ) + data = urllib.parse.urlencode({"userlogin": login, "password": password, "UseCookie": "1"}) data = data.encode("ascii") cookie_jar = http.cookiejar.CookieJar()