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

Method test_detect_stream_bz2

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

Source from the content-addressed store, hash-verified

1045
1046class Bz2DetectReadTest(Bz2Test, DetectReadTest):
1047 def test_detect_stream_bz2(self):
1048 # Originally, tarfile's stream detection looked for the string
1049 # "BZh91" at the start of the file. This is incorrect because
1050 # the '9' represents the blocksize (900,000 bytes). If the file was
1051 # compressed using another blocksize autodetection fails.
1052 with open(tarname, "rb") as fobj:
1053 data = fobj.read()
1054
1055 # Compress with blocksize 100,000 bytes, the file starts with "BZh11".
1056 with bz2.BZ2File(tmpname, "wb", compresslevel=1) as fobj:
1057 fobj.write(data)
1058
1059 self._testfunc_file(tmpname, "r|*")
1060
1061class LzmaDetectReadTest(LzmaTest, DetectReadTest):
1062 pass

Callers

nothing calls this directly

Calls 4

_testfunc_fileMethod · 0.80
openFunction · 0.50
readMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected