Skip to content

Commit 02bfa65

Browse files
committed
Present python-function-structure-comparator with reviewed source and examples
1 parent 4b39ad1 commit 02bfa65

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

‎tests/test_core.py‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import json
43
import tempfile
54
import unittest
65
from pathlib import Path
@@ -51,15 +50,26 @@ def test_inventory_loader_and_candidate_ranking(self) -> None:
5150
def test_file_comparison_does_not_execute_source(self) -> None:
5251
with tempfile.TemporaryDirectory() as tmp:
5352
marker = Path(tmp) / "marker.txt"
54-
source = f"def f():\n open({str(marker)!r}, 'w').write('bad')\n"
53+
# Both importing the module and calling its function would write.
54+
# POSIX spelling also exercises literal paths consistently on Windows.
55+
literal_path = marker.as_posix()
56+
source = (
57+
f"open({literal_path!r}, 'w').write('imported')\n"
58+
f"def f():\n open({literal_path!r}, 'w').write('called')\n"
59+
)
5560
a = Path(tmp) / "a.py"
5661
b = Path(tmp) / "b.py"
5762
a.write_text(source, encoding="utf-8")
5863
b.write_text(source, encoding="utf-8")
5964
result = compare_file_to_file(a, b)
6065
self.assertFalse(marker.exists())
6166
self.assertEqual(result["file_a"], "a.py")
62-
self.assertNotIn(str(Path(tmp)), json.dumps(result))
67+
self.assertEqual(result["file_b"], "b.py")
68+
# Input-location metadata uses basenames; literals in source must
69+
# remain available to the structural comparison, not be redacted.
70+
features = result["comparison"]["function_specific_comparison"]
71+
self.assertIn(literal_path, features["features_a"]["string_literals"])
72+
self.assertIn(literal_path, features["features_b"]["string_literals"])
6373

6474

6575
if __name__ == "__main__":

0 commit comments

Comments
 (0)