Skip to content

Commit

Permalink
pythongh-127146: Mark test_bz2 tests with requires_subprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
hoodmane committed Dec 3, 2024
1 parent 8c3fd1f commit cd1fe93
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Lib/test/test_bz2.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,15 @@ def testClosedIteratorDeadlock(self):
# This call will deadlock if the above call failed to release the lock.
self.assertRaises(ValueError, bz2f.readlines)

@support.requires_subprocess()
def testWrite(self):
with BZ2File(self.filename, "w") as bz2f:
self.assertRaises(TypeError, bz2f.write)
bz2f.write(self.TEXT)
with open(self.filename, 'rb') as f:
self.assertEqual(ext_decompress(f.read()), self.TEXT)

@support.requires_subprocess()
def testWriteChunks10(self):
with BZ2File(self.filename, "w") as bz2f:
n = 0
Expand All @@ -270,6 +272,7 @@ def testWriteNonDefaultCompressLevel(self):
with open(self.filename, "rb") as f:
self.assertEqual(f.read(), expected)

@support.requires_subprocess()
def testWriteLines(self):
with BZ2File(self.filename, "w") as bz2f:
self.assertRaises(TypeError, bz2f.writelines)
Expand All @@ -288,6 +291,7 @@ def testWriteMethodsOnReadOnlyFile(self):
self.assertRaises(OSError, bz2f.write, b"a")
self.assertRaises(OSError, bz2f.writelines, [b"a"])

@support.requires_subprocess()
def testAppend(self):
with BZ2File(self.filename, "w") as bz2f:
self.assertRaises(TypeError, bz2f.write)
Expand Down Expand Up @@ -771,6 +775,7 @@ def testPeekBytesIO(self):
self.assertTrue(self.TEXT.startswith(pdata))
self.assertEqual(bz2f.read(), self.TEXT)

@support.requires_subprocess()
def testWriteBytesIO(self):
with BytesIO() as bio:
with BZ2File(bio, "w") as bz2f:
Expand Down Expand Up @@ -819,6 +824,7 @@ def test_issue44439(self):


class BZ2CompressorTest(BaseTest):
@support.requires_subprocess()
def testCompress(self):
bz2c = BZ2Compressor()
self.assertRaises(TypeError, bz2c.compress)
Expand All @@ -832,6 +838,7 @@ def testCompressEmptyString(self):
data += bz2c.flush()
self.assertEqual(data, self.EMPTY_DATA)

@support.requires_subprocess()
def testCompressChunks10(self):
bz2c = BZ2Compressor()
n = 0
Expand Down Expand Up @@ -1037,6 +1044,7 @@ def test_uninitialized_BZ2Decompressor_crash(self):


class CompressDecompressTest(BaseTest):
@support.requires_subprocess()
def testCompress(self):
data = bz2.compress(self.TEXT)
self.assertEqual(ext_decompress(data), self.TEXT)
Expand Down Expand Up @@ -1082,6 +1090,7 @@ class OpenTest(BaseTest):
def open(self, *args, **kwargs):
return bz2.open(*args, **kwargs)

@support.requires_subprocess()
def test_binary_modes(self):
for mode in ("wb", "xb"):
if mode == "xb":
Expand All @@ -1099,6 +1108,7 @@ def test_binary_modes(self):
file_data = ext_decompress(f.read())
self.assertEqual(file_data, self.TEXT * 2)

@support.requires_subprocess()
def test_implicit_binary_modes(self):
# Test implicit binary modes (no "b" or "t" in mode string).
for mode in ("w", "x"):
Expand All @@ -1117,6 +1127,7 @@ def test_implicit_binary_modes(self):
file_data = ext_decompress(f.read())
self.assertEqual(file_data, self.TEXT * 2)

@support.requires_subprocess()
def test_text_modes(self):
text = self.TEXT.decode("ascii")
text_native_eol = text.replace("\n", os.linesep)
Expand Down Expand Up @@ -1168,6 +1179,7 @@ def test_bad_params(self):
self.assertRaises(ValueError,
self.open, self.filename, "rb", newline="\n")

@support.requires_subprocess()
def test_encoding(self):
# Test non-default encoding.
text = self.TEXT.decode("ascii")
Expand Down

0 comments on commit cd1fe93

Please sign in to comment.