Skip to content

Commit c86acd8

Browse files
committed
tests: Update merger tests to use shorter helper
1 parent 8ffd9fb commit c86acd8

1 file changed

Lines changed: 19 additions & 44 deletions

File tree

tests/test_merger.py

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,37 @@
22

33
from __future__ import annotations
44

5-
from textwrap import dedent
6-
7-
from griffe import GriffeLoader, temporary_pypackage
5+
from griffe import temporary_visited_package
86

97

108
def test_dont_trigger_alias_resolution_when_merging_stubs() -> None:
119
"""Assert that we don't trigger alias resolution when merging stubs."""
12-
with temporary_pypackage("package", ["mod.py", "mod.pyi"]) as tmp_package:
13-
tmp_package.path.joinpath("mod.py").write_text(
14-
dedent(
15-
"""
16-
import pathlib
17-
18-
def f() -> pathlib.Path:
19-
return pathlib.Path()
20-
""",
21-
),
22-
)
23-
tmp_package.path.joinpath("mod.pyi").write_text(
24-
dedent(
25-
"""
26-
import pathlib
27-
28-
def f() -> pathlib.Path: ...
29-
""",
30-
),
31-
)
32-
loader = GriffeLoader(search_paths=[tmp_package.tmpdir])
33-
loader.load(tmp_package.name)
10+
with temporary_visited_package(
11+
"package",
12+
{
13+
"mod.py": "import pathlib\n\ndef f() -> pathlib.Path:\n return pathlib.Path()",
14+
"mod.pyi": "import pathlib\n\ndef f() -> pathlib.Path: ...",
15+
},
16+
) as pkg:
17+
assert not pkg["mod.pathlib"].resolved
3418

3519

3620
def test_merge_stubs_on_wildcard_imported_objects() -> None:
3721
"""Assert that stubs can be merged on wildcard imported objects."""
38-
with temporary_pypackage("package", ["mod.py", "__init__.pyi"]) as tmp_package:
39-
tmp_package.path.joinpath("mod.py").write_text(
40-
dedent(
41-
"""
42-
class A:
43-
def hello(value: int | str) -> int | str:
44-
return value
45-
""",
46-
),
47-
)
48-
tmp_package.path.joinpath("__init__.py").write_text("from .mod import *")
49-
tmp_package.path.joinpath("__init__.pyi").write_text(
50-
dedent(
51-
"""
22+
with temporary_visited_package(
23+
"package",
24+
{
25+
"mod.py": "class A:\n def hello(value: int | str) -> int | str:\n return value",
26+
"__init__.py": "from .mod import *",
27+
"__init__.pyi": """
5228
from typing import overload
5329
class A:
5430
@overload
5531
def hello(value: int) -> int: ...
5632
@overload
5733
def hello(value: str) -> str: ...
5834
""",
59-
),
60-
)
61-
loader = GriffeLoader(search_paths=[tmp_package.tmpdir])
62-
module = loader.load(tmp_package.name)
63-
assert module["A.hello"].overloads
35+
},
36+
) as pkg:
37+
assert pkg["A.hello"].overloads
38+

0 commit comments

Comments
 (0)