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

Method test_create_pax_header

Lib/test/test_tarfile.py:2298–2351  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2296 tar.close()
2297
2298 def test_create_pax_header(self):
2299 # The ustar header should contain values that can be
2300 # represented reasonably, even if a better (e.g. higher
2301 # precision) version is set in the pax header.
2302 # Issue #45863
2303
2304 # values that should be kept
2305 t = tarfile.TarInfo()
2306 t.name = "foo"
2307 t.mtime = 1000.1
2308 t.size = 100
2309 t.uid = 123
2310 t.gid = 124
2311 info = t.get_info()
2312 header = t.create_pax_header(info, encoding="iso8859-1")
2313 self.assertEqual(info['name'], "foo")
2314 # mtime should be rounded to nearest second
2315 self.assertIsInstance(info['mtime'], int)
2316 self.assertEqual(info['mtime'], 1000)
2317 self.assertEqual(info['size'], 100)
2318 self.assertEqual(info['uid'], 123)
2319 self.assertEqual(info['gid'], 124)
2320 self.assertEqual(header,
2321 b'././@PaxHeader' + bytes(86) \
2322 + b'0000000\x000000000\x000000000\x0000000000020\x0000000000000\x00010205\x00 x' \
2323 + bytes(100) + b'ustar\x0000'+ bytes(247) \
2324 + b'16 mtime=1000.1\n' + bytes(496) + b'foo' + bytes(97) \
2325 + b'0000644\x000000173\x000000174\x0000000000144\x0000000001750\x00006516\x00 0' \
2326 + bytes(100) + b'ustar\x0000' + bytes(247))
2327
2328 # values that should be changed
2329 t = tarfile.TarInfo()
2330 t.name = "foo\u3374" # can't be represented in ascii
2331 t.mtime = 10**10 # too big
2332 t.size = 10**10 # too big
2333 t.uid = 8**8 # too big
2334 t.gid = 8**8+1 # too big
2335 info = t.get_info()
2336 header = t.create_pax_header(info, encoding="iso8859-1")
2337 # name is kept as-is in info but should be added to pax header
2338 self.assertEqual(info['name'], "foo\u3374")
2339 self.assertEqual(info['mtime'], 0)
2340 self.assertEqual(info['size'], 0)
2341 self.assertEqual(info['uid'], 0)
2342 self.assertEqual(info['gid'], 0)
2343 self.assertEqual(header,
2344 b'././@PaxHeader' + bytes(86) \
2345 + b'0000000\x000000000\x000000000\x0000000000130\x0000000000000\x00010207\x00 x' \
2346 + bytes(100) + b'ustar\x0000' + bytes(247) \
2347 + b'15 path=foo\xe3\x8d\xb4\n16 uid=16777216\n' \
2348 + b'16 gid=16777217\n20 size=10000000000\n' \
2349 + b'21 mtime=10000000000\n'+ bytes(424) + b'foo?' + bytes(96) \
2350 + b'0000644\x000000000\x000000000\x0000000000000\x0000000000000\x00006540\x00 0' \
2351 + bytes(100) + b'ustar\x0000' + bytes(247))
2352
2353
2354class UnicodeTest:

Callers

nothing calls this directly

Calls 4

get_infoMethod · 0.95
create_pax_headerMethod · 0.95
assertIsInstanceMethod · 0.80
assertEqualMethod · 0.45

Tested by

no test coverage detected