Belle II Software development
ExamplesTest Class Reference
Inheritance diagram for ExamplesTest:

Protected Member Functions

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

Detailed Description

Test to run all example scripts.

Definition at line 20 of file b2test_utils_analysis.py.

Member Function Documentation

◆ _test_examples_dir()

def _test_examples_dir (   self,
  path_to_glob,
  broken = None,
  filepattern = "",
  nevents = 10 
)
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 27 of file b2test_utils_analysis.py.

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

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