5 Check if the validation scripts can be executed using basf2 with "--dry-run".
9 import b2test_utils
as b2u
13 import subprocess
as sp
14 import multiprocessing
as mp
15 from concurrent.futures
import ProcessPoolExecutor
17 __authors__ = [
'Giacomo De Pietro']
22 A very simple argument parser.
24 parser = argparse.ArgumentParser(description=__doc__)
25 parser.add_argument(
'-j',
'--jobs',
28 help=
'Number of workers to be used by ProcessPoolExecutor.',
33 def dry_run(validation_file):
35 Check if the steering file at the given path can be run with the "--dry-run" option.
37 result = sp.call([
'basf2', validation_file,
'--dry-run',
'-i',
'input.root',
'-o',
'output.root',
'-l',
'ERROR'])
38 return (result, validation_file)
41 if __name__ ==
'__main__':
43 args = arg_parser().parse_args()
46 num_workers = max(int(mp.cpu_count() / (1. + os.getloadavg()[1])), 1)
48 num_workers = args.jobs
49 basf2.B2INFO(f
'The test will be executed using {num_workers} workers.')
51 validation_path = basf2.find_file(
'skim/validation/')
53 with b2u.clean_working_directory():
54 with ProcessPoolExecutor(max_workers=num_workers)
as pool:
55 for result, validation_file
in pool.map(dry_run, glob.glob(f
'{validation_path}*.py')):
57 failed_files.append(f
'skim/validation/{os.path.basename(validation_file)}')
58 if len(failed_files) > 0:
59 basf2.B2FATAL(
'The following validation scripts in the skim package failed, check them:\n'
60 +
' \n'.join(failed_files))