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

Method _test_partial_input

Lib/test/test_tarfile.py:3149–3167  ·  view source on GitHub ↗
(self, mode)

Source from the content-addressed store, hash-verified

3147 # on an empty or partial bzipped file.
3148
3149 def _test_partial_input(self, mode):
3150 class MyBytesIO(io.BytesIO):
3151 hit_eof = False
3152 def read(self, n):
3153 if self.hit_eof:
3154 raise AssertionError("infinite loop detected in "
3155 "tarfile.open()")
3156 self.hit_eof = self.tell() == len(self.getvalue())
3157 return super(MyBytesIO, self).read(n)
3158 def seek(self, *args):
3159 self.hit_eof = False
3160 return super(MyBytesIO, self).seek(*args)
3161
3162 data = bz2.compress(tarfile.TarInfo("foo").tobuf())
3163 for x in range(len(data) + 1):
3164 try:
3165 tarfile.open(fileobj=MyBytesIO(data[:x]), mode=mode)
3166 except tarfile.ReadError:
3167 pass # we have no interest in ReadErrors
3168
3169 def test_partial_input(self):
3170 self._test_partial_input("r")

Callers 2

test_partial_inputMethod · 0.95

Calls 4

tobufMethod · 0.80
MyBytesIOClass · 0.70
compressMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected