13 Test all the steering files used in the online_book lessons.
14 Proudly based on analysis/test/examples.py.
24 from typing
import Optional, List
27 from basf2
import find_file
28 from b2test_utils
import clean_working_directory, is_ci
31 def light_release() -> bool:
32 """ Returns true if we're in a light release """
35 except ModuleNotFoundError:
41 """ Test steering files """
46 broken: Optional[List[str]] =
None,
47 additional_arguments: Optional[List[str]] =
None,
48 expensive_tests: Optional[List[str]] =
None,
49 skip_in_light: Optional[List[str]] =
None,
52 Internal function to test a directory full of example scripts with an
53 optional list of broken scripts to be skipped.
56 path_to_glob (str): the path to a directory to search for python
57 scripts (must end in .py)
58 broken (list(str)): (optional) names of scripts that are known to
59 be broken and can be skipped
60 additional_arguments (list(str)): (optional) additional arguments
61 for basf2 to be passed when testing the scripts
62 expensive_tests (list(str)): (optional) names of scripts that take
63 longer and should e.g. not run on bamboo
64 skip_in_light (list(str)): (optional) names of scripts that have to
65 be excluded in light builds
67 if additional_arguments
is None:
68 additional_arguments = []
71 if expensive_tests
is None:
73 if skip_in_light
is None:
78 original_dir = find_file(path_to_glob)
79 working_dir = find_file(shutil.copytree(original_dir,
'working_dir'))
80 all_egs = sorted(glob.glob(working_dir +
"/*.py"))
82 filename = os.path.basename(eg)
83 if filename
in broken:
85 if is_ci()
and filename
in expensive_tests:
87 if light_release()
and filename
in skip_in_light:
89 with self.subTest(msg=filename):
90 result = subprocess.run(
91 [
"basf2",
"-n1", eg, *additional_arguments],
92 stdout=subprocess.PIPE,
93 stderr=subprocess.STDOUT,
96 if result.returncode != 0:
100 sys.stdout.buffer.write(result.stdout)
101 self.assertEqual(result.returncode, 0)
105 @unittest.skipIf(
not os.path.exists(
find_file(
"starterkit/2021/1111540100_eph3_BGx0_1.root",
"examples",
silent=True,
)
107 "Test data files not found.",
110 """Test lesson on basf2 basics."""
112 path_to_glob=
"online_book/basf2/steering_files",
113 additional_arguments=[
"1"],
115 "065_generate_mc.py",
119 "065_generate_mc.py",
120 "067_generate_mc.py",
127 if __name__ ==
"__main__":
128 with clean_working_directory():
130
def _test_examples_dir(self, str path_to_glob, Optional[List[str]] broken=None, Optional[List[str]] additional_arguments=None, Optional[List[str]] expensive_tests=None, Optional[List[str]] skip_in_light=None)
def test_lessons_1_to_5(self)