From d7400d589f5f7a0871c9f6b4e579382a321da3fd Mon Sep 17 00:00:00 2001 From: deanlee Date: Mon, 9 Dec 2024 12:36:02 +0800 Subject: [PATCH] add test case --- common/parameter_updater.py | 2 +- common/tests/test_params.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/common/parameter_updater.py b/common/parameter_updater.py index d3c37d46cdd17b..927522ebbc73d5 100644 --- a/common/parameter_updater.py +++ b/common/parameter_updater.py @@ -22,7 +22,7 @@ def get(self, param: str) -> str | None: return self.param_values[param] def get_bool(self, param: str) -> bool: - return self.get(param) == '1' + return self.get(param) == b'1' def get_int(self, param: str, def_val: int = 0) -> int: value = self.get(param) diff --git a/common/tests/test_params.py b/common/tests/test_params.py index 16cbc45295d527..5b5bccfe43c517 100644 --- a/common/tests/test_params.py +++ b/common/tests/test_params.py @@ -5,6 +5,7 @@ import uuid from openpilot.common.params import Params, ParamKeyType, UnknownKeyName +from openpilot.common.parameter_updater import ParameterUpdater class TestParams: def setup_method(self): @@ -100,6 +101,18 @@ def _delayed_writer(): assert q.get("CarParams") is None assert q.get("CarParams", True) == b"1" + def test_parameter_updater(self): + parameter_updater = ParameterUpdater(["DongleId", "CarParams", "IsMetric"]) + parameter_updater.start() + Params().put("DongleId", "cb38263377b873ee") + Params().put("CarParams", "123") + Params().put_bool("IsMetric", True) + time.sleep(0.2) + assert parameter_updater.get("DongleId") == b'cb38263377b873ee' + assert parameter_updater.get_bool("IsMetric") is True + assert parameter_updater.get_int("CarParams") == 123 + parameter_updater.stop() + def test_params_all_keys(self): keys = Params().all_keys()