MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_create_pax_header

Method test_create_pax_header

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

Source from the content-addressed store, hash-verified

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