Stricter pylint (#550)

* stricter pylint

* Add as argument
master
Willem Melching 2020-06-02 16:27:07 -07:00 committed by GitHub
parent a38925a0a4
commit e0a706e4f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 83 additions and 79 deletions

View File

@ -29,4 +29,5 @@ repos:
types: [python]
exclude: '^(tests/automated)/'
args:
- --disable=R,C,W
- --disable=C,R,W0613,W0511,W0212,W0201,W0311,W0106,W0603,W0621,W0703,E1136
- --generated-members="usb1.*"

View File

@ -1,2 +0,0 @@
[MASTER]
generated-members=usb1.*

View File

@ -10,7 +10,7 @@ def egcd(a, b):
return (g, x - (b // a) * y, y)
def modinv(a, m):
g, x, y = egcd(a, m)
g, x, _ = egcd(a, m)
if g != 1:
raise Exception('modular inverse does not exist')
else:
@ -23,7 +23,7 @@ def to_c_string(x):
def to_c_uint32(x):
nums = []
for i in range(0x20):
for _ in range(0x20):
nums.append(x % (2**32))
x //= (2**32)
return "{" + 'U,'.join(map(str, nums)) + "U}"

View File

@ -29,8 +29,8 @@ class Info():
def load(self, filename, start, end):
"""Given a CSV file, adds information about message IDs and their values."""
with open(filename, 'rb') as input:
reader = csv.reader(input)
with open(filename, 'rb') as inp:
reader = csv.reader(inp)
next(reader, None) # skip the CSV header
for row in reader:
if not len(row):
@ -55,12 +55,12 @@ class Info():
self.messages[message_id] = Message(message_id)
new_message = True
message = self.messages[message_id]
bytes = bytearray.fromhex(data)
for i in range(len(bytes)):
ones = int(bytes[i])
bts = bytearray.fromhex(data)
for i in range(len(bts)):
ones = int(bts[i])
message.ones[i] = ones if new_message else message.ones[i] & ones
# Inverts the data and masks it to a byte to get the zeros as ones.
zeros = (~int(bytes[i])) & 0xff
zeros = (~int(bts[i])) & 0xff
message.zeros[i] = zeros if new_message else message.zeros[i] & zeros
def PrintUnique(log_file, low_range, high_range):

View File

@ -52,8 +52,8 @@ class Info():
def load(self, filename):
"""Given a CSV file, adds information about message IDs and their values."""
with open(filename, 'r') as input:
reader = csv.reader(input)
with open(filename, 'r') as inp:
reader = csv.reader(inp)
header = next(reader, None)
if header[0] == 'time':
self.cabana(reader)
@ -88,11 +88,11 @@ class Info():
message = self.messages[message_id]
if data not in self.messages[message_id].data:
message.data[data] = True
bytes = bytearray.fromhex(data)
for i in range(len(bytes)):
message.ones[i] = message.ones[i] | int(bytes[i])
bts = bytearray.fromhex(data)
for i in range(len(bts)):
message.ones[i] = message.ones[i] | int(bts[i])
# Inverts the data and masks it to a byte to get the zeros as ones.
message.zeros[i] = message.zeros[i] | ((~int(bytes[i])) & 0xff)
message.zeros[i] = message.zeros[i] | ((~int(bts[i])) & 0xff)
def PrintUnique(interesting_file, background_files):

View File

@ -16,7 +16,7 @@ def tesla_tester():
try:
p = Panda("WIFI")
except:
except Exception:
print("WiFi connection timed out. Please make sure your Panda is connected and try again.")
sys.exit(0)

View File

@ -30,10 +30,7 @@ def build_st(target, mkfile="Makefile", clean=True):
clean_cmd = "make -f %s clean" % mkfile if clean else ":"
cmd = 'cd %s && %s && make -f %s %s' % (os.path.join(BASEDIR, "board"), clean_cmd, mkfile, target)
try:
_ = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
except subprocess.CalledProcessError:
raise
_ = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
def parse_can_buffer(dat):
ret = []
@ -381,7 +378,6 @@ class Panda(object):
self._handle.controlWrite(Panda.REQUEST_OUT, 0xd1, 0, 0, b'')
except Exception as e:
print(e)
pass
def get_version(self):
return self._handle.controlRead(Panda.REQUEST_IN, 0xd6, 0, 0, 0x40).decode('utf8')

View File

@ -18,6 +18,7 @@
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
# Street, Fifth Floor, Boston, MA 02110-1301 USA.
# pylint: skip-file
# flake8: noqa
import argparse

View File

@ -308,7 +308,7 @@ class CanClient():
print("CAN-RX: drain - {}".format(len(msgs)))
self.rx_buff.clear()
else:
for rx_addr, rx_ts, rx_data, rx_bus in msgs or []:
for rx_addr, _, rx_data, rx_bus in msgs or []:
if self._recv_filter(rx_bus, rx_addr) and len(rx_data) > 0:
rx_data = bytes(rx_data) # convert bytearray to bytes

View File

@ -20,7 +20,7 @@ def can_printer():
start = sec_since_boot()
lp = sec_since_boot()
msgs = defaultdict(list)
canbus = int(os.getenv("CAN", 0))
canbus = int(os.getenv("CAN", "0"))
while True:
can_recv = p.can_recv()
for address, _, dat, src in can_recv:

View File

@ -14,7 +14,7 @@ unsetcolor = "\033[00m"
if __name__ == "__main__":
while True:
try:
port_number = int(os.getenv("PORT", 0))
port_number = int(os.getenv("PORT", "0"))
claim = os.getenv("CLAIM") is not None
serials = Panda.list()

View File

@ -25,7 +25,7 @@ REGISTER_ADDRESS_REGIONS = [
(0xE0000000, 0xE00FFFFF)
]
def hash(reg_addr):
def _hash(reg_addr):
return (((reg_addr >> 16) ^ ((((reg_addr + 1) & 0xFFFF) * HASHING_PRIME) & 0xFFFF)) & REGISTER_MAP_SIZE)
# Calculate hash for each address
@ -33,18 +33,18 @@ hashes = []
double_hashes = []
for (start_addr, stop_addr) in REGISTER_ADDRESS_REGIONS:
for addr in range(start_addr, stop_addr + 1, BYTES_PER_REG):
h = hash(addr)
h = _hash(addr)
hashes.append(h)
double_hashes.append(hash(h))
double_hashes.append(_hash(h))
# Make histograms
plt.subplot(2, 1, 1)
plt.hist(hashes, bins=REGISTER_MAP_SIZE)
plt.title("Number of collisions per hash")
plt.title("Number of collisions per _hash")
plt.xlabel("Address")
plt.subplot(2, 1, 2)
plt.hist(double_hashes, bins=REGISTER_MAP_SIZE)
plt.title("Number of collisions per double hash")
plt.title("Number of collisions per double _hash")
plt.xlabel("Address")
plt.show()

View File

@ -467,9 +467,9 @@ def test_elm_send_can_multimsg():
sim.join()
s.close()
"""The ability to correctly filter out messages with the wrong PID is not
implemented correctly in the reference device."""
def test_elm_can_check_mode_pid():
"""The ability to correctly filter out messages with the wrong PID is not
implemented correctly in the reference device."""
s = elm_connect()
serial = os.getenv("CANSIMSERIAL") if os.getenv("CANSIMSERIAL") else None
sim = elm_car_simulator.ELMCarSimulator(serial, lin=False)

View File

@ -7,27 +7,27 @@ DEBUG = False
if __name__ == "__main__":
p = Panda()
len = p._handle.controlRead(Panda.REQUEST_IN, 0x06, 3 << 8 | 238, 0, 1)
length = p._handle.controlRead(Panda.REQUEST_IN, 0x06, 3 << 8 | 238, 0, 1)
print('Microsoft OS String Descriptor')
dat = p._handle.controlRead(Panda.REQUEST_IN, 0x06, 3 << 8 | 238, 0, len[0])
dat = p._handle.controlRead(Panda.REQUEST_IN, 0x06, 3 << 8 | 238, 0, length[0])
if DEBUG:
print('LEN: {}'.format(hex(len[0])))
print('LEN: {}'.format(hex(length[0])))
hexdump("".join(map(chr, dat)))
ms_vendor_code = dat[16]
if DEBUG:
print('MS_VENDOR_CODE: {}'.format(hex(len[0])))
print('MS_VENDOR_CODE: {}'.format(hex(length[0])))
print('\nMicrosoft Compatible ID Feature Descriptor')
len = p._handle.controlRead(Panda.REQUEST_IN, ms_vendor_code, 0, 4, 1)
length = p._handle.controlRead(Panda.REQUEST_IN, ms_vendor_code, 0, 4, 1)
if DEBUG:
print('LEN: {}'.format(hex(len[0])))
dat = p._handle.controlRead(Panda.REQUEST_IN, ms_vendor_code, 0, 4, len[0])
print('LEN: {}'.format(hex(length[0])))
dat = p._handle.controlRead(Panda.REQUEST_IN, ms_vendor_code, 0, 4, length[0])
hexdump("".join(map(chr, dat)))
print('\nMicrosoft Extended Properties Feature Descriptor')
len = p._handle.controlRead(Panda.REQUEST_IN, ms_vendor_code, 0, 5, 1)
length = p._handle.controlRead(Panda.REQUEST_IN, ms_vendor_code, 0, 5, 1)
if DEBUG:
print('LEN: {}'.format(hex(len[0])))
dat = p._handle.controlRead(Panda.REQUEST_IN, ms_vendor_code, 0, 5, len[0])
print('LEN: {}'.format(hex(length[0])))
dat = p._handle.controlRead(Panda.REQUEST_IN, ms_vendor_code, 0, 5, length[0])
hexdump("".join(map(chr, dat)))

View File

@ -271,7 +271,7 @@ class PandaSafetyTest(PandaSafetyTestBase):
pass
@abc.abstractmethod
def _gas_msg(self, speed):
def _gas_msg(self, gas):
pass
@abc.abstractmethod

View File

@ -36,8 +36,8 @@ class TestChryslerSafety(common.PandaSafetyTest, common.TorqueSteeringSafetyTest
values = {"ACC_CANCEL": cancel}
return self.packer.make_can_msg_panda("WHEEL_BUTTONS", 0, values)
def _pcm_status_msg(self, active):
values = {"ACC_STATUS_2": 0x7 if active else 0,
def _pcm_status_msg(self, enable):
values = {"ACC_STATUS_2": 0x7 if enable else 0,
"COUNTER": self.cnt_cruise % 16}
self.__class__.cnt_cruise += 1
return self.packer.make_can_msg_panda("ACC_2", 0, values)

View File

@ -48,6 +48,9 @@ class TestGmSafety(common.PandaSafetyTest):
def test_cruise_engaged_prev(self):
pass
def _pcm_status_msg(self, enable):
raise NotImplementedError
def _speed_msg(self, speed):
values = {"%sWheelSpd" % s: speed for s in ["RL", "RR"]}
return self.packer.make_can_msg_panda("EBCMWheelSpdRear", 0, values)
@ -261,5 +264,6 @@ class TestGmSafety(common.PandaSafetyTest):
elif pedal == 'gas':
self._rx(self._gas_msg(0))
if __name__ == "__main__":
unittest.main()

View File

@ -44,6 +44,9 @@ class TestHondaSafety(common.PandaSafetyTest):
def test_cruise_engaged_prev(self):
pass
def _pcm_status_msg(self, enable):
pass
def _speed_msg(self, speed):
values = {"XMISSION_SPEED": speed, "COUNTER": self.cnt_speed % 4}
self.__class__.cnt_speed += 1
@ -70,7 +73,7 @@ class TestHondaSafety(common.PandaSafetyTest):
def _send_brake_msg(self, brake):
# must be implemented when inherited
raise NotImplementedError()
raise NotImplementedError
def test_resume_button(self):
self.safety.set_controls_allowed(0)
@ -178,7 +181,6 @@ class TestHondaSafety(common.PandaSafetyTest):
class TestHondaNidecSafety(TestHondaSafety, common.InterceptorSafetyTest):
TX_MSGS = [[0xE4, 0], [0x194, 0], [0x1FA, 0], [0x200, 0], [0x30C, 0], [0x33D, 0]]
STANDSTILL_THRESHOLD = 0
RELAY_MALFUNCTION_ADDR = 0xE4
@ -279,6 +281,9 @@ class TestHondaBoschSafety(TestHondaSafety):
self.__class__.cnt_brake += 1
return self.packer.make_can_msg_panda("BRAKE_MODULE", self.PT_BUS, values)
def _send_brake_msg(self, brake):
pass
# TODO: add back in once alternative brake checksum/counter validation is added
# def test_alt_brake_rx_hook(self):
# self.safety.set_honda_alt_brake_msg(1)
@ -288,7 +293,6 @@ class TestHondaBoschSafety(TestHondaSafety):
# to_push[0].RDLR = to_push[0].RDLR & 0xFFF0FFFF # invalidate checksum
# self.assertFalse(self._rx(to_push))
# self.assertFalse(self.safety.get_controls_allowed())
def test_alt_disengage_on_brake(self):
self.safety.set_honda_alt_brake_msg(1)
self.safety.set_controls_allowed(1)

View File

@ -56,8 +56,8 @@ class TestHyundaiSafety(common.PandaSafetyTest):
values = {"CF_Clu_CruiseSwState": buttons}
return self.packer.make_can_msg_panda("CLU11", 0, values)
def _gas_msg(self, val):
values = {"CF_Ems_AclAct": val, "AliveCounter": self.cnt_gas % 4}
def _gas_msg(self, gas):
values = {"CF_Ems_AclAct": gas, "AliveCounter": self.cnt_gas % 4}
self.__class__.cnt_gas += 1
return self.packer.make_can_msg_panda("EMS16", 0, values, fix_checksum=checksum)
@ -74,8 +74,8 @@ class TestHyundaiSafety(common.PandaSafetyTest):
self.__class__.cnt_speed += 1
return self.packer.make_can_msg_panda("WHL_SPD11", 0, values)
def _pcm_status_msg(self, enabled):
values = {"ACCMode": enabled, "CR_VSM_Alive": self.cnt_cruise % 16}
def _pcm_status_msg(self, enable):
values = {"ACCMode": enable, "CR_VSM_Alive": self.cnt_cruise % 16}
self.__class__.cnt_cruise += 1
return self.packer.make_can_msg_panda("SCC12", 0, values, fix_checksum=checksum)

View File

@ -45,20 +45,20 @@ class TestMazdaSafety(common.PandaSafetyTest):
values = {"LKAS_REQUEST": torque}
return self.packer.make_can_msg_panda("CAM_LKAS", 0, values)
def _speed_msg(self, s):
values = {"SPEED": s}
def _speed_msg(self, speed):
values = {"SPEED": speed}
return self.packer.make_can_msg_panda("ENGINE_DATA", 0, values)
def _brake_msg(self, pressed):
values = {"BRAKE_ON": pressed}
def _brake_msg(self, brake):
values = {"BRAKE_ON": brake}
return self.packer.make_can_msg_panda("PEDALS", 0, values)
def _gas_msg(self, pressed):
values = {"PEDAL_GAS": pressed}
def _gas_msg(self, gas):
values = {"PEDAL_GAS": gas}
return self.packer.make_can_msg_panda("ENGINE_DATA", 0, values)
def _pcm_status_msg(self, cruise_on):
values = {"CRZ_ACTIVE": cruise_on}
def _pcm_status_msg(self, enable):
values = {"CRZ_ACTIVE": enable}
return self.packer.make_can_msg_panda("CRZ_CTRL", 0, values)
def test_enable_control_allowed_from_cruise(self):

View File

@ -40,11 +40,11 @@ class TestNissanSafety(common.PandaSafetyTest):
self.safety.set_desired_angle_last(t)
def _angle_meas_msg_array(self, angle):
for i in range(6):
for _ in range(6):
self._rx(self._angle_meas_msg(angle))
def _pcm_status_msg(self, enabled):
values = {"CRUISE_ENABLED": enabled}
def _pcm_status_msg(self, enable):
values = {"CRUISE_ENABLED": enable}
return self.packer.make_can_msg_panda("CRUISE_STATE", 2, values)
def _lkas_control_msg(self, angle, state):

View File

@ -67,13 +67,13 @@ class TestSubaruSafety(common.PandaSafetyTest):
self.__class__.cnt_gas += 1
return self.packer.make_can_msg_panda("Throttle", 0, values)
def _pcm_status_msg(self, cruise):
values = {"Cruise_Activated": cruise, "Counter": self.cnt_cruise % 4}
def _pcm_status_msg(self, enable):
values = {"Cruise_Activated": enable, "Counter": self.cnt_cruise % 4}
self.__class__.cnt_cruise += 1
return self.packer.make_can_msg_panda("CruiseControl", 0, values)
def _set_torque_driver(self, min_t, max_t):
for i in range(0, 5):
for _ in range(0, 5):
self._rx(self._torque_driver_msg(min_t))
self._rx(self._torque_driver_msg(max_t))
@ -207,8 +207,8 @@ class TestSubaruLegacySafety(TestSubaruSafety):
values = {"Throttle_Pedal": gas}
return self.packer.make_can_msg_panda("Throttle", 0, values)
def _pcm_status_msg(self, cruise):
values = {"Cruise_Activated": cruise}
def _pcm_status_msg(self, enable):
values = {"Cruise_Activated": enable}
return self.packer.make_can_msg_panda("CruiseControl", 0, values)

View File

@ -52,21 +52,21 @@ class TestToyotaSafety(common.PandaSafetyTest, common.InterceptorSafetyTest,
values = {"ACCEL_CMD": accel}
return self.packer.make_can_msg_panda("ACC_CONTROL", 0, values)
def _speed_msg(self, s):
values = {("WHEEL_SPEED_%s" % n): s for n in ["FR", "FL", "RR", "RL"]}
def _speed_msg(self, speed):
values = {("WHEEL_SPEED_%s" % n): speed for n in ["FR", "FL", "RR", "RL"]}
return self.packer.make_can_msg_panda("WHEEL_SPEEDS", 0, values)
def _brake_msg(self, pressed):
values = {"BRAKE_PRESSED": pressed}
def _brake_msg(self, brake):
values = {"BRAKE_PRESSED": brake}
return self.packer.make_can_msg_panda("BRAKE_MODULE", 0, values)
def _gas_msg(self, pressed):
def _gas_msg(self, gas):
cruise_active = self.safety.get_controls_allowed()
values = {"GAS_RELEASED": not pressed, "CRUISE_ACTIVE": cruise_active}
values = {"GAS_RELEASED": not gas, "CRUISE_ACTIVE": cruise_active}
return self.packer.make_can_msg_panda("PCM_CRUISE", 0, values)
def _pcm_status_msg(self, cruise_on):
values = {"CRUISE_ACTIVE": cruise_on}
def _pcm_status_msg(self, enable):
values = {"CRUISE_ACTIVE": enable}
return self.packer.make_can_msg_panda("PCM_CRUISE", 0, values)
# Toyota gas gains are the same

View File

@ -77,8 +77,8 @@ class TestVolkswagenPqSafety(common.PandaSafetyTest):
return to_send
# ACC engaged status (shared message Motor_2)
def _pcm_status_msg(self, cruise):
self.__class__.cruise_engaged = cruise
def _pcm_status_msg(self, enable):
self.__class__.cruise_engaged = enable
return self._motor_2_msg()
# Driver steering input torque