Belle II Software prerelease-10-00-00a
ExamplesTest Class Reference
Inheritance diagram for ExamplesTest:
Collaboration diagram for ExamplesTest:

Protected Member Functions

 _test_examples_dir (self, path_to_glob, broken=None, filepattern="", nevents=10, cleanup=False)
 

Detailed Description

Test to run all example scripts.

Definition at line 21 of file b2test_utils_analysis.py.

Member Function Documentation

◆ _test_examples_dir()

_test_examples_dir ( self,
path_to_glob,
broken = None,
filepattern = "",
nevents = 10,
cleanup = False )
protected
Internal function to test a directory full of example scripts with an optional list of broken scripts to be skipped.

Parameters:
    path_to_glob (str): the path to search for scripts
    broken (list(str)): (optional) scripts that are known to be broken and can be skipped

Definition at line 28 of file b2test_utils_analysis.py.

28 def _test_examples_dir(self, path_to_glob, broken=None, filepattern="", nevents=10, cleanup=False):
29 """
30 Internal function to test a directory full of example scripts with an optional list of broken scripts to be skipped.
31
32 Parameters:
33 path_to_glob (str): the path to search for scripts
34 broken (list(str)): (optional) scripts that are known to be broken and can be skipped
35 """
36 if broken is None:
37 broken = []
38 configure_logging_for_tests()
39 all_egs = sorted(glob.glob(find_file(path_to_glob) + f"/{filepattern}*.py"))
40 for eg in all_egs:
41 with (clean_working_directory() if cleanup else nullcontext()):
42 filename = os.path.basename(eg)
43 if filename not in broken:
44 with self.subTest(msg=filename):
45 outputfilename = filename.replace('.py', '.root')
46 result = subprocess.run(['basf2', '-n', f'{nevents}', eg, '-o',
47 outputfilename], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
48 if result.returncode != 0:
49 # failure running example so let's print the output
50 # on stderr so it's not split from output of unittest
51 # done like this since we don't want to decode/encode utf8
52 sys.stdout.buffer.write(result.stdout)
53 self.assertEqual(result.returncode, 0)
54
55 if os.path.exists(outputfilename) and isNtuple(outputfilename):
56 scanTTree(outputfilename)
57
58

The documentation for this class was generated from the following file: