Coverage for tests / test_call_graph / test_formatters.py: 100%
28 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-08 15:04 -0800
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-08 15:04 -0800
1"""Tests for DOT format and external call filtering."""
3from __future__ import annotations
5from pathlib import Path
6import tempfile
8from call_graph import build_call_graph
9from call_graph.formatters import format_dot
12def test_format_dot():
13 code = """
14 def foo():
15 bar()
17 def bar():
18 baz()
20 def baz():
21 pass
22 """
23 with tempfile.NamedTemporaryFile(mode="w", suffix=".py", delete=False) as f:
24 f.write(code)
25 f.flush()
27 graph = build_call_graph([Path(f.name)])
28 dot_output = format_dot(graph)
30 assert "digraph call_graph" in dot_output
31 # Node IDs now use filepath:function_name format
32 filepath = f.name
33 assert f'"{filepath}:foo" -> "{filepath}:bar"' in dot_output
34 assert f'"{filepath}:bar" -> "{filepath}:baz"' in dot_output
36 Path(f.name).unlink()
39def test_format_dot_filters_external():
40 code = """
41 def foo():
42 print("hello")
43 bar()
45 def bar():
46 pass
47 """
48 with tempfile.NamedTemporaryFile(mode="w", suffix=".py", delete=False) as f:
49 f.write(code)
50 f.flush()
52 graph = build_call_graph([Path(f.name)])
53 dot_output = format_dot(graph)
55 # External calls should be filtered out
56 assert "print" not in dot_output
57 # Only internal calls should appear
58 filepath = f.name
59 assert f'"{filepath}:foo" -> "{filepath}:bar"' in dot_output
61 Path(f.name).unlink()