Beispiel #1
0
    def test_log_metric_value_raises_exception_not_number_or_string_different_value(
            self):
        expected_error_message = 'Invalid metric with key="loss" of value={\'a\': 22} with type <class \'dict\'>. ' \
                                 'Value should be of type string or number, or a list of strings / numbers'

        with self.assertRaises(TypeError) as metric:
            log_metric('loss', {"a": 22})
        self.assertEqual(str(metric.exception), expected_error_message)
Beispiel #2
0
    def test_log_metric_value_raises_exception_not_number_or_string_with_different_key(
            self):
        expected_error_message = 'Invalid metric with key="gain" of value=[[2]] with type <class \'list\'>. ' \
                                 'Value should be of type string or number, or a list of strings / numbers'

        with self.assertRaises(TypeError) as metric:
            log_metric('gain', [[2]])
        self.assertEqual(str(metric.exception), expected_error_message)
Beispiel #3
0
    def test_log_metric_with_invalid_list(self):
        expected_error_message = 'Invalid metric with key="bloop" of value=[<class \'Exception\'>] with type ' \
                                 '<class \'list\'>. Value should be of type string or number, or a list of ' \
                                 'strings / numbers'

        with self.assertRaises(TypeError) as metric:
            log_metric('bloop', [Exception])
        self.assertEqual(str(metric.exception), expected_error_message)
Beispiel #4
0
    def test_log_metric_value_raises_exception_cut_down_to_thirty_chars(self):
        metric_value = [[1] * 50]

        expected_error_message = 'Invalid metric with key="loss" of value=[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ... with type ' \
                                 '<class \'list\'>. Value should be of type string or number, or a list of ' \
                                 'strings / numbers'

        with self.assertRaises(TypeError) as metric:
            log_metric('loss', metric_value)
        self.assertEqual(str(metric.exception), expected_error_message)
Beispiel #5
0
    def test_log_metric_value_raises_exception_not_number_or_string_custom_class_using_default_repr(
            self):
        class MyCoolClass(object):
            def __init__(self):
                pass

        metric_value = MyCoolClass()
        representation = str(metric_value)[:30] + " ..."
        expected_error_message_format = 'Invalid metric with key="loss" of value={} with type {}. Value should be of ' \
                                        'type string or number, or a list of strings / numbers'
        expected_error_message = expected_error_message_format.format(
            representation, type(metric_value))

        with self.assertRaises(TypeError) as metric:
            log_metric('loss', metric_value)
        self.assertEqual(str(metric.exception), expected_error_message)
Beispiel #6
0
    def test_log_metric_logs_key_invalid_key_type_different_key(self):
        with self.assertRaises(ValueError) as error_context:
            log_metric(5.44, 0.554)

        self.assertIn('Invalid metric name `5.44`',
                      error_context.exception.args)
Beispiel #7
0
 def _run_job_and_log_two_metrics(self):
     self._set_job_running()
     log_metric(self.fake_metric_name, self.fake_metric_value)
     log_metric(self.fake_metric_name_2, self.fake_metric_value_2)
Beispiel #8
0
 def _run_job_and_log_metric(self, metric_name, metric_value):
     self._set_job_running()
     log_metric(metric_name, metric_value)