10 Simple launcher for decfiles/tests/test_changed_decfiles.py_noexec. This tests whether new decay files work.
19 from pathlib
import Path
20 from tempfile
import NamedTemporaryFile
23 def add_hint(errorstring: str):
25 hint =
"\nDon't forget to add custom (i.e. not yet discovered or measured) particles to " \
26 "decfiles/tests/test_changed_decfiles.pdl, otherwise the test will not pass." \
27 " Already discovered particles should go in framework/particledb/data/evt.pdl instead."
29 if 'Unknown particle name' in errorstring:
30 return errorstring + hint
35 if __name__ ==
'__main__':
42 if not os.environ.get(
'BELLE2_LOCAL_DIR'):
45 topdir = Path(os.environ[
'BELLE2_LOCAL_DIR'])
46 assert topdir.is_dir()
49 merge_base = repo.merge_base(
'origin/main', repo.head)
50 diff_to_main = repo.head.commit.diff(merge_base)
52 added_or_modified_decfiles = [topdir / new_file.a_path
for new_file
in diff_to_main
53 if (Path(new_file.a_path).suffix ==
'.dec')
54 and (Path(
'decfiles/dec')
in Path(new_file.a_path).parents)]
56 steering_file = basf2.find_file(
'decfiles/tests/test_changed_decfiles.py_noexec')
57 custom_evtpdl = basf2.find_file(
"decfiles/tests/test_changed_decfiles.pdl")
58 default_evtpdl = basf2.find_file(
'data/framework/particledb/evt.pdl')
61 if added_or_modified_decfiles:
62 changed_file_string =
'\n'.join(str(p)
for p
in added_or_modified_decfiles)
63 print(f
"Changed decayfiles: \n{changed_file_string}")
65 with NamedTemporaryFile(mode=
'w', suffix=
'.pdl')
as tempfile:
67 for fname
in [custom_evtpdl, default_evtpdl]:
68 with open(fname,
'r')
as infile:
69 tempfile.write(infile.read())
71 for decfile
in added_or_modified_decfiles:
73 run_results.append(subprocess.run([
'basf2', steering_file, str(decfile), tempfile.name],
76 files_and_errors = [f
'Decfile {added_or_modified_decfiles[i]} failed with output \n'
77 f
'{ret.stdout.decode()} \n and error \n {add_hint(ret.stderr.decode())}'
78 for i, ret
in enumerate(run_results)
if ret.returncode != 0]
80 if len(files_and_errors):
81 raise RuntimeError(
"At least one added decfile has failed.\n"
82 +
'\n'.join(files_and_errors))
def configure_logging_for_tests(user_replacements=None)
def clean_working_directory()
def skip_test(reason, py_case=None)