fix a bunch of python warnings (#28576)

* fix a bunch of python warnings

* fix that
pull/28583/head
Adeeb Shihadeh 2 years ago committed by GitHub
parent 056bc05489
commit 111b4eee30
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      selfdrive/athena/tests/test_athenad.py
  2. 5
      selfdrive/controls/tests/test_alerts.py
  3. 5
      selfdrive/manager/process.py
  4. 9
      system/hardware/tici/hardware.py

@ -159,7 +159,7 @@ class TestAthenadMethods(unittest.TestCase):
resp = dispatcher["uploadFileToUrl"]("qlog.bz2", f"{host}/qlog.bz2", {}) resp = dispatcher["uploadFileToUrl"]("qlog.bz2", f"{host}/qlog.bz2", {})
self.assertEqual(resp['enqueued'], 1) self.assertEqual(resp['enqueued'], 1)
self.assertNotIn('failed', resp) self.assertNotIn('failed', resp)
self.assertDictContainsSubset({"path": fn, "url": f"{host}/qlog.bz2", "headers": {}}, resp['items'][0]) self.assertLessEqual({"path": fn, "url": f"{host}/qlog.bz2", "headers": {}}.items(), resp['items'][0].items())
self.assertIsNotNone(resp['items'][0].get('id')) self.assertIsNotNone(resp['items'][0].get('id'))
self.assertEqual(athenad.upload_queue.qsize(), 1) self.assertEqual(athenad.upload_queue.qsize(), 1)

@ -76,9 +76,10 @@ class TestAlerts(unittest.TestCase):
break break
font = fonts[alert.alert_size][i] font = fonts[alert.alert_size][i]
w, _ = draw.textsize(txt, font) left, _, right, _ = draw.textbbox((0, 0), txt, font)
width = right - left
msg = f"type: {alert.alert_type} msg: {txt}" msg = f"type: {alert.alert_type} msg: {txt}"
self.assertLessEqual(w, max_text_width, msg=msg) self.assertLessEqual(width, max_text_width, msg=msg)
def test_alert_sanity_check(self): def test_alert_sanity_check(self):
for event_types in EVENTS.values(): for event_types in EVENTS.values():

@ -100,8 +100,9 @@ class ManagerProcess(ABC):
try: try:
fn = WATCHDOG_FN + str(self.proc.pid) fn = WATCHDOG_FN + str(self.proc.pid)
# TODO: why can't pylint find struct.unpack? with open(fn, "rb") as f:
self.last_watchdog_time = struct.unpack('Q', open(fn, "rb").read())[0] # pylint: disable=no-member # TODO: why can't pylint find struct.unpack?
self.last_watchdog_time = struct.unpack('Q', f.read())[0] # pylint: disable=no-member
except Exception: except Exception:
pass pass

@ -106,8 +106,10 @@ class Tici(HardwareBase):
return model return model
def get_sound_card_online(self): def get_sound_card_online(self):
return (os.path.isfile('/proc/asound/card0/state') and if os.path.isfile('/proc/asound/card0/state'):
open('/proc/asound/card0/state').read().strip() == 'ONLINE') with open('/proc/asound/card0/state') as f:
return f.read().strip() == 'ONLINE'
return False
def reboot(self, reason=None): def reboot(self, reason=None):
subprocess.check_output(["sudo", "reboot"]) subprocess.check_output(["sudo", "reboot"])
@ -452,7 +454,8 @@ class Tici(HardwareBase):
def get_gpu_usage_percent(self): def get_gpu_usage_percent(self):
try: try:
used, total = open('/sys/class/kgsl/kgsl-3d0/gpubusy').read().strip().split() with open('/sys/class/kgsl/kgsl-3d0/gpubusy') as f:
used, total = f.read().strip().split()
return 100.0 * int(used) / int(total) return 100.0 * int(used) / int(total)
except Exception: except Exception:
return 0 return 0

Loading…
Cancel
Save