MCPcopy
hub / github.com/rocky/python-uncompyle6 / do_tests

Function do_tests

test/test_pythonlib.py:154–232  ·  view source on GitHub ↗
(src_dir, obj_patterns, target_dir, opts)

Source from the content-addressed store, hash-verified

152
153
154def do_tests(src_dir, obj_patterns, target_dir, opts):
155 def file_matches(files, root, basenames, patterns):
156 files.extend(
157 [
158 os.path.normpath(os.path.join(root, n))
159 for n in basenames
160 for pat in patterns
161 if fnmatch(n, pat)
162 ]
163 )
164
165 files = []
166 # Change directories so use relative rather than
167 # absolute paths. This speeds up things, and allows
168 # main() to write to a relative-path destination.
169 cwd = os.getcwd()
170 os.chdir(src_dir)
171
172 if opts["do_compile"]:
173 compiled_version = opts["compiled_version"]
174 if compiled_version and PYTHON_VERSION_TRIPLE != compiled_version:
175 print(
176 "Not compiling: desired Python version is %s but we are running %s"
177 % (compiled_version, PYTHON_VERSION_TRIPLE),
178 file=sys.stderr,
179 )
180 else:
181 for root, dirs, basenames in os.walk(src_dir):
182 file_matches(files, root, basenames, PY)
183 for sfile in files:
184 py_compile.compile(sfile)
185 pass
186 pass
187 files = []
188 pass
189 pass
190
191 for root, dirs, basenames in os.walk("."):
192 # Turn root into a relative path
193 dirname = root[2:] # 2 = len('.') + 1
194 file_matches(files, dirname, basenames, obj_patterns)
195
196 if not files:
197 print(
198 "Didn't come up with any files to test! Try with --compile?",
199 file=sys.stderr,
200 )
201 exit(1)
202
203 os.chdir(cwd)
204 files.sort()
205
206 if opts["start_with"]:
207 try:
208 start_with = files.index(opts["start_with"])
209 files = files[start_with:]
210 print(">>> starting with file", files[0])
211 except ValueError:

Callers 1

test_pythonlib.pyFile · 0.70

Calls 3

mainFunction · 0.90
file_matchesFunction · 0.85
sortMethod · 0.80

Tested by

no test coverage detected