mirror of
https://github.com/safishamsi/graphify.git
synced 2026-10-14 07:59:40 +00:00
fix: retract provisional package import edges
(cherry picked from commit 9a54565cb4)
This commit is contained in:
1 parent
3792ff1fda
commit
310b317355
2 files changed
+158
No files matched your search
@@ -256,3 +256,103 @@ def test_python_parameter_return_and_generic_contexts(tmp_path: Path):
|
||||
assert ("process()", "Payload", "parameter_type") in pairs
|
||||
assert ("process()", "Result", "return_type") in pairs
|
||||
assert ("process_many()", "Payload", "generic_arg") in pairs
|
||||
|
||||
|
||||
def test_issue_3777_package_module_collision_phantom_cycle_absent(tmp_path: Path):
|
||||
from graphify.analyze import find_import_cycles
|
||||
from graphify.build import build_from_json
|
||||
|
||||
nettacker_py = _write(
|
||||
tmp_path / "nettacker.py",
|
||||
"from nettacker.main import run\n\ndef cli():\n run()\n",
|
||||
)
|
||||
init_py = _write(tmp_path / "nettacker/__init__.py", "")
|
||||
main_py = _write(
|
||||
tmp_path / "nettacker/main.py",
|
||||
"from nettacker.core.app import Nettacker\n\ndef run():\n return Nettacker()\n",
|
||||
)
|
||||
app_py = _write(
|
||||
tmp_path / "nettacker/core/app.py",
|
||||
"from nettacker import logger\n\nclass Nettacker:\n def start(self):\n logger.log_info('start')\n",
|
||||
)
|
||||
logger_py = _write(
|
||||
tmp_path / "nettacker/logger.py",
|
||||
"def log_info(msg):\n print(msg)\n",
|
||||
)
|
||||
|
||||
result = extract(
|
||||
[nettacker_py, init_py, main_py, app_py, logger_py],
|
||||
cache_root=tmp_path,
|
||||
root=tmp_path,
|
||||
)
|
||||
|
||||
app_file = _node_id(result, "app.py", "nettacker/core/app.py")
|
||||
logger_file = _node_id(result, "logger.py", "nettacker/logger.py")
|
||||
nettacker_file = _node_id(result, "nettacker.py", "nettacker.py")
|
||||
|
||||
assert _has_edge(result, app_file, logger_file, "imports_from")
|
||||
assert not _has_edge(result, app_file, nettacker_file, "imports_from")
|
||||
|
||||
graph = build_from_json(result)
|
||||
assert find_import_cycles(graph) == []
|
||||
|
||||
|
||||
def test_issue_3777_nested_module_package_collision_resolves_to_submodule(tmp_path: Path):
|
||||
from graphify.analyze import find_import_cycles
|
||||
from graphify.build import build_from_json
|
||||
|
||||
runner_py = _write(
|
||||
tmp_path / "pkg/runner.py",
|
||||
"from pkg.runner.step import run\n\ndef start():\n run()\n",
|
||||
)
|
||||
init_py = _write(tmp_path / "pkg/runner/__init__.py", "")
|
||||
step_py = _write(
|
||||
tmp_path / "pkg/runner/step.py",
|
||||
"from pkg.runner import helper\n\ndef run():\n helper.work()\n",
|
||||
)
|
||||
helper_py = _write(
|
||||
tmp_path / "pkg/runner/helper.py",
|
||||
"def work():\n pass\n",
|
||||
)
|
||||
|
||||
result = extract(
|
||||
[runner_py, init_py, step_py, helper_py],
|
||||
cache_root=tmp_path,
|
||||
root=tmp_path,
|
||||
)
|
||||
|
||||
step_file = _node_id(result, "step.py", "pkg/runner/step.py")
|
||||
helper_file = _node_id(result, "helper.py", "pkg/runner/helper.py")
|
||||
runner_file = _node_id(result, "runner.py", "pkg/runner.py")
|
||||
|
||||
assert _has_edge(result, step_file, helper_file, "imports_from")
|
||||
assert not _has_edge(result, step_file, runner_file, "imports_from")
|
||||
|
||||
graph = build_from_json(result)
|
||||
assert find_import_cycles(graph) == []
|
||||
|
||||
|
||||
def test_issue_3777_namespace_package_submodule_import(tmp_path: Path):
|
||||
sub = _write(tmp_path / "ns/sub.py", "def helper():\n pass\n")
|
||||
consumer = _write(tmp_path / "ns/consumer.py", "from ns import sub\n")
|
||||
|
||||
result = extract([sub, consumer], cache_root=tmp_path, root=tmp_path)
|
||||
|
||||
consumer_file = _node_id(result, "consumer.py", "ns/consumer.py")
|
||||
sub_file = _node_id(result, "sub.py", "ns/sub.py")
|
||||
|
||||
assert _has_edge(result, consumer_file, sub_file, "imports_from")
|
||||
|
||||
|
||||
def test_issue_3777_standalone_module_import_unaffected(tmp_path: Path):
|
||||
standalone = _write(tmp_path / "standalone.py", "def fn():\n return 42\n")
|
||||
consumer = _write(tmp_path / "consumer.py", "from standalone import fn\n")
|
||||
|
||||
result = extract([standalone, consumer], cache_root=tmp_path, root=tmp_path)
|
||||
|
||||
consumer_file = _node_id(result, "consumer.py", "consumer.py")
|
||||
standalone_file = _node_id(result, "standalone.py", "standalone.py")
|
||||
fn_symbol = _node_id(result, "fn()", "standalone.py")
|
||||
|
||||
assert _has_edge(result, consumer_file, standalone_file, "imports_from")
|
||||
assert _has_edge(result, consumer_file, fn_symbol, "imports")
|
||||
Reference in new issue
Block a user