do some linting with flake8
This commit is contained in:
parent
0bbc8f8e08
commit
4d362f8e09
30
.flake8
Normal file
30
.flake8
Normal file
@ -0,0 +1,30 @@
|
||||
[flake8]
|
||||
ignore =
|
||||
# E501 line too long
|
||||
E501,
|
||||
# W391 newlines at EOF
|
||||
W391,
|
||||
# E241 multiple spaces after comma
|
||||
E241,
|
||||
# E302 expected 2 newlines
|
||||
E302,
|
||||
# W503 line break before binary operator (to be deprecated)
|
||||
W503,
|
||||
# E265 block comment should start with '# '
|
||||
E265,
|
||||
# E123 closing bracket does not match indentation of opening bracket's line
|
||||
E123,
|
||||
# E124 closing bracket does not match visual indentation
|
||||
E124,
|
||||
# E221 multiple spaces before operator
|
||||
E221,
|
||||
# E201 whitespace after '['
|
||||
E201,
|
||||
# # E741 ambiguous variable name 'I'
|
||||
# E741,
|
||||
|
||||
|
||||
per-file-ignores =
|
||||
# F401 import without use
|
||||
*/__init__.py: F401,
|
||||
__init__.py: F401,
|
@ -68,7 +68,7 @@ def parse_datetime(data: bytes) -> List[datetime]:
|
||||
raise KlamathError(f'Incorrect datetime size ({len(data)}). Data is {data!r}.')
|
||||
dts = []
|
||||
for ii in range(0, len(data), 12):
|
||||
year, *date_parts = parse_int2(data[ii:ii+12])
|
||||
year, *date_parts = parse_int2(data[ii:ii + 12])
|
||||
dts.append(datetime(year + 1900, *date_parts))
|
||||
return dts
|
||||
|
||||
@ -149,7 +149,7 @@ def encode_real8(fnums: numpy.ndarray) -> numpy.ndarray:
|
||||
|
||||
real8 = sign | gds_exp_bits | gds_mant
|
||||
real8[zero] = 0
|
||||
real8[gds_exp < -14] = 0 # number is too small
|
||||
real8[gds_exp < -14] = 0 # number is too small
|
||||
|
||||
return real8
|
||||
|
||||
|
@ -28,7 +28,6 @@ T = TypeVar('T', bound='Text')
|
||||
X = TypeVar('X', bound='Box')
|
||||
|
||||
|
||||
|
||||
def read_properties(stream: IO[bytes]) -> Dict[int, bytes]:
|
||||
"""
|
||||
Read element properties.
|
||||
@ -189,7 +188,7 @@ class Reference(Element):
|
||||
b += STRANS.write(stream, int(self.invert_y) << 15)
|
||||
if self.mag != 1:
|
||||
b += MAG.write(stream, self.mag)
|
||||
if self.angle_deg !=0:
|
||||
if self.angle_deg != 0:
|
||||
b += ANGLE.write(stream, self.angle_deg)
|
||||
|
||||
if self.colrow is not None:
|
||||
@ -481,7 +480,7 @@ class Text(Element):
|
||||
b += STRANS.write(stream, int(self.invert_y) << 15)
|
||||
if self.mag != 1:
|
||||
b += MAG.write(stream, self.mag)
|
||||
if self.angle_deg !=0:
|
||||
if self.angle_deg != 0:
|
||||
b += ANGLE.write(stream, self.angle_deg)
|
||||
b += XY.write(stream, self.xy)
|
||||
b += STRING.write(stream, self.string)
|
||||
|
@ -55,7 +55,7 @@ class FileHeader:
|
||||
Returns:
|
||||
FileHeader object
|
||||
"""
|
||||
version = HEADER.read(stream)[0]
|
||||
_version = HEADER.read(stream)[0] # noqa: F841 # var is unused
|
||||
mod_time, acc_time = BGNLIB.read(stream)
|
||||
name = LIBNAME.skip_and_read(stream)
|
||||
uu, dbu = UNITS.skip_and_read(stream)
|
||||
@ -223,7 +223,7 @@ def scan_hierarchy(stream: IO[bytes]) -> Dict[bytes, Dict[bytes, int]]:
|
||||
elif tag == ENDEL.tag:
|
||||
if ref_count is None:
|
||||
ref_count = 1
|
||||
assert(ref_name is not None)
|
||||
assert ref_name is not None
|
||||
cur_structure[ref_name] += ref_count
|
||||
else:
|
||||
stream.seek(size, io.SEEK_CUR)
|
||||
|
@ -111,7 +111,7 @@ class PRESENTATION(BitArrayRecord):
|
||||
|
||||
|
||||
class SPACING(Int2Record):
|
||||
tag = 0x1802 #Not sure about 02; Unused
|
||||
tag = 0x1802 # Not sure about 02; Unused
|
||||
|
||||
|
||||
class STRING(ASCIIRecord):
|
||||
@ -133,11 +133,11 @@ class ANGLE(Real8Record):
|
||||
|
||||
|
||||
class UINTEGER(Int2Record):
|
||||
tag = 0x1d02 #Unused; not sure about 02
|
||||
tag = 0x1d02 # Unused; not sure about 02
|
||||
|
||||
|
||||
class USTRING(ASCIIRecord):
|
||||
tag = 0x1e06 #Unused; not sure about 06
|
||||
tag = 0x1e06 # Unused; not sure about 06
|
||||
|
||||
|
||||
class REFLIBS(ASCIIRecord):
|
||||
@ -183,11 +183,11 @@ class ATTRTABLE(ASCIIRecord):
|
||||
|
||||
|
||||
class STYPTABLE(ASCIIRecord):
|
||||
tag = 0x2406 #UNUSED, not sure about 06
|
||||
tag = 0x2406 # UNUSED, not sure about 06
|
||||
|
||||
|
||||
class STRTYPE(Int2Record):
|
||||
tag = 0x2502 #UNUSED
|
||||
tag = 0x2502 # UNUSED
|
||||
|
||||
|
||||
class ELFLAGS(BitArrayRecord):
|
||||
|
@ -12,9 +12,9 @@ from .basic import KlamathError
|
||||
|
||||
|
||||
def test_parse_bitarray():
|
||||
assert(parse_bitarray(b'59') == 13625)
|
||||
assert(parse_bitarray(b'\0\0') == 0)
|
||||
assert(parse_bitarray(b'\xff\xff') == 65535)
|
||||
assert parse_bitarray(b'59') == 13625
|
||||
assert parse_bitarray(b'\0\0') == 0
|
||||
assert parse_bitarray(b'\xff\xff') == 65535
|
||||
|
||||
# 4 bytes (too long)
|
||||
with pytest.raises(KlamathError):
|
||||
@ -51,12 +51,12 @@ def test_parse_int4():
|
||||
|
||||
def test_decode_real8():
|
||||
# zeroes
|
||||
assert(decode_real8(numpy.array([0x0])) == 0)
|
||||
assert(decode_real8(numpy.array([1<<63])) == 0) # negative
|
||||
assert(decode_real8(numpy.array([0xff << 56])) == 0) # denormalized
|
||||
assert decode_real8(numpy.array([0x0])) == 0
|
||||
assert decode_real8(numpy.array([1 << 63])) == 0 # negative
|
||||
assert decode_real8(numpy.array([0xff << 56])) == 0 # denormalized
|
||||
|
||||
assert(decode_real8(numpy.array([0x4110 << 48])) == 1.0)
|
||||
assert(decode_real8(numpy.array([0xC120 << 48])) == -2.0)
|
||||
assert decode_real8(numpy.array([0x4110 << 48])) == 1.0
|
||||
assert decode_real8(numpy.array([0xC120 << 48])) == -2.0
|
||||
|
||||
|
||||
def test_parse_real8():
|
||||
@ -73,36 +73,36 @@ def test_parse_real8():
|
||||
|
||||
|
||||
def test_parse_ascii():
|
||||
# # empty data Now allowed!
|
||||
# with pytest.raises(KlamathError):
|
||||
# parse_ascii(b'')
|
||||
# # empty data Now allowed!
|
||||
# with pytest.raises(KlamathError):
|
||||
# parse_ascii(b'')
|
||||
|
||||
assert(parse_ascii(b'12345') == b'12345')
|
||||
assert(parse_ascii(b'12345\0') == b'12345') # strips trailing null byte
|
||||
assert parse_ascii(b'12345') == b'12345'
|
||||
assert parse_ascii(b'12345\0') == b'12345' # strips trailing null byte
|
||||
|
||||
|
||||
def test_pack_bitarray():
|
||||
packed = pack_bitarray(321)
|
||||
assert(len(packed) == 2)
|
||||
assert(packed == struct.pack('>H', 321))
|
||||
assert len(packed) == 2
|
||||
assert packed == struct.pack('>H', 321)
|
||||
|
||||
|
||||
def test_pack_int2():
|
||||
packed = pack_int2((3, 2, 1))
|
||||
assert(len(packed) == 3*2)
|
||||
assert(packed == struct.pack('>3h', 3, 2, 1))
|
||||
assert(pack_int2([-3, 2, -1]) == struct.pack('>3h', -3, 2, -1))
|
||||
assert len(packed) == 3 * 2
|
||||
assert packed == struct.pack('>3h', 3, 2, 1)
|
||||
assert pack_int2([-3, 2, -1]) == struct.pack('>3h', -3, 2, -1)
|
||||
|
||||
|
||||
def test_pack_int4():
|
||||
packed = pack_int4((3, 2, 1))
|
||||
assert(len(packed) == 3*4)
|
||||
assert(packed == struct.pack('>3l', 3, 2, 1))
|
||||
assert(pack_int4([-3, 2, -1]) == struct.pack('>3l', -3, 2, -1))
|
||||
assert len(packed) == 3 * 4
|
||||
assert packed == struct.pack('>3l', 3, 2, 1)
|
||||
assert pack_int4([-3, 2, -1]) == struct.pack('>3l', -3, 2, -1)
|
||||
|
||||
|
||||
def test_encode_real8():
|
||||
assert(encode_real8(numpy.array([0.0])) == 0)
|
||||
assert encode_real8(numpy.array([0.0])) == 0
|
||||
arr = numpy.array((1.0, -2.0, 1e-9, 1e-3, 1e-12))
|
||||
assert_array_equal(decode_real8(encode_real8(arr)), arr)
|
||||
|
||||
@ -110,10 +110,10 @@ def test_encode_real8():
|
||||
def test_pack_real8():
|
||||
reals = (0, 1, -1, 0.5, 1e-9, 1e-3, 1e-12)
|
||||
packed = pack_real8(reals)
|
||||
assert(len(packed) == len(reals) * 8)
|
||||
assert len(packed) == len(reals) * 8
|
||||
assert_array_equal(parse_real8(packed), reals)
|
||||
|
||||
|
||||
def test_pack_ascii():
|
||||
assert(pack_ascii(b'4321') == b'4321')
|
||||
assert(pack_ascii(b'321') == b'321\0')
|
||||
assert pack_ascii(b'4321') == b'4321'
|
||||
assert pack_ascii(b'321') == b'321\0'
|
||||
|
Loading…
Reference in New Issue
Block a user