Skip to content

Commit 0c5cb15

Browse files
committed
QA: Black assisted code quality pass.
1 parent 4737e82 commit 0c5cb15

File tree

5 files changed

+34
-37
lines changed

5 files changed

+34
-37
lines changed

examples/bargraph.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
"""
1313
QNH = 1013.25
1414

15-
BAR_CHAR = u'\u2588'
15+
BAR_CHAR = "\u2588"
1616

17-
ANSI_COLOR_RED = '\x1b[31m'
18-
ANSI_COLOR_GREEN = '\x1b[32m'
19-
ANSI_COLOR_YELLOW = '\x1b[33m'
20-
ANSI_COLOR_BLUE = '\x1b[34m'
21-
ANSI_COLOR_MAGENTA = '\x1b[35m'
22-
ANSI_COLOR_BLACK = '\x1b[30m'
23-
ANSI_COLOR_RESET = '\x1b[0m'
17+
ANSI_COLOR_RED = "\x1b[31m"
18+
ANSI_COLOR_GREEN = "\x1b[32m"
19+
ANSI_COLOR_YELLOW = "\x1b[33m"
20+
ANSI_COLOR_BLUE = "\x1b[34m"
21+
ANSI_COLOR_MAGENTA = "\x1b[35m"
22+
ANSI_COLOR_BLACK = "\x1b[30m"
23+
ANSI_COLOR_RESET = "\x1b[0m"
2424

2525

2626
colours = [ANSI_COLOR_BLUE, ANSI_COLOR_GREEN, ANSI_COLOR_YELLOW, ANSI_COLOR_RED, ANSI_COLOR_MAGENTA]
@@ -83,12 +83,15 @@ def calculate_altitude(pressure, qnh=1013.25):
8383
p_bar = p_colour + p_bar + ANSI_COLOR_RESET
8484
a_bar = a_colour + a_bar + ANSI_COLOR_RESET
8585

86-
t_reading = "{:.4f}c".format(temperature).ljust(BAR_WIDTH + 14)
87-
p_reading = "{:.4f}hPa".format(pressure / 100).ljust(BAR_WIDTH + 14)
88-
a_reading = "{:.2f}m".format(altitude).ljust(BAR_WIDTH + 14)
86+
t_reading = f"{temperature:.4f}c".ljust(BAR_WIDTH + 14)
87+
p_reading = f"{pressure / 100:.4f}hPa".ljust(BAR_WIDTH + 14)
88+
a_reading = f"{altitude:.2f}m".ljust(BAR_WIDTH + 14)
8989

90-
sys.stdout.write('\x1b[0;1H')
91-
sys.stdout.write(u"""{title}
90+
title = "ICP10125 Sensor".ljust(BAR_WIDTH + 14, " ")
91+
blank = " " * (BAR_WIDTH + 14)
92+
93+
sys.stdout.write("\x1b[0;1H")
94+
sys.stdout.write(f"""{title}
9295
{blank}
9396
Temperature: {t_bar}
9497
{t_reading}
@@ -97,16 +100,7 @@ def calculate_altitude(pressure, qnh=1013.25):
97100
Altitude: {a_bar}
98101
{a_reading}
99102
{blank}
100-
""".format(
101-
title="ICP10125 Sensor".ljust(BAR_WIDTH + 14, " "),
102-
t_bar=t_bar,
103-
p_bar=p_bar,
104-
a_bar=a_bar,
105-
t_reading=t_reading,
106-
p_reading=p_reading,
107-
a_reading=a_reading,
108-
blank=" " * (BAR_WIDTH + 14)
109-
))
103+
""")
110104
sys.stdout.flush()
111105

112106
except KeyboardInterrupt:

icp10125/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from smbus2 import SMBus, i2c_msg
55

6-
__version__ = '0.0.1'
6+
__version__ = "0.0.1"
77

88
NORMAL = 0x6825
99
LOW_POWER = 0x609C
@@ -49,7 +49,7 @@ def __init__(self, address=None):
4949

5050
chip_id = self.chip_id()
5151
if chip_id != CHIP_ID:
52-
raise RuntimeError("ICP10125: Invalid Chip ID {:02x}, expected: {:02x}".format(chip_id, CHIP_ID))
52+
raise RuntimeError(f"ICP10125: Invalid Chip ID {chip_id:02x}, expected: {CHIP_ID:02x}")
5353

5454
self.read_otp()
5555

@@ -72,7 +72,7 @@ def rdwr(self, command, length=0, delay=0):
7272
result = list(msg_r)
7373
data = []
7474
for chunk in range(0, len(result), 3):
75-
if self.crc8(result[chunk:chunk + 2]) != result[chunk + 2]:
75+
if self.crc8(result[chunk : chunk + 2]) != result[chunk + 2]:
7676
raise ValueError("ICP10125: Invalid CRC8 in response.")
7777
data.append((result[chunk] << 8) | result[chunk + 1])
7878
if len(data) == 1:
@@ -84,12 +84,12 @@ def rdwr(self, command, length=0, delay=0):
8484

8585
def chip_id(self):
8686
result = self.rdwr(READ_ID, 3)
87-
return result & 0x3f
87+
return result & 0x3F
8888

8989
def read_otp(self):
9090
move_address_ptr = [
9191
MOVE_ADDRESS_PTR >> 8, MOVE_ADDRESS_PTR & 0xff,
92-
0x00, 0x66, 0x9c # Address CRC8
92+
0x00, 0x66, 0x9C # Address CRC8
9393
]
9494
self.rdwr(move_address_ptr)
9595

@@ -144,7 +144,7 @@ def calculate_conversion_constants(self, p_LUT):
144144
return A, B, C
145145

146146
def crc8(self, data, polynomial=0x31):
147-
result = 0xff
147+
result = 0xFF
148148
for byte in data:
149149
result ^= byte
150150
for bit in range(8):
@@ -153,4 +153,4 @@ def crc8(self, data, polynomial=0x31):
153153
result ^= polynomial
154154
else:
155155
result <<= 1
156-
return result & 0xff
156+
return result & 0xFF

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ skip = """
9494
[tool.isort]
9595
line_length = 200
9696

97+
[tool.black]
98+
line_length = 200
99+
97100
[tool.check-manifest]
98101
ignore = [
99102
'.stickler.yml',

tests/conftest.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
import pytest
55

66

7-
@pytest.fixture(scope='function', autouse=False)
7+
@pytest.fixture(scope="function", autouse=False)
88
def smbus2():
99
"""Mock smbus module."""
10-
sys.modules['smbus2'] = mock.MagicMock()
11-
yield sys.modules['smbus2']
12-
del sys.modules['smbus2']
10+
sys.modules["smbus2"] = mock.MagicMock()
11+
yield sys.modules["smbus2"]
12+
del sys.modules["smbus2"]
1313

1414

15-
@pytest.fixture(scope='function', autouse=False)
15+
@pytest.fixture(scope="function", autouse=False)
1616
def icp10125():
1717
"""Import icp10125 module."""
1818
import icp10125
1919
yield icp10125
20-
del sys.modules['icp10125']
20+
del sys.modules["icp10125"]

tests/test_setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ def test_setup_invalid_crc8(smbus2, icp10125):
2121

2222
with pytest.raises(ValueError):
2323
sensor = icp10125.ICP10125()
24-
del sensor
24+
del sensor

0 commit comments

Comments
 (0)