13from unittest.mock
import Mock
15import validationfunctions
17from validationtestutil
import create_fake_scripts
22 Tests the automated validation script discovery
26 with tempfile.TemporaryDirectory()
as tmpdir:
27 print(f
"Created temporary test folder {tmpdir}")
31 os.path.join(tmpdir,
"pkg1",
"validation"),
"pkg1_a.py"
34 os.path.join(tmpdir,
"pkg1",
"validation"),
"pkg1_b.py"
37 os.path.join(tmpdir,
"pkg1",
"validation"),
"pkg1_c.py"
41 os.path.join(tmpdir,
"pkg2",
"validation"),
"pkg2_b.py"
44 os.path.join(tmpdir,
"pkg2",
"validation"),
"pkg2_c.py"
49 os.path.join(tmpdir,
"some_other_folder",
"pkgother",
"validation"),
54 basepath = {
"local": str(tmpdir)}
57 location=
"local", basepaths=basepath, log=Mock()
62 or "pkg2" not in folders
63 or "some_other_folder" in folders
65 print(
"scripts were discovered in the wrong folders")
69 folders[
"pkg1"], Mock(),
".py"
73 len([s
for s
in scripts
if s.endswith(
"pkg1/validation/pkg1_a.py")])
76 print(
"script file was not discovered")
82 with tempfile.TemporaryDirectory()
as tmpdir:
83 print(f
"Created temporary test folder {tmpdir}")
87 os.path.join(tmpdir,
"pkg1",
"validation"),
"pkg1_a.py"
90 os.path.join(tmpdir,
"pkg1",
"validation"),
"pkg1_b.py"
93 os.path.join(tmpdir,
"pkg1",
"validation"),
"pkg1_c.py"
97 os.path.join(tmpdir,
"pkg2",
"validation"),
"pkg2_b.py"
100 os.path.join(tmpdir,
"pkg2",
"validation"),
"pkg2_c.py"
105 os.path.join(tmpdir,
"some_other_folder",
"pkgother",
"validation"),
110 basepath = {
"local": str(tmpdir),
"central": str(tmpdir)}
113 location=
"central", basepaths=basepath, log=Mock()
117 "pkg1" not in folders
118 or "pkg2" not in folders
119 or "some_other_folder" in folders
121 print(
"scripts were discovered in the wrong folders")
125if __name__ ==
"__main__":
Dict[str, str] get_validation_folders(str location, Dict[str, str] basepaths, logging.Logger log)
List[str] scripts_in_dir(str dirpath, logging.Logger log, ext="*")