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

Method test_write_pyfile

Lib/test/test_zipfile/test_core.py:1455–1483  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1453 unlink(filename)
1454
1455 def test_write_pyfile(self):
1456 self.requiresWriteAccess(os.path.dirname(__file__))
1457 with TemporaryFile() as t, zipfile.PyZipFile(t, "w") as zipfp:
1458 fn = __file__
1459 if fn.endswith('.pyc'):
1460 path_split = fn.split(os.sep)
1461 if os.altsep is not None:
1462 path_split.extend(fn.split(os.altsep))
1463 if '__pycache__' in path_split:
1464 fn = importlib.util.source_from_cache(fn)
1465 else:
1466 fn = fn[:-1]
1467
1468 zipfp.writepy(fn)
1469
1470 bn = os.path.basename(fn)
1471 self.assertNotIn(bn, zipfp.namelist())
1472 self.assertCompiledIn(bn, zipfp.namelist())
1473
1474 with TemporaryFile() as t, zipfile.PyZipFile(t, "w") as zipfp:
1475 fn = __file__
1476 if fn.endswith('.pyc'):
1477 fn = fn[:-1]
1478
1479 zipfp.writepy(fn, "testpackage")
1480
1481 bn = "%s/%s" % ("testpackage", os.path.basename(fn))
1482 self.assertNotIn(bn, zipfp.namelist())
1483 self.assertCompiledIn(bn, zipfp.namelist())
1484
1485 def test_write_python_package(self):
1486 import email

Callers

nothing calls this directly

Calls 11

requiresWriteAccessMethod · 0.95
assertCompiledInMethod · 0.95
TemporaryFileFunction · 0.90
writepyMethod · 0.80
assertNotInMethod · 0.80
dirnameMethod · 0.45
endswithMethod · 0.45
splitMethod · 0.45
extendMethod · 0.45
basenameMethod · 0.45
namelistMethod · 0.45

Tested by

no test coverage detected