Belle II Software
release-08-01-10
test_script_discovery.py
1
#!/usr/bin/env python3
2
3
10
11
import
sys
12
import
os
13
from
unittest.mock
import
Mock
14
import
tempfile
15
import
validationfunctions
16
17
from
validationtestutil
import
create_fake_scripts
18
19
20
def
main
():
21
"""
22
Tests the automated validation script discovery
23
"""
24
25
# will create a temporary folder and delete it once this block is left
26
with
tempfile.TemporaryDirectory()
as
tmpdir:
27
print(f
"Created temporary test folder {tmpdir}"
)
28
29
# create a couple of fake validation scripts
30
create_fake_scripts(
31
os.path.join(tmpdir,
"pkg1"
,
"validation"
),
"pkg1_a.py"
32
)
33
create_fake_scripts(
34
os.path.join(tmpdir,
"pkg1"
,
"validation"
),
"pkg1_b.py"
35
)
36
create_fake_scripts(
37
os.path.join(tmpdir,
"pkg1"
,
"validation"
),
"pkg1_c.py"
38
)
39
40
create_fake_scripts(
41
os.path.join(tmpdir,
"pkg2"
,
"validation"
),
"pkg2_b.py"
42
)
43
create_fake_scripts(
44
os.path.join(tmpdir,
"pkg2"
,
"validation"
),
"pkg2_c.py"
45
)
46
47
# this should not be found !
48
create_fake_scripts(
49
os.path.join(tmpdir,
"some_other_folder"
,
"pkgother"
,
"validation"
),
50
"pkgother_b.py"
,
51
)
52
53
# fake the basepath
54
basepath = {
"local"
: str(tmpdir)}
55
56
folders =
validationfunctions.get_validation_folders
(
57
location=
"local"
, basepaths=basepath, log=Mock()
58
)
59
60
if
(
61
"pkg1"
not
in
folders
62
or
"pkg2"
not
in
folders
63
or
"some_other_folder"
in
folders
64
):
65
print(
"scripts were discovered in the wrong folders"
)
66
sys.exit(1)
67
68
scripts =
validationfunctions.scripts_in_dir
(
69
folders[
"pkg1"
], Mock(),
".py"
70
)
71
72
if
(
73
len([s
for
s
in
scripts
if
s.endswith(
"pkg1/validation/pkg1_a.py"
)])
74
== 0
75
):
76
print(
"script file was not discovered"
)
77
sys.exit(1)
78
79
print(scripts)
80
81
# test for release and local case
82
with
tempfile.TemporaryDirectory()
as
tmpdir:
83
print(f
"Created temporary test folder {tmpdir}"
)
84
85
# create a couple of fake validation scripts
86
create_fake_scripts(
87
os.path.join(tmpdir,
"pkg1"
,
"validation"
),
"pkg1_a.py"
88
)
89
create_fake_scripts(
90
os.path.join(tmpdir,
"pkg1"
,
"validation"
),
"pkg1_b.py"
91
)
92
create_fake_scripts(
93
os.path.join(tmpdir,
"pkg1"
,
"validation"
),
"pkg1_c.py"
94
)
95
96
create_fake_scripts(
97
os.path.join(tmpdir,
"pkg2"
,
"validation"
),
"pkg2_b.py"
98
)
99
create_fake_scripts(
100
os.path.join(tmpdir,
"pkg2"
,
"validation"
),
"pkg2_c.py"
101
)
102
103
# this should not be found !
104
create_fake_scripts(
105
os.path.join(tmpdir,
"some_other_folder"
,
"pkgother"
,
"validation"
),
106
"pkgother_b.py"
,
107
)
108
109
# fake the basepath
110
basepath = {
"local"
: str(tmpdir),
"central"
: str(tmpdir)}
111
112
folders =
validationfunctions.get_validation_folders
(
113
location=
"central"
, basepaths=basepath, log=Mock()
114
)
115
116
if
(
117
"pkg1"
not
in
folders
118
or
"pkg2"
not
in
folders
119
or
"some_other_folder"
in
folders
120
):
121
print(
"scripts were discovered in the wrong folders"
)
122
sys.exit(1)
123
124
125
if
__name__ ==
"__main__"
:
126
main
()
main
Definition:
main.py:1
main
int main(int argc, char **argv)
Run all tests.
Definition:
test_main.cc:91
validationfunctions.scripts_in_dir
List[str] scripts_in_dir(str dirpath, logging.Logger log, ext="*")
Definition:
validationfunctions.py:336
validationfunctions.get_validation_folders
Dict[str, str] get_validation_folders(str location, Dict[str, str] basepaths, logging.Logger log)
Definition:
validationfunctions.py:128
validation
tests
test_script_discovery.py
Generated on Mon Sep 23 2024 14:07:13 for Belle II Software by
1.9.1