diff --git a/config/coverage.ini b/config/coverage.ini index 728a0ebb..110f3750 100644 --- a/config/coverage.ini +++ b/config/coverage.ini @@ -4,7 +4,8 @@ parallel = true source = packages/griffelib/src/griffe packages/griffecli/src/griffecli - tests/ + packages/griffecli/tests/ + packages/griffelib/tests/ [coverage:paths] equivalent = @@ -17,8 +18,8 @@ precision = 2 omit = src/*/__init__.py src/*/__main__.py - tests/__init__.py - tests/tmp/* + packages/*/tests/__init__.py + packages/*/tests/tmp/* exclude_lines = pragma: no cover if TYPE_CHECKING diff --git a/config/pytest.ini b/config/pytest.ini index 4c999a01..49df537b 100644 --- a/config/pytest.ini +++ b/config/pytest.ini @@ -1,11 +1,11 @@ [pytest] python_files = - test_*.py + packages/*/tests/**/test_*.py addopts = --cov --cov-config config/coverage.ini testpaths = - tests + packages/*/tests # action:message_regex:warning_class:module_regex:line filterwarnings = diff --git a/config/ruff.toml b/config/ruff.toml index 8193ff81..3c060b59 100644 --- a/config/ruff.toml +++ b/config/ruff.toml @@ -4,7 +4,7 @@ output-format = "concise" [lint] exclude = [ - "tests/fixtures/*.py", + "packages/*/tests/fixtures/*.py", ] select = ["ALL"] ignore = [ @@ -65,11 +65,11 @@ logger-objects = ["griffe.logger"] "INP001", # File is part of an implicit namespace package "T201", # Print statement ] -"tests/test_git.py" = [ +"packages/griffelib/tests/test_git.py" = [ "S603", # `subprocess` call: check for execution of untrusted input "S607", # Starting a process with a partial executable path ] -"tests/**.py" = [ +"packages/*/tests/**.py" = [ "ARG005", # Unused lambda argument "FBT001", # Boolean positional arg in function definition "PLC1901", # a == "" can be simplified to not a @@ -91,7 +91,7 @@ convention = "google" [format] exclude = [ - "tests/fixtures/*.py", + "packages/*/tests/fixtures/*.py", ] docstring-code-format = true docstring-code-line-length = 80 diff --git a/config/ty.toml b/config/ty.toml index 0c5fc4b8..e35b6572 100644 --- a/config/ty.toml +++ b/config/ty.toml @@ -1,5 +1,5 @@ [src] -exclude = ["tests/fixtures"] +exclude = ["packages/*/tests/fixtures"] [terminal] error-on-warning = true diff --git a/config/vscode/launch.json b/config/vscode/launch.json index a8b3381f..8736c855 100644 --- a/config/vscode/launch.json +++ b/config/vscode/launch.json @@ -41,7 +41,6 @@ "-vvv", "--no-cov", "--dist=no", - "tests", "-k=${input:tests_selection}" ] } @@ -54,4 +53,4 @@ "default": "" } ] -} \ No newline at end of file +} diff --git a/docs/guide/contributors/architecture.md b/docs/guide/contributors/architecture.md index 75847068..000f945c 100644 --- a/docs/guide/contributors/architecture.md +++ b/docs/guide/contributors/architecture.md @@ -24,7 +24,8 @@ descriptions = { "src": "The source of our Python package(s). See [Sources](#sources) and [Program structure](#program-structure).", "src/griffe": "Our public API, exposed to users. See [Program structure](#program-structure).", "packages/griffelib/src/griffe/_internal": "Our internal API, hidden from users. See [Program structure](#program-structure).", - "tests": "Our test suite. See [Tests](#tests).", + "packages/griffecli/tests": "Our test suite. See [Tests](#tests).", + "packages/griffelib/tests": "Our test suite. See [Tests](#tests).", ".copier-answers.yml": "The answers file generated by [Copier](https://copier.readthedocs.io/en/stable/). See [Boilerplate](#boilerplate).", "devdeps.txt": "Our development dependencies specification. See [`make setup`][command-setup] command.", "duties.py": "Our project tasks, written with [duty](https://pawamoy.github.io/duty). See [Tasks][tasks].", diff --git a/docs/guide/users/recommendations/public-apis.md b/docs/guide/users/recommendations/public-apis.md index 9a0d1cbb..2a790e35 100644 --- a/docs/guide/users/recommendations/public-apis.md +++ b/docs/guide/users/recommendations/public-apis.md @@ -444,7 +444,7 @@ In this script, we find our entrypoint, `griffe.main`, used programmatically. The second user of your CLI as API is... you again. When you write tests for your CLI, you import your entrypoints and call them by passing CLI options and arguments, maybe asserting the exit code raised with a `SystemExit` or the standard output/error thanks to [pytest's capture fixtures](https://docs.pytest.org/en/6.2.x/capture.html). Some simplified examples from our own test suite: -```python title="tests/test_cli.py" +```python import pytest import griffe diff --git a/duties.py b/duties.py index e6aee018..965960a9 100644 --- a/duties.py +++ b/duties.py @@ -20,7 +20,7 @@ from duty.context import Context -PY_SRC_PATHS = (Path(_) for _ in ("packages/griffecli/src", "packages/griffelib/src", "tests", "duties.py", "scripts")) +PY_SRC_PATHS = (Path(_) for _ in ("packages", "duties.py", "scripts")) PY_SRC_LIST = tuple(str(_) for _ in PY_SRC_PATHS) PY_SRC = " ".join(PY_SRC_LIST) CI = os.environ.get("CI", "0") in {"1", "true", "yes", ""} @@ -41,7 +41,7 @@ def _pyprefix(title: str) -> str: def _get_changelog_version() -> str: changelog_version_re = re.compile(r"^## \[(\d+\.\d+\.\d+)\].*$") with Path(__file__).parent.joinpath("CHANGELOG.md").open("r", encoding="utf8") as file: - return next(filter(bool, map(changelog_version_re.match, file))).group(1) # ty:ignore[invalid-argument-type,unresolved-attribute] + return next(filter(bool, map(changelog_version_re.match, file))).group(1) # ty:ignore[unresolved-attribute] @duty @@ -460,7 +460,6 @@ def test(ctx: Context, *cli_args: str) -> None: os.environ["PYTHONWARNDEFAULTENCODING"] = "1" ctx.run( tools.pytest( - "tests", config_file="config/pytest.ini", color="yes", ).add_args("-n", "auto", *cli_args), diff --git a/packages/griffecli/tests/__init__.py b/packages/griffecli/tests/__init__.py new file mode 100644 index 00000000..bc96b040 --- /dev/null +++ b/packages/griffecli/tests/__init__.py @@ -0,0 +1 @@ +"""Tests suite for `griffecli`.""" diff --git a/tests/test_cli.py b/packages/griffecli/tests/test_cli.py similarity index 100% rename from tests/test_cli.py rename to packages/griffecli/tests/test_cli.py diff --git a/packages/griffelib/src/griffe/_internal/expressions.py b/packages/griffelib/src/griffe/_internal/expressions.py index 99a5b90a..4043c04b 100644 --- a/packages/griffelib/src/griffe/_internal/expressions.py +++ b/packages/griffelib/src/griffe/_internal/expressions.py @@ -759,7 +759,7 @@ def canonical_path(self) -> str: return f"{self.parent.canonical_path}.{self.name}" if isinstance(self.parent, str): return f"{self.parent}.{self.name}" - parent = self.parent.members.get(self.member, self.parent) # ty:ignore[no-matching-overload] + parent = self.parent.members.get(self.member, self.parent) try: return parent.resolve(self.name) except NameResolutionError: @@ -1108,7 +1108,7 @@ def iterate(self, *, flat: bool = True) -> Iterator[str | Expr]: def _get_precedence(expr: Expr) -> _OperatorPrecedence: - return _precedence_map.get(type(expr), lambda _: _OperatorPrecedence.NONE)(expr) # ty:ignore[no-matching-overload] + return _precedence_map.get(type(expr), lambda _: _OperatorPrecedence.NONE)(expr) def _build_attribute(node: ast.Attribute, parent: Module | Class, **kwargs: Any) -> Expr: @@ -1198,7 +1198,7 @@ def _build_constant( ) else: return _build(parsed.body, parent, **kwargs) # ty:ignore[unresolved-attribute] - return {type(...): lambda _: "..."}.get(type(node.value), repr)(node.value) # ty:ignore[no-matching-overload] + return {type(...): lambda _: "..."}.get(type(node.value), repr)(node.value) def _build_dict(node: ast.Dict, parent: Module | Class, **kwargs: Any) -> Expr: diff --git a/packages/griffelib/src/griffe/_internal/loader.py b/packages/griffelib/src/griffe/_internal/loader.py index 51d6cb78..a9c4edcd 100644 --- a/packages/griffelib/src/griffe/_internal/loader.py +++ b/packages/griffelib/src/griffe/_internal/loader.py @@ -304,7 +304,7 @@ def expand_exports(self, module: Module, seen: set | None = None) -> None: if module.exports is None: return - expanded = [] + expanded: list[str | ExprName] = [] for export in module.exports: # It's a name: we resolve it, get the module it comes from, # recurse into it, and add its exports to the current ones. @@ -416,7 +416,7 @@ def expand_wildcards( if already_present: old_member = obj.get_member(new_member.name) old_lineno = old_member.alias_lineno if old_member.is_alias else old_member.lineno - overwrite = alias_lineno > (old_lineno or 0) + overwrite = (alias_lineno or 0) > (old_lineno or 0) # 1. If the expanded member is an alias with a target path equal to its own path, we stop. # This situation can arise because of Griffe's mishandling of (abusive) wildcard imports. diff --git a/tests/__init__.py b/packages/griffelib/tests/__init__.py similarity index 100% rename from tests/__init__.py rename to packages/griffelib/tests/__init__.py diff --git a/tests/conftest.py b/packages/griffelib/tests/conftest.py similarity index 100% rename from tests/conftest.py rename to packages/griffelib/tests/conftest.py diff --git a/tests/fixtures/_repo/v0.1.0/my_module/__init__.py b/packages/griffelib/tests/fixtures/_repo/v0.1.0/my_module/__init__.py similarity index 100% rename from tests/fixtures/_repo/v0.1.0/my_module/__init__.py rename to packages/griffelib/tests/fixtures/_repo/v0.1.0/my_module/__init__.py diff --git a/tests/fixtures/_repo/v0.2.0/my_module/__init__.py b/packages/griffelib/tests/fixtures/_repo/v0.2.0/my_module/__init__.py similarity index 100% rename from tests/fixtures/_repo/v0.2.0/my_module/__init__.py rename to packages/griffelib/tests/fixtures/_repo/v0.2.0/my_module/__init__.py diff --git a/tests/helpers.py b/packages/griffelib/tests/helpers.py similarity index 100% rename from tests/helpers.py rename to packages/griffelib/tests/helpers.py diff --git a/tests/test_api.py b/packages/griffelib/tests/test_api.py similarity index 100% rename from tests/test_api.py rename to packages/griffelib/tests/test_api.py diff --git a/tests/test_diff.py b/packages/griffelib/tests/test_diff.py similarity index 100% rename from tests/test_diff.py rename to packages/griffelib/tests/test_diff.py diff --git a/tests/test_docstrings/__init__.py b/packages/griffelib/tests/test_docstrings/__init__.py similarity index 100% rename from tests/test_docstrings/__init__.py rename to packages/griffelib/tests/test_docstrings/__init__.py diff --git a/tests/test_docstrings/conftest.py b/packages/griffelib/tests/test_docstrings/conftest.py similarity index 100% rename from tests/test_docstrings/conftest.py rename to packages/griffelib/tests/test_docstrings/conftest.py diff --git a/tests/test_docstrings/helpers.py b/packages/griffelib/tests/test_docstrings/helpers.py similarity index 100% rename from tests/test_docstrings/helpers.py rename to packages/griffelib/tests/test_docstrings/helpers.py diff --git a/tests/test_docstrings/test_google.py b/packages/griffelib/tests/test_docstrings/test_google.py similarity index 100% rename from tests/test_docstrings/test_google.py rename to packages/griffelib/tests/test_docstrings/test_google.py diff --git a/tests/test_docstrings/test_numpy.py b/packages/griffelib/tests/test_docstrings/test_numpy.py similarity index 100% rename from tests/test_docstrings/test_numpy.py rename to packages/griffelib/tests/test_docstrings/test_numpy.py diff --git a/tests/test_docstrings/test_sphinx.py b/packages/griffelib/tests/test_docstrings/test_sphinx.py similarity index 100% rename from tests/test_docstrings/test_sphinx.py rename to packages/griffelib/tests/test_docstrings/test_sphinx.py diff --git a/tests/test_docstrings/test_warnings.py b/packages/griffelib/tests/test_docstrings/test_warnings.py similarity index 100% rename from tests/test_docstrings/test_warnings.py rename to packages/griffelib/tests/test_docstrings/test_warnings.py diff --git a/tests/test_encoders.py b/packages/griffelib/tests/test_encoders.py similarity index 92% rename from tests/test_encoders.py rename to packages/griffelib/tests/test_encoders.py index d700c30a..8e967632 100644 --- a/tests/test_encoders.py +++ b/packages/griffelib/tests/test_encoders.py @@ -4,6 +4,7 @@ import json import sys +from pathlib import Path import pytest from jsonschema import ValidationError, validate @@ -91,7 +92,10 @@ def test_minimal_light_data_is_enough(symbol: str) -> None: # YORE: EOL 3.12: Remove block. # YORE: EOL 3.11: Remove line. -@pytest.mark.skipif(sys.version_info < (3, 12), reason="Python less than 3.12 does not have PEP 695 generics") +@pytest.mark.skipif( + sys.version_info < (3, 12), + reason="Python less than 3.12 does not have PEP 695 generics", +) def test_encoding_pep695_generics_without_defaults() -> None: """Test serialization and de-serialization of PEP 695 generics without defaults. @@ -159,6 +163,10 @@ def _validate(obj: dict, schema: dict) -> None: raise +@pytest.mark.skipif( + not Path("docs", "schema.json").exists(), + reason="schema.json not available", +) def test_json_schema() -> None: """Assert that our serialized data matches our JSON schema.""" loader = GriffeLoader() @@ -172,7 +180,14 @@ def test_json_schema() -> None: # YORE: EOL 3.12: Remove block. # YORE: EOL 3.11: Remove line. -@pytest.mark.skipif(sys.version_info < (3, 12), reason="Python less than 3.12 does not have PEP 695 generics") +@pytest.mark.skipif( + sys.version_info < (3, 12), + reason="Python less than 3.12 does not have PEP 695 generics", +) +@pytest.mark.skipif( + not Path("docs", "schema.json").exists(), + reason="schema.json not available", +) def test_json_schema_for_pep695_generics_without_defaults() -> None: """Assert that serialized PEP 695 generics without defaults match our JSON schema. @@ -193,6 +208,10 @@ def func[**P, T, *R](arg: T, *args: P.args, **kwargs: P.kwargs) -> tuple[*R]: pa # YORE: EOL 3.12: Remove line. @pytest.mark.skipif(sys.version_info < (3, 13), reason="Python less than 3.13 does not have defaults in PEP 695 generics") # fmt: skip +@pytest.mark.skipif( + not Path("docs", "schema.json").exists(), + reason="schema.json not available", +) def test_json_schema_for_pep695_generics() -> None: """Assert that serialized PEP 695 generics with defaults match our JSON schema. diff --git a/tests/test_expressions.py b/packages/griffelib/tests/test_expressions.py similarity index 100% rename from tests/test_expressions.py rename to packages/griffelib/tests/test_expressions.py diff --git a/tests/test_extensions/__init__.py b/packages/griffelib/tests/test_extensions/__init__.py similarity index 100% rename from tests/test_extensions/__init__.py rename to packages/griffelib/tests/test_extensions/__init__.py diff --git a/tests/test_extensions/test_base.py b/packages/griffelib/tests/test_extensions/test_base.py similarity index 88% rename from tests/test_extensions/test_base.py rename to packages/griffelib/tests/test_extensions/test_base.py index 2b4ed21f..712e71b3 100644 --- a/tests/test_extensions/test_base.py +++ b/packages/griffelib/tests/test_extensions/test_base.py @@ -2,7 +2,9 @@ from __future__ import annotations +import os import sys +from contextlib import contextmanager from pathlib import Path from typing import TYPE_CHECKING, Any @@ -14,17 +16,40 @@ GriffeLoader, ObjectNode, load_extensions, + sys_path, temporary_visited_module, temporary_visited_package, ) -from griffe._internal.models import Attribute, Class, Function, Module, Object, TypeAlias +from griffe._internal.models import ( + Attribute, + Class, + Function, + Module, + Object, + TypeAlias, +) if TYPE_CHECKING: import ast + from collections.abc import Iterator from griffe import Attribute, Class, Function, Module, Object, ObjectNode, TypeAlias +PACKAGE_ROOT = Path(__file__).parent.parent.parent + + +@contextmanager +def cd(path: str | Path) -> Iterator[None]: + """Change directory to `path` and restore the previous directory on exit.""" + old_path = Path.cwd() + os.chdir(path) + try: + yield + finally: + os.chdir(old_path) + + class AnalysisEventsTest(Extension): # noqa: D101 def __init__(self, *args: Any, **kwargs: Any) -> None: # noqa: D107 super().__init__() @@ -101,17 +126,20 @@ def on_alias_instance(self, *, node: ast.AST | ObjectNode, alias: Alias, **kwarg # With class. AnalysisEventsTest, # With absolute paths (esp. important to test for Windows). - Path("tests/test_extensions/test_base.py").absolute().as_posix(), - Path("tests/test_extensions/test_base.py:AnalysisEventsTest").absolute().as_posix(), + PACKAGE_ROOT.joinpath("tests/test_extensions/test_base.py").absolute().as_posix(), + PACKAGE_ROOT.joinpath("tests/test_extensions/test_base.py:AnalysisEventsTest").absolute().as_posix(), ], ) -def test_loading_extensions(extension: str | dict[str, dict[str, Any]] | Extension | type[Extension]) -> None: +def test_loading_extensions( + extension: str | dict[str, dict[str, Any]] | Extension | type[Extension], +) -> None: """Test the extensions loading mechanisms. Parameters: extension: Extension specification (parametrized). """ - extensions = load_extensions(extension) + with cd(PACKAGE_ROOT), sys_path(PACKAGE_ROOT, *sys.path): + extensions = load_extensions(extension) loaded: AnalysisEventsTest = extensions._extensions[0] # ty:ignore[invalid-assignment] # We cannot use isinstance here, # because loading from a filepath drops the parent `tests` package, @@ -157,7 +185,10 @@ def method(self): ... # YORE: EOL 3.11: Remove line. -@pytest.mark.skipif(sys.version_info < (3, 12), reason="Python less than 3.12 does not have PEP 695 type aliases") +@pytest.mark.skipif( + sys.version_info < (3, 12), + reason="Python less than 3.12 does not have PEP 695 type aliases", +) def test_analysis_events() -> None: """Test analysis events triggering.""" extension = AnalysisEventsTest() @@ -259,7 +290,10 @@ def method(self): ... # YORE: EOL 3.11: Remove line. -@pytest.mark.skipif(sys.version_info < (3, 12), reason="Python less than 3.12 does not have PEP 695 type aliases") +@pytest.mark.skipif( + sys.version_info < (3, 12), + reason="Python less than 3.12 does not have PEP 695 type aliases", +) def test_load_events() -> None: """Test load events triggering.""" extension = LoadEventsTest() diff --git a/tests/test_extensions/test_dataclasses.py b/packages/griffelib/tests/test_extensions/test_dataclasses.py similarity index 100% rename from tests/test_extensions/test_dataclasses.py rename to packages/griffelib/tests/test_extensions/test_dataclasses.py diff --git a/tests/test_extensions/test_unpack_typeddict.py b/packages/griffelib/tests/test_extensions/test_unpack_typeddict.py similarity index 100% rename from tests/test_extensions/test_unpack_typeddict.py rename to packages/griffelib/tests/test_extensions/test_unpack_typeddict.py diff --git a/tests/test_finder.py b/packages/griffelib/tests/test_finder.py similarity index 87% rename from tests/test_finder.py rename to packages/griffelib/tests/test_finder.py index c45ff0ce..d5048ede 100644 --- a/tests/test_finder.py +++ b/packages/griffelib/tests/test_finder.py @@ -13,7 +13,13 @@ @pytest.mark.parametrize( - ("pypackage", "module", "add_to_search_path", "expected_top_name", "expected_top_path"), + ( + "pypackage", + "module", + "add_to_search_path", + "expected_top_name", + "expected_top_path", + ), [ (("a", ["b.py"]), "a/b.py", True, "a", "a/__init__.py"), (("a", ["b.py"]), "a/b.py", False, "a", "a/__init__.py"), @@ -38,7 +44,9 @@ def test_find_module_with_path( expected_top_path: Expected top module path (parametrized). """ with temporary_pypackage(*pypackage) as tmp_package: - finder = ModuleFinder(search_paths=[tmp_package.tmpdir] if add_to_search_path else None) + finder = ModuleFinder( + search_paths=[tmp_package.tmpdir] if add_to_search_path else None, + ) _, package = finder.find_spec(tmp_package.tmpdir / module) assert package.name == expected_top_name if isinstance(package, NamespacePackage): @@ -64,8 +72,14 @@ def test_find_pkg_style_namespace_packages(statement: str) -> None: temporary_pypackage("namespace/package1") as tmp_package1, temporary_pypackage("namespace/package2") as tmp_package2, ): - tmp_package1.path.parent.joinpath("__init__.py").write_text(statement, encoding="utf8") - tmp_package2.path.parent.joinpath("__init__.py").write_text(statement, encoding="utf8") + tmp_package1.path.parent.joinpath("__init__.py").write_text( + statement, + encoding="utf8", + ) + tmp_package2.path.parent.joinpath("__init__.py").write_text( + statement, + encoding="utf8", + ) finder = ModuleFinder(search_paths=[tmp_package1.tmpdir, tmp_package2.tmpdir]) _, package = finder.find_spec("namespace") assert package.name == "namespace" @@ -117,7 +131,10 @@ def test_pth_file_handling_with_semi_colon(tmp_path: Path) -> None: assert paths == [Path("tests")] -@pytest.mark.parametrize("editable_file_name", ["__editables_whatever.py", "_editable_impl_whatever.py"]) +@pytest.mark.parametrize( + "editable_file_name", + ["__editables_whatever.py", "_editable_impl_whatever.py"], +) def test_editables_file_handling(tmp_path: Path, editable_file_name: str) -> None: """Assert editable modules by `editables` are handled. @@ -125,7 +142,10 @@ def test_editables_file_handling(tmp_path: Path, editable_file_name: str) -> Non tmp_path: Pytest fixture. """ pth_file = tmp_path / editable_file_name - pth_file.write_text("hello\nF.map_module('griffe', 'packages/griffelib/src/griffe/__init__.py')", encoding="utf8") + pth_file.write_text( + "hello\nF.map_module('griffe', 'packages/griffelib/src/griffe/__init__.py')", + encoding="utf8", + ) paths = [sp.path for sp in _handle_editable_module(pth_file)] assert paths == [Path("packages/griffelib/src")] @@ -139,13 +159,19 @@ def test_setuptools_file_handling(tmp_path: Path, annotation: str) -> None: annotation: The type annotation of the MAPPING variable. """ pth_file = tmp_path / "__editable__whatever.py" - pth_file.write_text(f"hello\nMAPPING{annotation} = {{'griffe': 'src/griffe'}}", encoding="utf8") + pth_file.write_text( + f"hello\nMAPPING{annotation} = {{'griffe': 'src/griffe'}}", + encoding="utf8", + ) paths = [sp.path for sp in _handle_editable_module(pth_file)] assert paths == [Path("src")] @pytest.mark.parametrize("annotation", ["", ": dict[str, str]"]) -def test_setuptools_file_handling_multiple_paths(tmp_path: Path, annotation: str) -> None: +def test_setuptools_file_handling_multiple_paths( + tmp_path: Path, + annotation: str, +) -> None: """Assert editable modules by `setuptools` are handled when multiple packages are installed in the same editable. Parameters: @@ -182,6 +208,10 @@ def test_scikit_build_core_file_handling(tmp_path: Path) -> None: assert paths == [Path("/path/to/whatever")] +@pytest.mark.skipif( + not Path("packages", "griffelib").exists(), + reason="not running from monorepo root", +) def test_meson_python_file_handling(tmp_path: Path) -> None: """Assert editable modules by `meson-python` are handled. @@ -258,10 +288,18 @@ def test_finding_stubs_packages( if expect == "none": with pytest.raises(ModuleNotFoundError): - finder.find_spec("package", try_relative_path=False, find_stubs_package=find_stubs) + finder.find_spec( + "package", + try_relative_path=False, + find_stubs_package=find_stubs, + ) return - name, result = finder.find_spec("package", try_relative_path=False, find_stubs_package=find_stubs) + name, result = finder.find_spec( + "package", + try_relative_path=False, + find_stubs_package=find_stubs, + ) assert name == "package" if expect == "both": @@ -291,7 +329,12 @@ def test_scanning_package_and_module_with_same_names(namespace_package: bool) -> namespace_package: Whether the temporary package is a namespace one. """ init = not namespace_package - with temporary_pypackage("pkg", ["pkg/mod.py", "mod/mod.py"], init=init, inits=init) as tmp_package: + with temporary_pypackage( + "pkg", + ["pkg/mod.py", "mod/mod.py"], + init=init, + inits=init, + ) as tmp_package: # Here we must make sure that all paths are relative # to correctly assert the finder's behavior, # so we pass `.` and actually enter the temporary directory. @@ -314,7 +357,12 @@ def test_scanning_package_and_module_with_same_names(namespace_package: bool) -> def test_not_finding_namespace_package_twice() -> None: """Deduplicate paths when finding namespace packages.""" - with temporary_pypackage("pkg", ["pkg/mod.py", "mod/mod.py"], init=False, inits=False) as tmp_package: + with temporary_pypackage( + "pkg", + ["pkg/mod.py", "mod/mod.py"], + init=False, + inits=False, + ) as tmp_package: old = Path.cwd() os.chdir(tmp_package.tmpdir) try: diff --git a/tests/test_functions.py b/packages/griffelib/tests/test_functions.py similarity index 100% rename from tests/test_functions.py rename to packages/griffelib/tests/test_functions.py diff --git a/tests/test_git.py b/packages/griffelib/tests/test_git.py similarity index 100% rename from tests/test_git.py rename to packages/griffelib/tests/test_git.py diff --git a/tests/test_inheritance.py b/packages/griffelib/tests/test_inheritance.py similarity index 100% rename from tests/test_inheritance.py rename to packages/griffelib/tests/test_inheritance.py diff --git a/tests/test_inspector.py b/packages/griffelib/tests/test_inspector.py similarity index 100% rename from tests/test_inspector.py rename to packages/griffelib/tests/test_inspector.py diff --git a/tests/test_loader.py b/packages/griffelib/tests/test_loader.py similarity index 100% rename from tests/test_loader.py rename to packages/griffelib/tests/test_loader.py diff --git a/tests/test_merger.py b/packages/griffelib/tests/test_merger.py similarity index 100% rename from tests/test_merger.py rename to packages/griffelib/tests/test_merger.py diff --git a/tests/test_mixins.py b/packages/griffelib/tests/test_mixins.py similarity index 100% rename from tests/test_mixins.py rename to packages/griffelib/tests/test_mixins.py diff --git a/tests/test_models.py b/packages/griffelib/tests/test_models.py similarity index 100% rename from tests/test_models.py rename to packages/griffelib/tests/test_models.py diff --git a/tests/test_nodes.py b/packages/griffelib/tests/test_nodes.py similarity index 100% rename from tests/test_nodes.py rename to packages/griffelib/tests/test_nodes.py diff --git a/tests/test_public_api.py b/packages/griffelib/tests/test_public_api.py similarity index 100% rename from tests/test_public_api.py rename to packages/griffelib/tests/test_public_api.py diff --git a/tests/test_stdlib.py b/packages/griffelib/tests/test_stdlib.py similarity index 100% rename from tests/test_stdlib.py rename to packages/griffelib/tests/test_stdlib.py diff --git a/tests/test_visitor.py b/packages/griffelib/tests/test_visitor.py similarity index 100% rename from tests/test_visitor.py rename to packages/griffelib/tests/test_visitor.py diff --git a/scripts/get_version.py b/scripts/get_version.py index bf968c5c..1c3411da 100644 --- a/scripts/get_version.py +++ b/scripts/get_version.py @@ -22,7 +22,7 @@ def get_version() -> str: if scm_version.version <= Version("0.1"): # Missing Git tags? with suppress(OSError, StopIteration): # noqa: SIM117 with _changelog.open("r", encoding="utf8") as file: - match = next(filter(None, map(_changelog_version_re.match, file))) # ty:ignore[invalid-argument-type] + match = next(filter(None, map(_changelog_version_re.match, file))) scm_version = scm_version._replace(version=Version(match.group(1))) return default_version_formatter(scm_version)