diff --git a/openpilot/starpilot/galaxy/test_android_auto_http.py b/openpilot/starpilot/galaxy/test_android_auto_http.py index c210a4ffa1..4cae3c4bbc 100644 --- a/openpilot/starpilot/galaxy/test_android_auto_http.py +++ b/openpilot/starpilot/galaxy/test_android_auto_http.py @@ -28,6 +28,7 @@ class ApiState(TypedDict): install_ready: bool enable_events: list[str] bluetooth_failure: NotRequired[str] + setup_owner: NotRequired[AndroidAutoSetup] class FakeImport: diff --git a/openpilot/starpilot/navigation/tests/test_route_runtime.py b/openpilot/starpilot/navigation/tests/test_route_runtime.py index 1e4898fcae..db4edb34a7 100644 --- a/openpilot/starpilot/navigation/tests/test_route_runtime.py +++ b/openpilot/starpilot/navigation/tests/test_route_runtime.py @@ -38,8 +38,10 @@ class Executor: def configured(tmp_path): - owner = NavigationOwner(tmp_path, runtime_source=lambda: None) - owner._is_metric = lambda: True + class MetricNavigationOwner(NavigationOwner): + def _is_metric(self) -> bool: + return True + owner = MetricNavigationOwner(tmp_path, runtime_source=lambda: None) settings = owner.configure({'enabled': True, 'token': 'pk.test'}, '0', True) owner.select({'name': 'Destination', 'longitude': .01, 'latitude': 0.}, settings['revision'], True) return owner diff --git a/openpilot/starpilot/system/android_auto/tests/test_apkpure.py b/openpilot/starpilot/system/android_auto/tests/test_apkpure.py index 0bd004c0bb..67a67255ab 100644 --- a/openpilot/starpilot/system/android_auto/tests/test_apkpure.py +++ b/openpilot/starpilot/system/android_auto/tests/test_apkpure.py @@ -85,7 +85,9 @@ def test_fetch_skips_links_about_to_expire(monkeypatch): body = response(release(expires=soon), release("17.6.663454-release", 176663454)) opener = fake_open(body) monkeypatch.setattr(apkpure.urllib.request, "build_opener", lambda *handlers: opener) - assert apkpure.fetch_latest(now=NOW)["version"] == "17.6.663454-release" + latest = apkpure.fetch_latest(now=NOW) + assert latest is not None + assert latest["version"] == "17.6.663454-release" request = opener.open.call_args.args[0] assert request.full_url == apkpure.API_URL and request.get_header("X-sv") == "29" assert request.get_header("User-agent") == "StarPilot-AndroidAuto/1" diff --git a/openpilot/starpilot/system/android_auto/tests/test_projection_layout_runtime.py b/openpilot/starpilot/system/android_auto/tests/test_projection_layout_runtime.py index ce5b876fcf..a4b8b38de0 100644 --- a/openpilot/starpilot/system/android_auto/tests/test_projection_layout_runtime.py +++ b/openpilot/starpilot/system/android_auto/tests/test_projection_layout_runtime.py @@ -112,7 +112,8 @@ class TestProjectionLayoutRuntime(unittest.TestCase): source.path.write_bytes(b'x' * 16385) # unreadable: keep the current layout and retry self.assertIsNone(watcher.poll()) self.assertIsNone(watcher.poll()) - source.path.write_text(json.dumps(original)) + temporary.write_text(json.dumps(original)) + os.replace(temporary, source.path) # Galaxy saves by atomic replace self.assertEqual(watcher.poll(), original) source.path.unlink() self.assertEqual(watcher.poll(), default_layout_for_viewport(viewport)) @@ -134,8 +135,8 @@ class TestProjectionLayoutRuntime(unittest.TestCase): return poll() finally: polled.set() - watcher.poll = observed_poll - with patch('openpilot.starpilot.system.android_auto.projection_layout_runtime.CHECK_SECONDS', 0.01): + with patch.object(watcher, 'poll', observed_poll), \ + patch('openpilot.starpilot.system.android_auto.projection_layout_runtime.CHECK_SECONDS', 0.01): watcher.start() try: changed = copy.deepcopy(original) diff --git a/openpilot/starpilot/tests/test_external_preferences_reset.py b/openpilot/starpilot/tests/test_external_preferences_reset.py index ac3cf9ef22..c1d6553a69 100644 --- a/openpilot/starpilot/tests/test_external_preferences_reset.py +++ b/openpilot/starpilot/tests/test_external_preferences_reset.py @@ -27,6 +27,8 @@ migration = load('external_reset_state_helpers', ROOT / 'state_migration.py') owner_ast = ast.parse((ROOT / 'navigation' / 'owner.py').read_text()) selected: list[ast.stmt] = [node for node in owner_ast.body if isinstance(node, (ast.FunctionDef, ast.ClassDef)) and node.name in ('ValidationError', 'destination', 'favorite_place')] +selected.extend(node for node in owner_ast.body if isinstance(node, ast.Assign) + and any(isinstance(target, ast.Name) and target.id == 'ROUTE_AVOIDANCES' for target in node.targets)) owner_class = next(node for node in owner_ast.body if isinstance(node, ast.ClassDef) and node.name == 'NavigationOwner') selected.append(next(node for node in owner_class.body if isinstance(node, ast.FunctionDef) and node.name == 'read')) namespace: dict = {'json': json, 'math': math, 'hashlib': hashlib, 'os': os, 'copy': copy, 'MAX_DOCUMENT': 256 * 1024, diff --git a/openpilot/starpilot/ui/tests/test_onroad_customization.py b/openpilot/starpilot/ui/tests/test_onroad_customization.py index 3e4a16465e..a2cf63ba4b 100644 --- a/openpilot/starpilot/ui/tests/test_onroad_customization.py +++ b/openpilot/starpilot/ui/tests/test_onroad_customization.py @@ -747,7 +747,7 @@ def test_stopped_timer_draws_inside_its_moved_widget(): view.fonts = Mock(spec=BitmapFonts) view.fonts.profile = Profile.COMPACT view.fonts.measure.return_value = NS(width=100, height=20) - state = NS(customization=document) + state = road(document) view._stopped_timer(state, 75) view.fonts.draw.assert_not_called() document["layouts"]["compact"][STOPPED_TIMER_WIDGET]["enabled"] = True @@ -770,11 +770,11 @@ def test_projection_timer_renders_at_saved_coordinates_without_native_timer_enab view.fonts = Mock(spec=BitmapFonts) view.fonts.profile = Profile.LARGE view.fonts.measure.return_value = NS(width=100, height=20) - view._stopped_timer(NS(customization=document), 134) + view._stopped_timer(road(document), 134) text_calls = view.fonts.draw.call_args_list[1::2] assert [call.args[0] for call in text_calls] == ['2 minutes', '14 seconds'] assert [call.args[3:5] for call in text_calls] == [(730, 669.5), (730, 741.5)] view.fonts.draw.reset_mock() document['layouts']['large'][STOPPED_TIMER_WIDGET]['enabled'] = False - view._stopped_timer(NS(customization=document), 134) + view._stopped_timer(road(document), 134) view.fonts.draw.assert_not_called()