From c65675a64d453e28336230ac3bccad902b1133f3 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Fri, 20 Oct 2023 07:30:16 +1100 Subject: [PATCH] autotest: add an epsilon kwarg for assert_parameter_values ... and reimplement assert_parameter_vaue in terms of that function --- Tools/autotest/common.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Tools/autotest/common.py b/Tools/autotest/common.py index 99685094031b2..14d6142fccfea 100644 --- a/Tools/autotest/common.py +++ b/Tools/autotest/common.py @@ -3810,21 +3810,23 @@ def log_list(self): self.progress("log list: %s" % str(ret)) return ret - def assert_parameter_values(self, parameters): + def assert_parameter_values(self, parameters, epsilon=None): names = parameters.keys() got = self.get_parameters(names) for name in names: - if got[name] != parameters[name]: + equal = got[name] == parameters[name] + if epsilon is not None: + delta = abs(got[name] - parameters[name]) + equal = delta <= epsilon + if not equal: raise NotAchievedException("parameter %s want=%f got=%f" % (name, parameters[name], got[name])) self.progress("%s has expected value %f" % (name, got[name])) - def assert_parameter_value(self, parameter, required): - got = self.get_parameter(parameter) - if got != required: - raise NotAchievedException("%s has unexpected value; want=%f got=%f" % - (parameter, required, got)) - self.progress("%s has value %f" % (parameter, required)) + def assert_parameter_value(self, parameter, required, **kwargs): + self.assert_parameter_values({ + parameter: required, + }, **kwargs) def assert_reach_imu_temperature(self, target, timeout): '''wait to reach a target temperature'''