Skip to content

Commit

Permalink
pre-commit: autoupdate hooks (commaai#1618)
Browse files Browse the repository at this point in the history
* Update pre-commit hook versions

* fix ranges

---------

Co-authored-by: adeebshihadeh <adeebshihadeh@users.noreply.github.com>
Co-authored-by: Shane Smiskol <shane@smiskol.com>
  • Loading branch information
3 people authored Aug 30, 2023
1 parent e6c1648 commit 526588b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ repos:
additional_dependencies: ['git+https://github.com/numpy/numpy-stubs', 'types-requests', 'types-atomicwrites',
'types-pycurl']
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.285
rev: v0.0.286
hooks:
- id: ruff
8 changes: 4 additions & 4 deletions python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def reconnect(self):

success = False
# wait up to 15 seconds
for _ in range(0, 15*10):
for _ in range(15*10):
try:
self.connect()
success = True
Expand Down Expand Up @@ -511,7 +511,7 @@ def flash_static(handle, code, mcu_type):
# flash over EP2
STEP = 0x10
logging.warning("flash: flashing")
for i in range(0, len(code), STEP):
for i in range(len(code), STEP):
handle.bulkWrite(2, code[i:i + STEP])

# reset
Expand Down Expand Up @@ -887,7 +887,7 @@ def serial_write(self, port_number, ln):
ret = 0
if isinstance(ln, str):
ln = bytes(ln, 'utf-8')
for i in range(0, len(ln), 0x20):
for i in range(len(ln), 0x20):
ret += self._handle.bulkWrite(2, struct.pack("B", port_number) + ln[i:i + 0x20])
return ret

Expand Down Expand Up @@ -940,7 +940,7 @@ def kline_send(self, x, bus=2, checksum=True):
self.kline_drain(bus=bus)
if checksum:
x += bytes([sum(x) % 0x100])
for i in range(0, len(x), 0xf):
for i in range(len(x), 0xf):
ts = x[i:i + 0xf]
logging.debug(f"kline send: 0x{ts.hex()}")
self._handle.bulkWrite(2, bytes([bus]) + ts)
Expand Down
2 changes: 1 addition & 1 deletion python/spi.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ def close(self):
def program(self, address, dat):
bs = 256 # max block size for writing to flash over SPI
dat += b"\xFF" * ((bs - len(dat)) % bs)
for i in range(0, len(dat) // bs):
for i in range(len(dat) // bs):
block = dat[i * bs:(i + 1) * bs]
self._cmd(0x31, data=[
struct.pack('>I', address + i*bs),
Expand Down
2 changes: 1 addition & 1 deletion python/usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def program(self, address, dat):
# Program
bs = min(len(dat), self._mcu_type.config.block_size)
dat += b"\xFF" * ((bs - len(dat)) % bs)
for i in range(0, len(dat) // bs):
for i in range(len(dat) // bs):
ldat = dat[i * bs:(i + 1) * bs]
print("programming %d with length %d" % (i, len(ldat)))
self._libusb_handle.controlWrite(0x21, self.DFU_DNLOAD, 2 + i, 0, ldat)
Expand Down
16 changes: 8 additions & 8 deletions tests/safety/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_prev_gas_interceptor(self):
self.safety.set_gas_interceptor_detected(False)

def test_disengage_on_gas_interceptor(self):
for g in range(0, 0x1000):
for g in range(0x1000):
self._rx(self._interceptor_user_gas(0))
self.safety.set_controls_allowed(True)
self._rx(self._interceptor_user_gas(g))
Expand All @@ -138,7 +138,7 @@ def test_disengage_on_gas_interceptor(self):
def test_alternative_experience_no_disengage_on_gas_interceptor(self):
self.safety.set_controls_allowed(True)
self.safety.set_alternative_experience(ALTERNATIVE_EXPERIENCE.DISABLE_DISENGAGE_ON_GAS)
for g in range(0, 0x1000):
for g in range(0x1000):
self._rx(self._interceptor_user_gas(g))
# Test we allow lateral, but not longitudinal
self.assertTrue(self.safety.get_controls_allowed())
Expand Down Expand Up @@ -576,13 +576,13 @@ def test_torque_measurements(self):
self.assertTrue(self.safety.get_torque_meas_min() in min_range)
self.assertTrue(self.safety.get_torque_meas_max() in max_range)

max_range = range(0, self.TORQUE_MEAS_TOLERANCE + 1)
max_range = range(self.TORQUE_MEAS_TOLERANCE + 1)
min_range = range(-(trq + self.TORQUE_MEAS_TOLERANCE), -trq + 1)
self._rx(self._torque_meas_msg(0))
self.assertTrue(self.safety.get_torque_meas_min() in min_range)
self.assertTrue(self.safety.get_torque_meas_max() in max_range)

max_range = range(0, self.TORQUE_MEAS_TOLERANCE + 1)
max_range = range(self.TORQUE_MEAS_TOLERANCE + 1)
min_range = range(-self.TORQUE_MEAS_TOLERANCE, 0 + 1)
self._rx(self._torque_meas_msg(0))
self.assertTrue(self.safety.get_torque_meas_min() in min_range)
Expand Down Expand Up @@ -733,7 +733,7 @@ def test_angle_cmd_when_disabled(self):
@add_regen_tests
class PandaSafetyTest(PandaSafetyTestBase):
TX_MSGS: Optional[List[List[int]]] = None
SCANNED_ADDRS = [*range(0x0, 0x800), # Entire 11-bit CAN address space
SCANNED_ADDRS = [*range(0x800), # Entire 11-bit CAN address space
*range(0x18DA00F1, 0x18DB00F1, 0x100), # 29-bit UDS physical addressing
*range(0x18DB00F1, 0x18DC00F1, 0x100), # 29-bit UDS functional addressing
*range(0x3300, 0x3400), # Honda
Expand Down Expand Up @@ -791,14 +791,14 @@ def test_relay_malfunction(self):
self.assertFalse(self.safety.get_relay_malfunction())
self._rx(make_msg(self.RELAY_MALFUNCTION_BUS, self.RELAY_MALFUNCTION_ADDR, 8))
self.assertTrue(self.safety.get_relay_malfunction())
for bus in range(0, 3):
for bus in range(3):
for addr in self.SCANNED_ADDRS:
self.assertEqual(-1, self._tx(make_msg(bus, addr, 8)))
self.assertEqual(-1, self.safety.safety_fwd_hook(bus, addr))

def test_fwd_hook(self):
# some safety modes don't forward anything, while others blacklist msgs
for bus in range(0, 3):
for bus in range(3):
for addr in self.SCANNED_ADDRS:
# assume len 8
fwd_bus = self.FWD_BUS_LOOKUP.get(bus, -1)
Expand All @@ -807,7 +807,7 @@ def test_fwd_hook(self):
self.assertEqual(fwd_bus, self.safety.safety_fwd_hook(bus, addr), f"{addr=:#x} from {bus=} to {fwd_bus=}")

def test_spam_can_buses(self):
for bus in range(0, 4):
for bus in range(4):
for addr in self.SCANNED_ADDRS:
if all(addr != m[0] or bus != m[1] for m in self.TX_MSGS):
self.assertFalse(self._tx(make_msg(bus, addr, 8)), f"allowed TX {addr=} {bus=}")
Expand Down
4 changes: 2 additions & 2 deletions tests/safety/test_honda.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ def _send_acc_hud_msg(self, pcm_gas, pcm_speed):
def test_acc_hud_safety_check(self):
for controls_allowed in [True, False]:
self.safety.set_controls_allowed(controls_allowed)
for pcm_gas in range(0, 255):
for pcm_speed in range(0, 100):
for pcm_gas in range(255):
for pcm_speed in range(100):
send = (controls_allowed and pcm_gas <= self.MAX_GAS) or (pcm_gas == 0 and pcm_speed == 0)
self.assertEqual(send, self._tx(self._send_acc_hud_msg(pcm_gas, pcm_speed)))

Expand Down

0 comments on commit 526588b

Please sign in to comment.