13 Check if the validation scripts can be executed using basf2 with "--dry-run".
17 import b2test_utils
as b2u
21 import subprocess
as sp
22 import multiprocessing
as mp
23 from concurrent.futures
import ProcessPoolExecutor
28 A very simple argument parser.
30 parser = argparse.ArgumentParser(description=__doc__)
31 parser.add_argument(
'-j',
'--jobs',
34 help=
'Number of workers to be used by ProcessPoolExecutor.',
39 def dry_run(validation_file):
41 Check if the steering file at the given path can be run with the "--dry-run" option.
43 result = sp.call([
'basf2', validation_file,
'--dry-run',
'-i',
'input.root',
'-o',
'output.root',
'-l',
'ERROR'])
44 return (result, validation_file)
47 if __name__ ==
'__main__':
49 b2u.skip_test_if_light()
51 args = arg_parser().parse_args()
54 num_workers = max(int(mp.cpu_count() / (1. + os.getloadavg()[1])), 1)
56 num_workers = args.jobs
57 basf2.B2INFO(f
'The test will be executed using {num_workers} workers.')
59 validation_path = basf2.find_file(
'skim/validation/')
61 with b2u.clean_working_directory():
62 with ProcessPoolExecutor(max_workers=num_workers)
as pool:
63 for result, validation_file
in pool.map(dry_run, glob.glob(f
'{validation_path}*.py')):
65 failed_files.append(f
'skim/validation/{os.path.basename(validation_file)}')
66 if len(failed_files) > 0:
67 basf2.B2FATAL(
'The following validation scripts in the skim package failed, check them:\n'
68 +
' \n'.join(failed_files))