Skip to content

Commit 48065a0

Browse files
committed
test.py: make logic for finding scripts clearer
We search for and find non-generated scripts (`.sh`, but not `.gen.sh`), whereas we record all generated scripts, which we then combine to get all scripts.
1 parent 3dea6a9 commit 48065a0

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

tests/__init__.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ class Test(object):
2222
"check": ["check.sh", "test.sh"]
2323
}
2424

25-
def __init__(self, directory: str, generated_scripts: set[Path]):
26-
self.scripts = {
27-
f.name for f in Path(directory).iterdir() if f.suffix == ".sh" and
28-
(".gen" not in f.suffixes or any(f.samefile(script) for script in generated_scripts))
29-
}
30-
self.dir = directory
31-
self.conf_file = os.path.join(directory, CONF_YML)
32-
self.name = os.path.basename(directory)
25+
def __init__(self, directory: Path, generated_scripts: set[Path]):
26+
# We only want scripts that have been generated by us now,
27+
# but non `*.gen*` scripts we can search for.
28+
non_gen_script_paths = { f for f in directory.iterdir() if f.suffix == ".sh" and ".gen" not in f.suffixes }
29+
script_paths = non_gen_script_paths | generated_scripts
30+
self.scripts = { str(script.relative_to(directory)) for script in script_paths }
31+
self.dir = str(directory)
32+
self.conf_file = str(directory / CONF_YML)
33+
self.name = directory.name
3334

3435
def run_script(self, stage, script, verbose=False, xfail=False) -> bool:
3536
"""
@@ -213,7 +214,7 @@ def run_tests(conf: Config, generated_scripts: set[Path]):
213214
if not conf.ignore_requirements:
214215
check(conf)
215216

216-
tests = [Test(td, generated_scripts) for td in conf.project_dirs]
217+
tests = [Test(Path(td), generated_scripts) for td in conf.project_dirs]
217218

218219
failure = False
219220
for tt in tests:

0 commit comments

Comments
 (0)