Belle II Software  light-2205-abys
SteeringFileTest Class Reference
Inheritance diagram for SteeringFileTest:
Collaboration diagram for SteeringFileTest:

Public Member Functions

def test_lessons_1_to_5 (self)
 

Private Member Functions

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, Optional[List[str]] skip=None, Optional[Dict[str, int]] n_events=None)
 

Detailed Description

Test steering files

Definition at line 102 of file steering_files.py.

Member Function Documentation

◆ _test_examples_dir()

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,
Optional[List[str]]   skip = None,
Optional[Dict[str, int]]   n_events = None 
)
private
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 a directory to search for python
        scripts (must end in .py)
    broken (list(str)): (optional) names of scripts that are known to
        be broken and can be skipped
    additional_arguments (list(str)): (optional) additional arguments
        for basf2 to be passed when testing the scripts
    expensive_tests (list(str)): (optional) names of scripts that take
        longer and should e.g. not run on bamboo
    skip_in_light (list(str)): (optional) names of scripts that have to
        be excluded in light builds
    skip (list(str)): (optional) names of scripts to always skip
    n_events (dict(str, int)): mapping of name of script to number of
        required events for it to run (`-n` argument). If a filename
        isn't listed, we assume 1

Definition at line 105 of file steering_files.py.

114  ):
115  """
116  Internal function to test a directory full of example scripts with an
117  optional list of broken scripts to be skipped.
118 
119  Parameters:
120  path_to_glob (str): the path to a directory to search for python
121  scripts (must end in .py)
122  broken (list(str)): (optional) names of scripts that are known to
123  be broken and can be skipped
124  additional_arguments (list(str)): (optional) additional arguments
125  for basf2 to be passed when testing the scripts
126  expensive_tests (list(str)): (optional) names of scripts that take
127  longer and should e.g. not run on bamboo
128  skip_in_light (list(str)): (optional) names of scripts that have to
129  be excluded in light builds
130  skip (list(str)): (optional) names of scripts to always skip
131  n_events (dict(str, int)): mapping of name of script to number of
132  required events for it to run (`-n` argument). If a filename
133  isn't listed, we assume 1
134  """
135  if additional_arguments is None:
136  additional_arguments = []
137  if broken is None:
138  broken = []
139  if expensive_tests is None:
140  expensive_tests = []
141  if skip_in_light is None:
142  skip_in_light = []
143  if skip is None:
144  skip = []
145  if n_events is None:
146  n_events = {}
147  # we have to copy all the steering files (plus other stuffs, like decfiles) we want to test
148  # into a new directory and then cd it as working directory when subprocess.run is executed,
149  # otherwise the test will fail horribly if find_file is called by one of the tested steerings.
150  original_dir = find_file(path_to_glob)
151  print(f"Our user id: {os.getuid()}")
152  _permission_report(original_dir)
153  working_dir = find_file(shutil.copytree(original_dir, "working_dir"))
154  _permission_report(working_dir)
155  # Add write permissions for user to this directory
156  os.chmod(working_dir, 0o744)
157  _permission_report(working_dir)
158  all_egs = sorted(glob.glob(working_dir + "/*.py"))
159  for eg in all_egs:
160  filename = os.path.basename(eg)
161  if filename in broken:
162  continue
163  if is_ci() and filename in expensive_tests:
164  continue
165  if light_release() and filename in skip_in_light:
166  continue
167  if filename in skip:
168  continue
169  with self.subTest(msg=filename):
170  # pylint: disable=subprocess-run-check
171  result = subprocess.run(
172  [
173  "basf2",
174  "-n",
175  str(n_events.get(filename, 1)),
176  eg,
177  *additional_arguments,
178  ],
179  stdout=subprocess.PIPE,
180  stderr=subprocess.STDOUT,
181  cwd=working_dir,
182  )
183  if result.returncode != 0:
184  # failure running example so let's print the output
185  # on stderr so it's not split from output of unittest
186  # done like this since we don't want to decode/encode utf8
187  sys.stdout.buffer.write(result.stdout)
188  self.assertEqual(result.returncode, 0)
189 

◆ test_lessons_1_to_5()

def test_lessons_1_to_5 (   self)
Test lesson on basf2 basics.

Definition at line 196 of file steering_files.py.


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