Skip to content

Commit 8ffa5c3

Browse files
committed
Fix lint errors
1 parent 98e6393 commit 8ffa5c3

File tree

1 file changed

+67
-48
lines changed

1 file changed

+67
-48
lines changed

tests/test_gzip_compliance.py

Lines changed: 67 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232

3333
from isal import igzip
3434

35-
import pytest
36-
3735
data1 = b""" int length=DEFAULTALLOC, err = Z_OK;
3836
PyObject *RetVal;
3937
int flushmode = Z_FINISH;
@@ -46,7 +44,6 @@
4644
/* See http://www.winimage.com/zLibDll for Windows */
4745
"""
4846

49-
5047
TEMPDIR = os.path.abspath(tempfile.mkdtemp(suffix='-gzdir'))
5148

5249

@@ -76,10 +73,10 @@ def tearDown(self):
7673
class TestGzip(BaseTest):
7774
def write_and_read_back(self, data, mode='b'):
7875
b_data = bytes(data)
79-
with igzip.IGzipFile(self.filename, 'w'+mode) as f:
80-
l = f.write(data)
81-
self.assertEqual(l, len(b_data))
82-
with igzip.IGzipFile(self.filename, 'r'+mode) as f:
76+
with igzip.IGzipFile(self.filename, 'w' + mode) as f:
77+
length = f.write(data)
78+
self.assertEqual(length, len(b_data))
79+
with igzip.IGzipFile(self.filename, 'r' + mode) as f:
8380
self.assertEqual(f.read(), b_data)
8481

8582
def test_write(self):
@@ -114,7 +111,7 @@ def test_write_read_with_pathlike_file(self):
114111
def test_write_memoryview(self):
115112
self.write_and_read_back(memoryview(data1 * 50))
116113
m = memoryview(bytes(range(256)))
117-
data = m.cast('B', shape=[8,8,4])
114+
data = m.cast('B', shape=[8, 8, 4])
118115
self.write_and_read_back(data)
119116

120117
def test_write_bytearray(self):
@@ -141,7 +138,7 @@ def test_read(self):
141138
# Try reading.
142139
with igzip.IGzipFile(self.filename, 'r') as f:
143140
d = f.read()
144-
self.assertEqual(d, data1*50)
141+
self.assertEqual(d, data1 * 50)
145142

146143
def test_read1(self):
147144
self.test_write()
@@ -202,7 +199,7 @@ def test_append(self):
202199

203200
with igzip.IGzipFile(self.filename, 'rb') as f:
204201
d = f.read()
205-
self.assertEqual(d, (data1*50) + (data2*15))
202+
self.assertEqual(d, (data1 * 50) + (data2 * 15))
206203

207204
def test_many_append(self):
208205
# Bug #1074261 was triggered when reading a file that contained
@@ -211,7 +208,7 @@ def test_many_append(self):
211208
with igzip.IGzipFile(self.filename, 'wb') as f:
212209
f.write(b'a')
213210
for i in range(0, 200):
214-
with igzip.IGzipFile(self.filename, "ab") as f: # append
211+
with igzip.IGzipFile(self.filename, "ab") as f: # append
215212
f.write(b'a')
216213

217214
# Try reading the file
@@ -220,8 +217,9 @@ def test_many_append(self):
220217
while 1:
221218
ztxt = zgfile.read(8192)
222219
contents += ztxt
223-
if not ztxt: break
224-
self.assertEqual(contents, b'a'*201)
220+
if not ztxt:
221+
break
222+
self.assertEqual(contents, b'a' * 201)
225223

226224
def test_exclusive_write(self):
227225
with igzip.IGzipFile(self.filename, 'xb') as f:
@@ -250,7 +248,8 @@ def test_readline(self):
250248
line_length = 0
251249
while 1:
252250
L = f.readline(line_length)
253-
if not L and line_length != 0: break
251+
if not L and line_length != 0:
252+
break
254253
self.assertTrue(len(L) <= line_length)
255254
line_length = (line_length + 1) % 50
256255

@@ -264,7 +263,8 @@ def test_readlines(self):
264263
with igzip.IGzipFile(self.filename, 'rb') as f:
265264
while 1:
266265
L = f.readlines(150)
267-
if L == []: break
266+
if L == []:
267+
break
268268

269269
def test_seek_read(self):
270270
self.test_write()
@@ -274,10 +274,11 @@ def test_seek_read(self):
274274
while 1:
275275
oldpos = f.tell()
276276
line1 = f.readline()
277-
if not line1: break
277+
if not line1:
278+
break
278279
newpos = f.tell()
279280
f.seek(oldpos) # negative seek
280-
if len(line1)>10:
281+
if len(line1) > 10:
281282
amount = 10
282283
else:
283284
amount = len(line1)
@@ -324,7 +325,7 @@ def test_paddedfile_getattr(self):
324325

325326
def test_mtime(self):
326327
mtime = 123456789
327-
with igzip.IGzipFile(self.filename, 'w', mtime = mtime) as fWrite:
328+
with igzip.IGzipFile(self.filename, 'w', mtime=mtime) as fWrite:
328329
fWrite.write(data1)
329330
with igzip.IGzipFile(self.filename) as fRead:
330331
self.assertTrue(hasattr(fRead, 'mtime'))
@@ -336,22 +337,22 @@ def test_mtime(self):
336337
def test_metadata(self):
337338
mtime = 123456789
338339

339-
with igzip.IGzipFile(self.filename, 'w', mtime = mtime) as fWrite:
340+
with igzip.IGzipFile(self.filename, 'w', mtime=mtime) as fWrite:
340341
fWrite.write(data1)
341342

342343
with open(self.filename, 'rb') as fRead:
343344
# see RFC 1952: http://www.faqs.org/rfcs/rfc1952.html
344345

345346
idBytes = fRead.read(2)
346-
self.assertEqual(idBytes, b'\x1f\x8b') # igzip ID
347+
self.assertEqual(idBytes, b'\x1f\x8b') # igzip ID
347348

348349
cmByte = fRead.read(1)
349-
self.assertEqual(cmByte, b'\x08') # deflate
350+
self.assertEqual(cmByte, b'\x08') # deflate
350351

351352
try:
352353
expectedname = os.path.basename(self.filename).encode(
353354
'Latin-1') + b'\x00'
354-
expectedflags = b'\x08' # only the FNAME flag is set
355+
expectedflags = b'\x08' # only the FNAME flag is set
355356
except UnicodeEncodeError:
356357
expectedname = b''
357358
expectedflags = b'\x00'
@@ -360,26 +361,28 @@ def test_metadata(self):
360361
self.assertEqual(flagsByte, expectedflags)
361362

362363
mtimeBytes = fRead.read(4)
363-
self.assertEqual(mtimeBytes, struct.pack('<i', mtime)) # little-endian
364+
self.assertEqual(mtimeBytes,
365+
struct.pack('<i', mtime)) # little-endian
364366

365367
xflByte = fRead.read(1)
366-
self.assertEqual(xflByte, b'\x02') # maximum compression
368+
self.assertEqual(xflByte, b'\x02') # maximum compression
367369

368370
osByte = fRead.read(1)
369-
self.assertEqual(osByte, b'\xff') # OS "unknown" (OS-independent)
371+
self.assertEqual(osByte, b'\xff') # OS "unknown" (OS-independent)
370372

371-
# Since the FNAME flag is set, the zero-terminated filename follows.
372-
# RFC 1952 specifies that this is the name of the input file, if any.
373-
# However, the igzip module defaults to storing the name of the output
374-
# file in this field.
373+
# Since the FNAME flag is set, the zero-terminated filename
374+
# follows. RFC 1952 specifies that this is the name of the input
375+
# file, if any. However, the gzip module defaults to storing the
376+
# name of the output file in this field.
375377
nameBytes = fRead.read(len(expectedname))
376378
self.assertEqual(nameBytes, expectedname)
377379

378380
# Since no other flags were set, the header ends here.
379-
# Rather than process the compressed data, let's seek to the trailer.
381+
# Rather than process the compressed data, let's seek to the
382+
# trailer.
380383
fRead.seek(os.stat(self.filename).st_size - 8)
381384

382-
crc32Bytes = fRead.read(4) # CRC32 of uncompressed data [data1]
385+
crc32Bytes = fRead.read(4) # CRC32 of uncompressed data [data1]
383386
self.assertEqual(crc32Bytes, b'\xaf\xd7d\x83')
384387

385388
isizeBytes = fRead.read(4)
@@ -401,11 +404,12 @@ def test_compresslevel_metadata(self):
401404

402405
for (name, level, expectedXflByte) in cases:
403406
major, minor, _, _, _ = sys.version_info
404-
if major == 3 and minor <=7 or major < 3:
407+
if major == 3 and minor <= 7 or major < 3:
405408
# Specific xfl bytes introduced in 3.7
406409
expectedXflByte = b'\x02'
407410
with self.subTest(name):
408-
fWrite = igzip.IGzipFile(self.filename, 'w', compresslevel=level)
411+
fWrite = igzip.IGzipFile(self.filename, 'w',
412+
compresslevel=level)
409413
with fWrite:
410414
fWrite.write(data1)
411415
with open(self.filename, 'rb') as fRead:
@@ -428,7 +432,7 @@ def test_with_open(self):
428432
self.fail("__enter__ on a closed file didn't raise an exception")
429433
try:
430434
with igzip.IGzipFile(self.filename, "wb") as f:
431-
1/0
435+
1 / 0
432436
except ZeroDivisionError:
433437
pass
434438
else:
@@ -510,7 +514,7 @@ def test_fileobj_from_fdopen(self):
510514
# fileobj created with os.fdopen().
511515
fd = os.open(self.filename, os.O_WRONLY | os.O_CREAT)
512516
with os.fdopen(fd, "wb") as f:
513-
with igzip.IGzipFile(fileobj=f, mode="w") as g:
517+
with igzip.IGzipFile(fileobj=f, mode="w"):
514518
pass
515519

516520
def test_fileobj_mode(self):
@@ -567,7 +571,7 @@ def test_decompress_limited(self):
567571
self.assertEqual(decomp.read(1), b'\0')
568572
max_decomp = 1 + io.DEFAULT_BUFFER_SIZE
569573
self.assertLessEqual(decomp._buffer.raw.tell(), max_decomp,
570-
"Excessive amount of data was decompressed")
574+
"Excessive amount of data was decompressed")
571575

572576
# Testing compress/decompress shortcut functions
573577

@@ -576,7 +580,8 @@ def test_compress(self):
576580
for args in [(), (1,), (2,), (3,), (0,)]:
577581
datac = igzip.compress(data, *args)
578582
self.assertEqual(type(datac), bytes)
579-
with igzip.IGzipFile(fileobj=io.BytesIO(datac), mode="rb") as f:
583+
with igzip.IGzipFile(fileobj=io.BytesIO(datac),
584+
mode="rb") as f:
580585
self.assertEqual(f.read(), data)
581586

582587
def test_compress_mtime(self):
@@ -586,8 +591,9 @@ def test_compress_mtime(self):
586591
with self.subTest(data=data, args=args):
587592
datac = igzip.compress(data, *args, mtime=mtime)
588593
self.assertEqual(type(datac), bytes)
589-
with igzip.IGzipFile(fileobj=io.BytesIO(datac), mode="rb") as f:
590-
f.read(1) # to set mtime attribute
594+
with igzip.IGzipFile(fileobj=io.BytesIO(datac),
595+
mode="rb") as f:
596+
f.read(1) # to set mtime attribute
591597
self.assertEqual(f.mtime, mtime)
592598

593599
def test_decompress(self):
@@ -601,7 +607,7 @@ def test_decompress(self):
601607
self.assertEqual(igzip.decompress(datac), data)
602608

603609
def test_read_truncated(self):
604-
data = data1*50
610+
data = data1 * 50
605611
# Drop the CRC (4 bytes) and file size (4 bytes).
606612
truncated = igzip.compress(data)[:-8]
607613
with igzip.IGzipFile(fileobj=io.BytesIO(truncated)) as f:
@@ -629,6 +635,7 @@ def test_prepend_error(self):
629635
with igzip.open(self.filename, "rb") as f:
630636
f._buffer.raw._fp.prepend()
631637

638+
632639
class TestOpen(BaseTest):
633640
def test_binary_modes(self):
634641
uncompressed = data1 * 50
@@ -752,8 +759,8 @@ def test_encoding_error_handler(self):
752759
# Test with non-default encoding error handler.
753760
with igzip.open(self.filename, "wb") as f:
754761
f.write(b"foo\xffbar")
755-
with igzip.open(self.filename, "rt", encoding="ascii", errors="ignore") \
756-
as f:
762+
with igzip.open(self.filename, "rt", encoding="ascii",
763+
errors="ignore") as f:
757764
self.assertEqual(f.read(), "foobar")
758765

759766
def test_newline(self):
@@ -774,7 +781,9 @@ def wrapper(*args, **kwargs):
774781
return function(*args, **kwargs)
775782
finally:
776783
shutil.rmtree(directory)
784+
777785
return wrapper
786+
778787
return decorator
779788

780789

@@ -811,7 +820,8 @@ def test_decompress_infile_outfile(self):
811820
self.assertEqual(err, b'')
812821

813822
def test_decompress_infile_outfile_error(self):
814-
rc, out, err = assert_python_ok('-m', 'isal.igzip', '-d', 'thisisatest.out')
823+
rc, out, err = assert_python_ok('-m', 'isal.igzip', '-d',
824+
'thisisatest.out')
815825
self.assertIn(b"filename doesn't end in .gz:", out)
816826
self.assertEqual(rc, 0)
817827
self.assertEqual(err, b'')
@@ -851,7 +861,9 @@ def test_compress_infile_outfile(self):
851861
with open(local_testigzip, 'wb') as fp:
852862
fp.write(self.data)
853863

854-
rc, out, err = assert_python_ok('-m', 'isal.igzip', compress_level, local_testigzip)
864+
rc, out, err = assert_python_ok('-m', 'isal.igzip',
865+
compress_level,
866+
local_testigzip)
855867

856868
self.assertTrue(os.path.exists(igzipname))
857869
self.assertEqual(out, b'')
@@ -860,13 +872,20 @@ def test_compress_infile_outfile(self):
860872
self.assertFalse(os.path.exists(igzipname))
861873

862874
def test_compress_fast_best_are_exclusive(self):
863-
rc, out, err = assert_python_failure('-m', 'isal.igzip', '--fast', '--best')
864-
self.assertIn(b"error: argument -3/--best: not allowed with argument -0/--fast", err)
875+
rc, out, err = assert_python_failure('-m', 'isal.igzip', '--fast',
876+
'--best')
877+
self.assertIn(
878+
b"error: argument -3/--best: not allowed with argument -0/--fast",
879+
err)
865880
self.assertEqual(out, b'')
866881

867882
def test_decompress_cannot_have_flags_compression(self):
868-
rc, out, err = assert_python_failure('-m', 'isal.igzip', '--fast', '-d')
869-
self.assertIn(b'error: argument -d/--decompress: not allowed with argument -0/--fast', err)
883+
rc, out, err = assert_python_failure('-m', 'isal.igzip', '--fast',
884+
'-d')
885+
self.assertIn(
886+
b'error: argument -d/--decompress: not allowed with argument '
887+
b'-0/--fast',
888+
err)
870889
self.assertEqual(out, b'')
871890

872891

0 commit comments

Comments
 (0)