Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
deanlee committed Dec 12, 2024
1 parent a5216a5 commit d7400d5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion common/parameter_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions common/tests/test_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit d7400d5

Please sign in to comment.