From db56d236dd1b2b5807de891fa6755b64ce2b5ac3 Mon Sep 17 00:00:00 2001 From: helle Date: Thu, 12 Jun 2025 03:22:51 +0200 Subject: [PATCH] tests/functional2: fixes prerequisite to ruff upgrade to 0.11.10 Most of these are simple fixes and clarifications. One set of fixes will come in the commit that actually upgrades nixpkgs and hence ruff as it will otherwise cause errors here. Change-Id: Ie857da0f6cf728478700ec2d24cf518f8c7b7815 --- tests/functional2/lang/lang_util.py | 4 ++-- tests/functional2/pyproject.toml | 2 +- tests/functional2/testlib/fixtures/http_server.py | 2 +- tests/functional2/testlib/fixtures/test_file_helper.py | 5 +++-- tests/functional2/testlib/fixtures/test_nix.py | 6 +++--- tests/functional2/testlib/nar.py | 8 ++++---- tests/functional2/testlib/test_utils.py | 8 ++++---- 7 files changed, 18 insertions(+), 17 deletions(-) diff --git a/tests/functional2/lang/lang_util.py b/tests/functional2/lang/lang_util.py index 29e43c93d..a90b2f84b 100644 --- a/tests/functional2/lang/lang_util.py +++ b/tests/functional2/lang/lang_util.py @@ -43,7 +43,7 @@ INVALID_TESTER_NAME = ( Base message for invalid runner, to use across collection """ -SUFFIX_REGEX = re.compile("-[\\w-]+?").pattern +SUFFIX_REGEX = r"-[\w-]+?" NAMING_PATTERN_LANG_TEST = re.compile( rf"{LangTestRunner.as_regex_selector()}(?P{SUFFIX_REGEX})?" ) @@ -262,7 +262,7 @@ def _collect_all_tests() -> tuple[list[LangTest], list[InvalidLangTest]]: # ignore test groups, which have a py file, as those are set up fully custom # and expected to be collected by pytest and not by us - if len(list(node.glob("*.py"))): + if list(node.glob("*.py")): logger.info("skipping %s as it contains a py file, assuming custom tests", node) continue t, i = _collect_test_group(node) diff --git a/tests/functional2/pyproject.toml b/tests/functional2/pyproject.toml index 396a91937..ad9041ee9 100644 --- a/tests/functional2/pyproject.toml +++ b/tests/functional2/pyproject.toml @@ -1,7 +1,7 @@ [project] name = "functional2" version = "2" -requires-python = ">=3.11" +requires-python = ">=3.12" [tool.pytest.ini_options] addopts = "-p no:xonsh" diff --git a/tests/functional2/testlib/fixtures/http_server.py b/tests/functional2/testlib/fixtures/http_server.py index 2cebdb4ec..fb7a818f7 100644 --- a/tests/functional2/testlib/fixtures/http_server.py +++ b/tests/functional2/testlib/fixtures/http_server.py @@ -119,7 +119,7 @@ def dev_main(): app.add_routes([web.get("/", root)]) with http_server(app) as httpd: - logging.info("Listening on http://[::1]:%d", httpd.port) + logger.info("Listening on http://[::1]:%d", httpd.port) time.sleep(3600) diff --git a/tests/functional2/testlib/fixtures/test_file_helper.py b/tests/functional2/testlib/fixtures/test_file_helper.py index f25f4929f..4278b1f86 100644 --- a/tests/functional2/testlib/fixtures/test_file_helper.py +++ b/tests/functional2/testlib/fixtures/test_file_helper.py @@ -272,7 +272,8 @@ def test_merge_fd_throws_on_conflict(): fd2 = {"a": File("a")} with pytest.raises( - ValueError, match="('Cannot merge files; got two different values for the same path', 'a')" + ValueError, + match=r"\('Cannot merge files; got two different values for the same path', 'a'\)", ): merge_file_declaration(fd1, fd2) @@ -283,6 +284,6 @@ def test_merge_fd_throws_on_conflict_with_full_path(): with pytest.raises( ValueError, - match="('Cannot merge files; got two different values for the same path', 'a/b/c/d')", + match=r"\('Cannot merge files; got two different values for the same path', 'a/b/c/d'\)", ): merge_file_declaration(fd1, fd2) diff --git a/tests/functional2/testlib/fixtures/test_nix.py b/tests/functional2/testlib/fixtures/test_nix.py index f4aa36f0b..0f39cc1af 100644 --- a/tests/functional2/testlib/fixtures/test_nix.py +++ b/tests/functional2/testlib/fixtures/test_nix.py @@ -34,7 +34,7 @@ def test_nix_settings_ser_fails_bad_top_level_type(): settings = NixSettings(nix_store_dir=Path("/store/nix")) settings.experimental_features = {"a": "b"} # type: ignore we are testing the types here - with pytest.raises(ValueError, match="Value is unsupported in nix config: {'a': 'b'}"): + with pytest.raises(ValueError, match=r"Value is unsupported in nix config: {'a': 'b'}"): settings.to_config() @@ -42,7 +42,7 @@ def test_nix_settings_ser_fails_bad_sub_type(): settings = NixSettings(nix_store_dir=Path("/store/nix")) settings.experimental_features = [["a", "b"], "c"] # type: ignore we are testing the types here - with pytest.raises(ValueError, match="Value is unsupported in nix config: .+"): + with pytest.raises(ValueError, match=r"Value is unsupported in nix config: .+"): settings.to_config() @@ -51,7 +51,7 @@ def test_nix_settings_fails_without_store_and_store_dir(): with pytest.raises( AssertionError, - match="Failing to set either nix_store_dir or store will cause accidental use of the system store.", + match=r"Failing to set either nix_store_dir or store will cause accidental use of the system store.", ): settings.to_config() diff --git a/tests/functional2/testlib/nar.py b/tests/functional2/testlib/nar.py index 4f2b1dad1..7bb425fb6 100644 --- a/tests/functional2/testlib/nar.py +++ b/tests/functional2/testlib/nar.py @@ -7,7 +7,7 @@ See "The Purely Functional Software Deployment Model", fig. 5.2 [1]. from abc import ABCMeta, abstractmethod import dataclasses import struct -from typing import Protocol +from typing import Protocol, ClassVar class Writable(Protocol): @@ -56,7 +56,7 @@ class NarItem(metaclass=ABCMeta): class Regular(NarItem): executable: bool contents: bytes - type_ = b"regular" + type_: ClassVar[bytes] = b"regular" def serialize_type(self, out: NarListener): if self.executable: @@ -70,7 +70,7 @@ class Regular(NarItem): class DirectoryUnordered(NarItem): entries: list[tuple[bytes, NarItem]] """Entries in the directory, not required to be in order because this nar is evil""" - type_ = b"directory" + type_: ClassVar[bytes] = b"directory" @staticmethod def entry(out: NarListener, name: bytes, item: "NarItem"): @@ -102,7 +102,7 @@ class Directory(NarItem): @dataclasses.dataclass class Symlink(NarItem): target: bytes - type_ = b"symlink" + type_: ClassVar[bytes] = b"symlink" def serialize_type(self, out: NarListener): out.str_(b"target") diff --git a/tests/functional2/testlib/test_utils.py b/tests/functional2/testlib/test_utils.py index 5d6ba3793..3efba199e 100644 --- a/tests/functional2/testlib/test_utils.py +++ b/tests/functional2/testlib/test_utils.py @@ -43,15 +43,15 @@ def test_type_doesnt_allow_generator(): def foo(): yield 1 - with pytest.raises(ValueError, match="Unsupported expected_type.+"): + with pytest.raises(ValueError, match=r"Unsupported expected_type.+"): is_value_of_type(foo, Generator[int, None, None]) def test_type_doesnt_allow_callable(): - def foo(a): # noqa: ANN001, ANN202: dummy stuff within testing, nothing external + def foo(a): # noqa: ANN001, ANN202 # dummy stuff within testing, nothing external return "a" + str(a) - with pytest.raises(ValueError, match="Unsupported expected_type.+"): + with pytest.raises(ValueError, match=r"Unsupported expected_type.+"): is_value_of_type(foo, Callable[[int], str]) @@ -62,7 +62,7 @@ def test_type_allows_none(): def test_doesnt_allow_generic(): class X[T]: ... - with pytest.raises(ValueError, match="Unsupported expected_type.+"): + with pytest.raises(ValueError, match=r"Unsupported expected_type.+"): is_value_of_type(0, X[int])