Skip to content

Commit bfe184b

Browse files
committed
test(project): render bash argv findings with ast.get_source_segment (#2306)
The #2306 scan test called ast.unparse, which is 3.9+, outside a version gate, so the #1899 guard failed Project tests on every PR merged with main. ast.get_source_segment (3.8+) renders the same finding. Tests: test_bash_startup_files_2306 and test_ast_unparse_is_gated_1899_unit pass (6 passed).
1 parent bb017ff commit bfe184b

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎tests/project/test_bash_startup_files_2306.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ def test_no_module_spells_out_a_bash_argv(self) -> None:
100100
for path in sorted(TESTS.rglob('*.py')):
101101
if path.resolve() == pathlib.Path(__file__).resolve():
102102
continue
103-
tree = ast.parse(path.read_text(encoding='utf-8'), str(path))
104-
found.extend(f'{path.relative_to(TESTS.parent).as_posix()}:{node.lineno}: {ast.unparse(node)}'
103+
source = path.read_text(encoding='utf-8')
104+
tree = ast.parse(source, str(path))
105+
found.extend(f'{path.relative_to(TESTS.parent).as_posix()}:{node.lineno}: '
106+
f'{ast.get_source_segment(source, node)}'
105107
for node in ast.walk(tree) if is_bash_argv(node))
106108
self.assertEqual(found, [], 'build these with tests._support.bash_argv')
107109

0 commit comments

Comments
 (0)