MCPcopy Create free account
hub / github.com/python/cpython / test_for_archive

Method test_for_archive

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

Source from the content-addressed store, hash-verified

2358 self.assertEqual(repr(zi), "<ZipInfo filename='empty' file_size=0>")
2359
2360 def test_for_archive(self):
2361 base_filename = TESTFN2.rstrip('/')
2362
2363 with zipfile.ZipFile(TESTFN, mode="w", compresslevel=1,
2364 compression=zipfile.ZIP_STORED) as zf:
2365 # no trailing forward slash
2366 zi = zipfile.ZipInfo(base_filename)._for_archive(zf)
2367 self.assertEqual(zi.compress_level, 1)
2368 self.assertEqual(zi.compress_type, zipfile.ZIP_STORED)
2369 # ?rw- --- ---
2370 filemode = stat.S_IRUSR | stat.S_IWUSR
2371 # filemode is stored as the highest 16 bits of external_attr
2372 self.assertEqual(zi.external_attr >> 16, filemode)
2373 self.assertEqual(zi.external_attr & 0xFF, 0) # no MS-DOS flag
2374
2375 with zipfile.ZipFile(TESTFN, mode="w", compresslevel=1,
2376 compression=zipfile.ZIP_STORED) as zf:
2377 # with a trailing slash
2378 zi = zipfile.ZipInfo(f'{base_filename}/')._for_archive(zf)
2379 self.assertEqual(zi.compress_level, 1)
2380 self.assertEqual(zi.compress_type, zipfile.ZIP_STORED)
2381 # d rwx rwx r-x
2382 filemode = stat.S_IFDIR
2383 filemode |= stat.S_IRWXU | stat.S_IRWXG
2384 filemode |= stat.S_IROTH | stat.S_IXOTH
2385 self.assertEqual(zi.external_attr >> 16, filemode)
2386 self.assertEqual(zi.external_attr & 0xFF, 0x10) # MS-DOS flag
2387
2388 def test_create_empty_zipinfo_default_attributes(self):
2389 """Ensure all required attributes are set."""

Callers

nothing calls this directly

Calls 3

_for_archiveMethod · 0.80
rstripMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected