diff --git a/selfdrive/athena/tests/test_athenad.py b/selfdrive/athena/tests/test_athenad.py index 5fda4d97f9..f32df74217 100755 --- a/selfdrive/athena/tests/test_athenad.py +++ b/selfdrive/athena/tests/test_athenad.py @@ -351,7 +351,7 @@ class TestAthenadMethods(unittest.TestCase): self.assertEqual(athenad.upload_queue.qsize(), 1) self.assertDictEqual(asdict(athenad.upload_queue.queue[-1]), asdict(item1)) - @mock.patch('selfdrive.athena.athenad.create_connection') + @mock.patch('openpilot.selfdrive.athena.athenad.create_connection') def test_startLocalProxy(self, mock_create_connection): end_event = threading.Event() diff --git a/selfdrive/athena/tests/test_registration.py b/selfdrive/athena/tests/test_registration.py index d2c1ab95f9..195fca2df9 100755 --- a/selfdrive/athena/tests/test_registration.py +++ b/selfdrive/athena/tests/test_registration.py @@ -23,7 +23,7 @@ class TestRegistration(unittest.TestCase): os.mkdir(os.path.join(self.persist.name, "comma")) self.priv_key = Path(os.path.join(self.persist.name, "comma/id_rsa")) self.pub_key = Path(os.path.join(self.persist.name, "comma/id_rsa.pub")) - self.persist_patcher = mock.patch("selfdrive.athena.registration.PERSIST", self.persist.name) + self.persist_patcher = mock.patch("openpilot.selfdrive.athena.registration.PERSIST", self.persist.name) self.persist_patcher.start() def tearDown(self): @@ -44,7 +44,7 @@ class TestRegistration(unittest.TestCase): self.params.put("HardwareSerial", "serial") self._generate_keys() - with mock.patch("selfdrive.athena.registration.api_get", autospec=True) as m: + with mock.patch("openpilot.selfdrive.athena.registration.api_get", autospec=True) as m: dongle = "DONGLE_ID_123" self.params.put("DongleId", dongle) self.assertEqual(register(), dongle) @@ -52,7 +52,7 @@ class TestRegistration(unittest.TestCase): def test_no_keys(self): # missing pubkey - with mock.patch("selfdrive.athena.registration.api_get", autospec=True) as m: + with mock.patch("openpilot.selfdrive.athena.registration.api_get", autospec=True) as m: dongle = register() self.assertEqual(m.call_count, 0) self.assertEqual(dongle, UNREGISTERED_DONGLE_ID) @@ -61,7 +61,7 @@ class TestRegistration(unittest.TestCase): def test_missing_cache(self): # keys exist but no dongle id self._generate_keys() - with mock.patch("selfdrive.athena.registration.api_get", autospec=True) as m: + with mock.patch("openpilot.selfdrive.athena.registration.api_get", autospec=True) as m: dongle = "DONGLE_ID_123" m.return_value = MockResponse(json.dumps({'dongle_id': dongle}), 200) self.assertEqual(register(), dongle) @@ -75,7 +75,7 @@ class TestRegistration(unittest.TestCase): def test_unregistered(self): # keys exist, but unregistered self._generate_keys() - with mock.patch("selfdrive.athena.registration.api_get", autospec=True) as m: + with mock.patch("openpilot.selfdrive.athena.registration.api_get", autospec=True) as m: m.return_value = MockResponse(None, 402) dongle = register() self.assertEqual(m.call_count, 1) diff --git a/selfdrive/thermald/tests/test_power_monitoring.py b/selfdrive/thermald/tests/test_power_monitoring.py index 862d58d9c9..62cde91034 100755 --- a/selfdrive/thermald/tests/test_power_monitoring.py +++ b/selfdrive/thermald/tests/test_power_monitoring.py @@ -3,34 +3,33 @@ import unittest from unittest.mock import patch from openpilot.common.params import Params -params = Params() +from openpilot.selfdrive.thermald.power_monitoring import PowerMonitoring, CAR_BATTERY_CAPACITY_uWh, \ + CAR_CHARGING_RATE_W, VBATT_PAUSE_CHARGING, DELAY_SHUTDOWN_TIME_S + # Create fake time -ssb = 0 +ssb = 0. def mock_time_monotonic(): global ssb - ssb += 1 + ssb += 1. return ssb -with patch("time.monotonic", new=mock_time_monotonic): - with patch("common.params.put_nonblocking", new=params.put): - from openpilot.selfdrive.thermald.power_monitoring import PowerMonitoring, CAR_BATTERY_CAPACITY_uWh, \ - CAR_CHARGING_RATE_W, VBATT_PAUSE_CHARGING, DELAY_SHUTDOWN_TIME_S - TEST_DURATION_S = 50 GOOD_VOLTAGE = 12 * 1e3 VOLTAGE_BELOW_PAUSE_CHARGING = (VBATT_PAUSE_CHARGING - 1) * 1e3 def pm_patch(name, value, constant=False): if constant: - return patch(f"selfdrive.thermald.power_monitoring.{name}", value) - return patch(f"selfdrive.thermald.power_monitoring.{name}", return_value=value) + return patch(f"openpilot.selfdrive.thermald.power_monitoring.{name}", value) + return patch(f"openpilot.selfdrive.thermald.power_monitoring.{name}", return_value=value) +@patch("time.monotonic", new=mock_time_monotonic) +@patch("openpilot.common.params.put_nonblocking", new=lambda x, y: Params().put(x, y)) class TestPowerMonitoring(unittest.TestCase): def setUp(self): - # Clear stored capacity before each test - params.remove("CarBatteryCapacity") - params.remove("DisablePowerDown") + self.params = Params() + self.params.remove("CarBatteryCapacity") + self.params.remove("DisablePowerDown") # Test to see that it doesn't do anything when pandaState is None def test_pandaState_present(self): @@ -139,7 +138,7 @@ class TestPowerMonitoring(unittest.TestCase): def test_disable_power_down(self): POWER_DRAW = 0 # To stop shutting down for other reasons TEST_TIME = 100 - params.put_bool("DisablePowerDown", True) + self.params.put_bool("DisablePowerDown", True) with pm_patch("HARDWARE.get_current_power_draw", POWER_DRAW): pm = PowerMonitoring() pm.car_battery_capacity_uWh = CAR_BATTERY_CAPACITY_uWh