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

Public Member Functions

def test_lessons_1_to_5 (self)
 

Protected 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 101 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 
)
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 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 in GitLab pipeline
    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 104 of file steering_files.py.

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

◆ test_lessons_1_to_5()

def test_lessons_1_to_5 (   self)
Test lesson on basf2 basics.

Definition at line 201 of file steering_files.py.

201 def test_lessons_1_to_5(self):
202 """Test lesson on basf2 basics."""
203 self._test_examples_dir(
204 path_to_glob="online_book/basf2/steering_files",
205 additional_arguments=["1"],
206 expensive_tests=["065_generate_mc.py", "067_generate_mc.py"],
207 skip_in_light=[
208 "065_generate_mc.py",
209 "067_generate_mc.py",
210 "085_module.py",
211 "087_module.py",
212 ],
213 n_events={
214 # See https://questions.belle2.org/question/11344/
215 "091_cs.py": 3000,
216 },
217 )
218
219

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