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
147
148
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
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
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
184
185
186 sys.stdout.buffer.write(result.stdout)
187 self.assertEqual(result.returncode, 0)
188