mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-06 12:33:51 +08:00
Fix typed lane centering default enrollment
This commit is contained in:
Executable → Regular
+1
-1
@@ -75,7 +75,7 @@ def manager_init() -> None:
|
||||
for k in params.all_keys():
|
||||
if k == b"LKASButtonControl":
|
||||
continue # Card enrolls the vehicle-specific default after identification.
|
||||
default_value = ("0" if os.path.lexists(params.get_param_path("Version")) else "1") if k == b"LaneCentering" else params.get_default_value(k)
|
||||
default_value = not os.path.lexists(params.get_param_path("Version")) if k == b"LaneCentering" else params.get_default_value(k)
|
||||
if default_value is not None and not os.path.lexists(params.get_param_path(k)):
|
||||
params.put(k, default_value, block=True)
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import ast
|
||||
import os
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
from openpilot.common.params import Params
|
||||
|
||||
|
||||
class TestLaneCenteringDefaults(unittest.TestCase):
|
||||
def test_typed_enrollment_preserves_existing_choices(self):
|
||||
source = Path(__file__).resolve().parents[1] / "manager.py"
|
||||
tree = ast.parse(source.read_text())
|
||||
loop = next(node for node in ast.walk(tree) if isinstance(node, ast.For) and
|
||||
ast.unparse(node.iter) == "params.all_keys()")
|
||||
code = compile(ast.fix_missing_locations(ast.Module(body=[loop], type_ignores=[])), str(source), "exec")
|
||||
for upgrade in (False, True):
|
||||
for saved in (None, b"0", b"1", b"malformed"):
|
||||
with self.subTest(upgrade=upgrade, saved=saved), tempfile.TemporaryDirectory() as root:
|
||||
params = Params(root)
|
||||
if upgrade:
|
||||
params.put("Version", "7.0", block=True)
|
||||
path = Path(params.get_param_path("LaneCentering"))
|
||||
if saved is not None:
|
||||
path.write_bytes(saved)
|
||||
exec(code, {"params": params, "os": os})
|
||||
self.assertEqual(path.read_bytes(), saved if saved is not None else b"0" if upgrade else b"1")
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "a2fbb60c55f751914d8c6933c6228f20ae1ba345b67abd78f1f0a1c503079eb7", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "a053ca5439f8e3928ec0c30fcaef86234d9e1891ccaa2a1c46098d121ef72a67", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user