SXXXXXXX_PyUCC/tests/test_scanner.py
2025-11-25 12:18:55 +01:00

44 lines
1.2 KiB
Python

import os
from pathlib import Path
from pyucc.core.scanner import _normalize_extensions, find_source_files
def test_normalize_extensions():
exts = ["py", ".PY", "", " txt "]
out = _normalize_extensions(exts)
assert ".py" in out
assert ".txt" in out
assert "" not in out
def test_find_source_files_allowed_and_ignore(tmp_path):
# create directory tree
d = tmp_path / "proj"
d.mkdir()
sub = d / "sub"
sub.mkdir()
f1 = d / "a.py"
f1.write_text("print('hello')\n")
f2 = d / "b.txt"
f2.write_text("just text\n")
f3 = d / "bin.exe"
f3.write_text("binary")
f4 = sub / "c.py"
f4.write_text("# comment\n\nprint(1)\n")
# allowed extensions filter
found = find_source_files(d, allowed_extensions=['.py'])
found_names = {p.name for p in found}
assert 'a.py' in found_names
assert 'c.py' in found_names
assert 'b.txt' not in found_names
assert 'bin.exe' not in found_names
# ignore patterns (ignore sub directory)
found2 = find_source_files(d, allowed_extensions=None, ignore_patterns=['sub'])
names2 = {p.name for p in found2}
assert 'a.py' in names2
assert 'c.py' not in names2