16 from basf2
import find_file
20 """Test to run all example scripts."""
22 @unittest.skipIf(not os.getenv('BELLE2_EXAMPLES_DATA_DIR'),
23 "$BELLE2_EXAMPLES_DATA_DIR not found.")
24 @unittest.skipIf(not os.getenv('BELLE2_VALIDATION_DATA_DIR'),
25 "$BELLE2_VALIDATION_DATA_DIR not found.")
28 Internal function to test a directory full of example scripts with an optional list of broken scripts to be skipped.
31 path_to_glob (str): the path to search for scripts
32 broken (list(str)): (optional) scripts that are known to be broken and can be skipped
36 all_egs = sorted(glob.glob(find_file(path_to_glob) +
"/*.py"))
38 filename = os.path.basename(eg)
39 if filename
not in broken:
40 with self.subTest(msg=filename):
41 result = subprocess.run([
'basf2',
'-n1', eg], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
42 if result.returncode != 0:
46 sys.stdout.buffer.write(result.stdout)
47 self.assertEqual(result.returncode, 0)
50 def scanTTree(filename):
51 from ROOT
import TFile
53 tfile = TFile(filename,
"READ")
54 print(f
"TFile: {filename}")
57 ttrees = [key.GetName()
for key
in tfile.GetListOfKeys()
if key.GetClassName() ==
"TTree"]
59 for ttree_name
in ttrees:
60 print(f
"TTree: {ttree_name}")
63 ttree = tfile.Get(ttree_name)
66 for branch
in ttree.GetListOfBranches():
67 branch_name = branch.GetName()
68 branch_value = getattr(ttree, branch.GetName())
69 if isinstance(branch_value, float):
70 print(f
"TBranch: {branch_name}, {branch_value:.4g}")
72 print(f
"TBranch: {branch_name}, {branch_value}")
def _test_examples_dir(self, path_to_glob, broken=None)