Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pycalibration
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
calibration
pycalibration
Commits
91afb1a6
Commit
91afb1a6
authored
3 years ago
by
Karim Ahmed
Browse files
Options
Downloads
Patches
Plain Diff
common out-folder and reference folder for tests
parent
795d78e8
No related branches found
No related tags found
1 merge request
!610
Add a pytest to run a dict of CALLAB test runs before releases
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/callab_tests.yaml
+288
-331
288 additions, 331 deletions
tests/callab_tests.yaml
tests/test_pre_deployment.py
+26
-15
26 additions, 15 deletions
tests/test_pre_deployment.py
with
314 additions
and
346 deletions
tests/callab_tests.yaml
+
288
−
331
View file @
91afb1a6
This diff is collapsed.
Click to expand it.
tests/test_pre_deployment.py
+
26
−
15
View file @
91afb1a6
...
...
@@ -17,13 +17,17 @@ import pathlib
import
time
from
contextlib
import
redirect_stdout
from
subprocess
import
PIPE
,
run
from
typing
import
Any
,
Dict
,
List
from
typing
import
Any
,
Dict
,
List
,
Tuple
import
pytest
import
yaml
import
xfel_calibrate.calibrate
as
calibrate
REFERENCE_FOLDER
=
"
/gpfs/exfel/data/scratch/ahmedk/test/remove/pytest
"
OUT_FOLDER
=
"
/gpfs/exfel/data/scratch/ahmedk/test/remove/pytest
"
with
open
(
"
./callab_tests.yaml
"
,
"
r
"
)
as
f
:
callab_test_dict
=
yaml
.
load
(
f
)
...
...
@@ -43,7 +47,7 @@ def validate_h5files(f, reference):
return
filemd5
(
f
)
==
filemd5
(
reference
/
f
.
name
),
f
def
parse_config
(
cmd
:
List
[
str
],
config
:
Dict
[
str
,
Any
])
->
List
[
str
]:
def
parse_config
(
cmd
:
List
[
str
],
config
:
Dict
[
str
,
Any
]
,
out_folder
:
str
)
->
List
[
str
]:
"""
Convert a dictionary to a list of arguments.
Values that are not strings will be cast.
...
...
@@ -52,6 +56,7 @@ def parse_config(cmd: List[str], config: Dict[str, Any]) -> List[str]:
Booleans will be converted to a `--key` flag, where `key` is the
dictionary key.
"""
for
key
,
value
in
config
.
items
():
if
'
'
in
key
or
(
isinstance
(
value
,
str
)
and
'
'
in
value
):
raise
ValueError
(
'
Spaces are not allowed
'
,
key
,
value
)
...
...
@@ -65,27 +70,33 @@ def parse_config(cmd: List[str], config: Dict[str, Any]) -> List[str]:
else
:
if
value
in
[
'""'
,
"''"
]:
value
=
""
if
key
==
"
out-folder
"
:
value
=
out_folder
cmd
+=
[
"
--{}
"
.
format
(
key
),
str
(
value
)]
return
cmd
@pytest.mark.manual_run
@pytest.mark.parametrize
(
"
calibration_test
"
,
list
(
callab_test_dict
.
items
()))
def
test_xfel_calibrate
(
calibration_test
):
test_key
,
val_dict
=
calibration_test
cmd
=
[
"
xfel-calibrate
"
,
val_dict
[
"
det_type
"
],
val_dict
[
"
cal_type
"
]]
cal_conf
=
val_dict
[
"
config
"
]
cal_conf
[
"
report-to
"
]
=
test_key
report_name
=
test_key
out_folder
=
pathlib
.
Path
(
cal_conf
[
"
out-folder
"
].
format
(
OUT_FOLDER
,
cal_conf
[
"
karabo-id
"
],
test_key
))
cmd
=
parse_config
(
cmd
,
cal_conf
,
out_folder
)
test_cmd
=
[
"
xfel-calibrate
"
,
val_dict
[
"
det_type
"
],
val_dict
[
"
cal_type
"
]]
conf_dict
=
val_dict
[
"
config
"
]
out_folder
=
pathlib
.
Path
(
conf_dict
[
"
out-folder
"
])
report_name
=
conf_dict
[
"
report-to
"
]
expected_dict
=
val_dict
[
"
expected
"
]
reference_out_folder
=
pathlib
.
Path
(
expected_dict
[
"
reference_out_folder
"
])
parse_config
(
test_cmd
,
val_dict
[
"
config
"
])
test_cmd
+=
[
"
--slurm-name
"
,
test_key
]
reference_folder
=
pathlib
.
Path
(
val_dict
[
"
reference-folder
"
].
format
(
REFERENCE_FOLDER
,
cal_conf
[
"
karabo-id
"
],
test_key
))
cmd
+=
[
"
--slurm-name
"
,
test_key
]
f
=
io
.
StringIO
()
with
redirect_stdout
(
f
):
calibrate
.
run
(
test_
cmd
)
calibrate
.
run
(
cmd
)
out_str
=
f
.
getvalue
()
...
...
@@ -120,7 +131,7 @@ def test_xfel_calibrate(calibration_test):
# 3rd Check number of produced h5 files.
h5files
=
list
(
out_folder
.
glob
(
"
*.h5
"
))
expected_h5files
=
list
(
reference_
out_
folder
.
glob
(
"
*.h5
"
))
expected_h5files
=
list
(
reference_folder
.
glob
(
"
*.h5
"
))
assert
len
(
h5files
)
==
len
(
expected_h5files
),
f
"
{
test_key
}
failure, number of files are not as expected.
"
# noqa
print
(
f
"
{
test_key
}
'
s calibration h5files numbers are as expected.
"
)
...
...
@@ -128,10 +139,10 @@ def test_xfel_calibrate(calibration_test):
non_valid_files
=
[]
with
multiprocessing
.
Pool
()
as
pool
:
result
=
pool
.
starmap
(
validate_h5files
,
zip
(
h5files
,
len
(
h5files
)
*
[
reference_
out_
folder
]))
h5files
,
len
(
h5files
)
*
[
reference_folder
]))
for
i
in
result
:
all_files_validated
.
append
(
i
[
0
])
if
i
[
0
]:
if
not
i
[
0
]:
non_valid_files
.
append
(
i
[
1
])
assert
all
(
all_files_validated
),
f
"
{
test_key
}
failure, while validating
{
non_valid_files
}
"
# noqa
print
(
f
"
{
test_key
}
'
s calibration h5files are validated successfully.
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment