5 Script that tests the various `caf.backends` and some options that are available.
6 This cannot be run as a normal unit test because not all backends are available on the
7 DESY cloud servers. So the only think we can do is test them individually on machines that
8 do have the backends installed.
12 from basf2
import find_file
16 ROOT.PyConfig.IgnoreCommandLineOptions =
True
18 from pathlib
import Path
20 from caf.backends
import Job, monitor_jobs, Local
23 test_script = Path(find_file(
"calibration/examples/job_submission/test_script.sh"))
24 test_basf2_script = Path(find_file(
"calibration/examples/job_submission/basic_basf2.py"))
25 test_data = Path(find_file(
"calibration/examples/job_submission/test_data"))
28 def test_path_exists(path):
30 raise FileNotFoundError(f
"The expected file {test_script.as_posix()} does not exist.")
33 def create_jobs(args):
34 test_path_exists(test_data)
35 test_path_exists(test_script)
36 test_path_exists(test_basf2_script)
37 output_dir = Path(
"test_backends_jobs")
38 j1 = Job(name=
"test_job1")
40 j1.working_dir = Path(output_dir, j1.name,
"working_dir").absolute()
42 j1.output_dir = Path(output_dir, j1.name,
"output_dir").absolute()
44 j1.cmd = [
"bash", test_script.name]
45 j1.args = [
"first_arg_example",
"\"Do quotes work?\""]
49 j1.input_sandbox_files.append(test_script.absolute())
51 j2 = Job(name=
"test_job2")
53 j2.working_dir = Path(output_dir, j2.name).absolute()
55 j2.output_dir = Path(output_dir, j2.name).absolute()
57 j2.cmd = [
"basf2", test_basf2_script.name]
59 j2.append_current_basf2_setup_cmds()
60 j2.input_sandbox_files.append(test_basf2_script.absolute())
61 j2.input_files = sorted(p.as_posix()
for p
in Path(test_data).glob(
"*.root"))
62 if args.files_per_subjob:
63 j2.max_files_per_subjob = args.files_per_subjob
64 elif args.max_subjobs:
65 j2.max_subjobs = args.max_subjobs
70 """Setup the argparser for this script"""
72 parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
75 for subparser
in subparsers:
83 parser = get_argparser()
84 args = parser.parse_args()
85 basf2.set_log_level(basf2.LogLevel.names[args.log_level])
87 basf2.set_log_level(basf2.LogLevel.DEBUG)
88 basf2.set_debug_level(args.debug_level)
89 jobs = create_jobs(args)
90 backend = args.func(args)
92 monitor_jobs(args, jobs)
93 if isinstance(backend, Local):
97 if __name__ ==
"__main__":