mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 03:03:41 +08:00
Type the dynamically loaded bookmark test helper
Preserve existing assertions and explicitly narrow the optional checkpoint. Focused ty and Ruff checks and all 29 bookmark tests pass. Refresh receipt for test-only changes; production source and native artifacts remain unchanged.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import ast
|
||||
from collections.abc import Callable
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace as NS
|
||||
from typing import cast
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
@@ -15,9 +17,9 @@ source = Path(__file__).parents[1] / 'selfdrived.py'
|
||||
module = ast.parse(source.read_text())
|
||||
owner = next(node for node in module.body if isinstance(node, ast.ClassDef) and node.name == 'SelfdriveD')
|
||||
method = next(node for node in owner.body if isinstance(node, ast.FunctionDef) and node.name == '_update_bookmarks')
|
||||
namespace = {'messaging': messaging, 'EventName': EventName}
|
||||
namespace: dict[str, object] = {'messaging': messaging, 'EventName': EventName}
|
||||
exec(compile(ast.Module(body=[method], type_ignores=[]), str(source), 'exec'), namespace)
|
||||
update_bookmarks = namespace['_update_bookmarks']
|
||||
update_bookmarks = cast(Callable[[NS], None], namespace['_update_bookmarks'])
|
||||
|
||||
|
||||
class Sources(dict):
|
||||
@@ -117,7 +119,7 @@ def test_large_burst_is_bounded_without_discarding_remaining_bookmarks():
|
||||
|
||||
|
||||
class SavedCheckpoint:
|
||||
def __init__(self, value=None):
|
||||
def __init__(self, value: dict[str, object] | None = None):
|
||||
self.value = value
|
||||
self.writes = self.reads = self.removes = 0
|
||||
|
||||
@@ -168,6 +170,7 @@ def test_unseen_startup_device_state_does_not_erase_saved_count():
|
||||
sources.seen = {'deviceState': False}
|
||||
drive = NS(bookmarks=counter, sm=sources)
|
||||
update_bookmarks(drive)
|
||||
assert params.value is not None
|
||||
assert params.value['count'] == 4
|
||||
assert params.reads == params.writes == params.removes == 0
|
||||
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "cd4fa5f5def602d09c2d7fb638fbe3b4a600c7c735612d97623b5da6fb526176", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "3e5c60a01a1c91e2c04e025036427855ca11d783e40ac532dd0e6c144364e548", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user