Passed
Push — master ( f9598b...4c4a55 )
by Vlad
01:28
created

test.test_timestamp_mixim   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 26
dl 0
loc 34
rs 10
c 0
b 0
f 0

5 Methods

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