MCPcopy Index your code
hub / github.com/python/cpython / _test_ddir_only

Method _test_ddir_only

Lib/test/test_compileall.py:303–330  ·  view source on GitHub ↗

Recursive compile_dir ddir must contain package paths; bpo39769.

(self, *, ddir, parallel=True)

Source from the content-addressed store, hash-verified

301 self.assertTrue(os.path.isfile(pyc_filename))
302
303 def _test_ddir_only(self, *, ddir, parallel=True):
304 """Recursive compile_dir ddir must contain package paths; bpo39769."""
305 fullpath = ["test", "foo"]
306 path = self.directory
307 mods = []
308 for subdir in fullpath:
309 path = os.path.join(path, subdir)
310 os.mkdir(path)
311 script_helper.make_script(path, "__init__", "")
312 mods.append(script_helper.make_script(path, "mod",
313 "def fn(): 1/0\nfn()\n"))
314
315 if parallel:
316 self.addCleanup(multiprocessing_cleanup_tests)
317 compileall.compile_dir(
318 self.directory, quiet=True, ddir=ddir,
319 workers=2 if parallel else 1)
320
321 self.assertTrue(mods)
322 for mod in mods:
323 self.assertStartsWith(mod, self.directory)
324 modcode = importlib.util.cache_from_source(mod)
325 modpath = mod[len(self.directory+os.sep):]
326 _, _, err = script_helper.assert_python_failure(modcode)
327 expected_in = os.path.join(ddir, modpath)
328 mod_code_obj = test.test_importlib.util.get_code_from_pyc(modcode)
329 self.assertEqual(mod_code_obj.co_filename, expected_in)
330 self.assertIn(f'"{expected_in}"', os.fsdecode(err))
331
332 def test_ddir_only_one_worker(self):
333 """Recursive compile_dir ddir= contains package paths; bpo39769."""

Calls 11

addCleanupMethod · 0.80
compile_dirMethod · 0.80
assertTrueMethod · 0.80
assertStartsWithMethod · 0.80
assert_python_failureMethod · 0.80
assertInMethod · 0.80
joinMethod · 0.45
mkdirMethod · 0.45
make_scriptMethod · 0.45
appendMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected