test.test_timestamp_mixin   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 25
dl 0
loc 32
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A TimestampMixinTestBase.test_timestamp_metric_family_sets_timestamp_on_metrics_add_metric() 0 5 1
A TimestampMixinTestBase.test_timestamp_metric_family_sets_timestamp_on_metrics_implicit_metrics() 0 4 1
A TimestampMixinTestBase.test_timestamp_metric_family_has_none_timestamp_if_unset() 0 3 1
A TimestampMixinTestBase.test_timestamp_metric_family_has_timestamp_if_set() 0 4 1
A TimestampMixinTestBase.test_timestamp_metric_family_keeps_timestamp_from_add_metric() 0 5 1
1
from unittest import TestCase
2
3
from kibana_prometheus_exporter.helpers import TimestampGaugeMetricFamily
4
5
6
class TimestampMixinTestBase(TestCase):
7
    def test_timestamp_metric_family_has_timestamp_if_set(self):
8
        timestamp = 214
9
        t = TimestampGaugeMetricFamily("some_name", "some description", timestamp=timestamp)
10
        self.assertEqual(t._timestamp, timestamp)
11
12
    def test_timestamp_metric_family_has_none_timestamp_if_unset(self):
13
        t = TimestampGaugeMetricFamily("some_name", "some description")
14
        self.assertIsNone(t._timestamp)
15
16
    def test_timestamp_metric_family_sets_timestamp_on_metrics_implicit_metrics(self):
17
        timestamp = 214
18
        t = TimestampGaugeMetricFamily("some_name", "some description", timestamp=timestamp, value=2)
19
        self.assertEqual(t.samples[0].timestamp, timestamp)
20
21
    def test_timestamp_metric_family_sets_timestamp_on_metrics_add_metric(self):
22
        timestamp = 214
23
        t = TimestampGaugeMetricFamily("some_name", "some description", timestamp=timestamp)
24
        t.add_metric(labels=[], value=123)
25
        self.assertEqual(t.samples[0].timestamp, timestamp)
26
27
    def test_timestamp_metric_family_keeps_timestamp_from_add_metric(self):
28
        timestamp = 214
29
        t = TimestampGaugeMetricFamily("some_name", "some description", timestamp=timestamp)
30
        t.add_metric(labels=[], value=123, timestamp=234)
31
        self.assertEqual(t.samples[0].timestamp, 234)
32