Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions tests/test_gzip_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,11 @@ def seek(self, *args):

class BaseTest(unittest.TestCase):

def __init__(self, methodName):
def setUp(self):
# Make a unique file name. The tests create the file themselves.
fileno, self.filename = tempfile.mkstemp()
os.close(fileno)
super().__init__(methodName)

def setUp(self):
if os.path.exists(self.filename):
os.unlink(self.filename)
os.unlink(self.filename)

def tearDown(self):
if os.path.exists(self.filename):
Expand Down
12 changes: 4 additions & 8 deletions tests/test_igzip.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import itertools
import os
import re
import shutil
import struct
import subprocess
import sys
Expand All @@ -39,11 +38,9 @@ def test_wrong_compresslevel_igzipfile():
error.match("Compression level should be between 0 and 3")


def test_repr():
tempdir = tempfile.mkdtemp()
with igzip.IGzipFile(os.path.join(tempdir, "test.gz"), "wb") as test:
def test_repr(tmp_path):
with igzip.IGzipFile(str(tmp_path / "test.gz"), "wb") as test:
assert "<igzip _io.BufferedWriter name='" in repr(test)
shutil.rmtree(tempdir)


def test_write_readonly_file():
Expand Down Expand Up @@ -602,9 +599,9 @@ def test_concatenated_gzip():
assert data == result


def test_seek():
def test_seek(tmp_path):
from io import SEEK_CUR, SEEK_END, SEEK_SET
with tempfile.NamedTemporaryFile("wb", delete=False) as tmpfile:
with open(tmp_path / "test.gz", "wb") as tmpfile:
tmpfile.write(gzip.compress(b"X" * 500 + b"A" + b"X" * 499))
tmpfile.write(gzip.compress(b"X" * 500 + b"B" + b"X" * 499))
tmpfile.write(gzip.compress(b"X" * 500 + b"C" + b"X" * 499))
Expand Down Expand Up @@ -637,7 +634,6 @@ def test_seek():
assert gzip_file.read(1) == b""
gzip_file.seek(-1500, SEEK_END)
assert gzip_file.read(1) == b"C"
os.remove(tmpfile.name)


def test_bgzip():
Expand Down
10 changes: 5 additions & 5 deletions tests/test_igzip_threaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ def test_threaded_read():


@pytest.mark.parametrize(["mode", "threads"],
itertools.product(["wb", "wt"], [1, 3, -1]))
def test_threaded_write(mode, threads):
with tempfile.NamedTemporaryFile("wb", delete=False) as tmp:
list(itertools.product(["wb", "wt"], [1, 3, -1])))
def test_threaded_write(tmp_path, mode, threads):
with open(tmp_path / "output.gz", "wb") as tmp:
# Use a small block size to simulate many writes.
with igzip_threaded.open(tmp, mode, threads=threads,
block_size=8*1024) as out_file:
Expand Down Expand Up @@ -87,12 +87,12 @@ def test_threaded_read_error():

@pytest.mark.timeout(5)
@pytest.mark.parametrize("threads", [1, 3])
def test_threaded_write_oversized_block_no_error(threads):
def test_threaded_write_oversized_block_no_error(tmp_path, threads):
# Random bytes are incompressible, and therefore are guaranteed to
# trigger a buffer overflow when larger than block size unless handled
# correctly.
data = os.urandom(1024 * 63) # not a multiple of block_size
with tempfile.NamedTemporaryFile(mode="wb", delete=False) as tmp:
with open(tmp_path / "output.gz", "wb") as tmp:
with igzip_threaded.open(
tmp, "wb", compresslevel=3, threads=threads,
block_size=8 * 1024
Expand Down
Loading