|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -import json |
4 | 3 | import tempfile |
5 | 4 | import unittest |
6 | 5 | from pathlib import Path |
@@ -51,15 +50,26 @@ def test_inventory_loader_and_candidate_ranking(self) -> None: |
51 | 50 | def test_file_comparison_does_not_execute_source(self) -> None: |
52 | 51 | with tempfile.TemporaryDirectory() as tmp: |
53 | 52 | 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 | + ) |
55 | 60 | a = Path(tmp) / "a.py" |
56 | 61 | b = Path(tmp) / "b.py" |
57 | 62 | a.write_text(source, encoding="utf-8") |
58 | 63 | b.write_text(source, encoding="utf-8") |
59 | 64 | result = compare_file_to_file(a, b) |
60 | 65 | self.assertFalse(marker.exists()) |
61 | 66 | 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"]) |
63 | 73 |
|
64 | 74 |
|
65 | 75 | if __name__ == "__main__": |
|
0 commit comments