def testDiagnosticStatusWrapper(self): stat = DiagnosticStatusWrapper() message = 'dummy' level = b'1' stat.summary(level, message) self.assertEqual(message, stat.message, 'DiagnosticStatusWrapper::summary failed\ to set message') self.assertEqual(level, stat.level, 'DiagnosticStatusWrapper::summary failed to set level') stat.add('toto', '%.1f' % 5.0) stat.add('baba', '5') stat.add('foo', '%05i' % 27) stat.add('bool', 'True') stat.add('bool2', 'False') self.assertEqual('5.0', stat.values[0].value, 'Bad value, adding a value with addf') self.assertEqual('5', stat.values[1].value, 'Bad value, adding a string with add') self.assertEqual('00027', stat.values[2].value, 'Bad value, adding a string with addf') self.assertEqual('toto', stat.values[0].key, 'Bad label, adding a value with add') self.assertEqual('baba', stat.values[1].key, 'Bad label, adding a string with add') self.assertEqual('foo', stat.values[2].key, 'Bad label, adding a string with addf') self.assertEqual('bool', stat.values[3].key, 'Bad label, adding a true bool key with add') self.assertEqual('True', stat.values[3].value, 'Bad value, adding a true bool with add') self.assertEqual('bool2', stat.values[4].key, 'Bad label, adding a false bool key\ with add') self.assertEqual('False', stat.values[4].value, 'Bad value, adding a false bool with add')
def d(stat: DiagnosticStatusWrapper) -> DiagnosticStatusWrapper: if self._motor_controller_state is None: stat.summary(DiagnosticStatus.STALE, "No more events recorded") return stat error_status = self._motor_controller_state.error_status[index] operational_state = self._motor_controller_state.operational_state[index] stat.add("Error status", error_status) stat.add("Operational state", operational_state) if error_status != "": stat.summary(DiagnosticStatus.ERROR, operational_state) else: stat.summary(DiagnosticStatus.OK, operational_state) return stat
def test_add(self): d = DiagnosticStatusWrapper() d.add('key', 'val') self.assertEqual(d.values[0].key, 'key') self.assertEqual(d.values[0].value, 'val')
def diagnostics(self, stat: DiagnosticStatusWrapper) -> DiagnosticStatusWrapper: """Create a diagnostic message to display in the standard stat format.""" if self._timestamp is None: stat.add("Topic error", "No events recorded") stat.summary(DiagnosticStatus.STALE, "No temperature recorded") return stat if (not LOWER_THRESHOLD_VALID_TEMPERATURE_VALUE < self._temperature < UPPER_THRESHOLD_VALID_TEMPERATURE_VALUE): stat.add("Current temperature", self._temperature) stat.summary( DiagnosticStatus.WARN, "No valid temperature value ({tp}).".format( tp=self._temperature), ) return stat stat.add("Default threshold", self._default_threshold) stat.add("Warning threshold", self._thresholds_warning) stat.add("Non fatal threshold", self._thresholds_non_fatal) stat.add("Fatal threshold", self._thresholds_fatal) stat.add("Current temperature", self._temperature) if self._default_threshold is None: stat.summary(DiagnosticStatus.WARN, "No thresholds found") elif self._temperature < self._thresholds_warning: stat.summary(DiagnosticStatus.OK, "OK ({tp}).".format(tp=self._temperature)) elif self._temperature < self._thresholds_non_fatal: stat.summary( DiagnosticStatus.WARN, "Temperature almost too high ({tp}).".format( tp=self._temperature), ) else: stat.summary( DiagnosticStatus.ERROR, "Temperature too high ({tp}).".format(tp=self._temperature), ) return stat