@@ -321,6 +321,16 @@ def collect(self):
321
321
return [metric_family ]
322
322
self .registry .register (CustomCollector ())
323
323
324
+ def test_untyped (self ):
325
+ self .custom_collector (UntypedMetricFamily ('u' , 'help' , value = 1 ))
326
+ self .assertEqual (1 , self .registry .get_sample_value ('u' , {}))
327
+
328
+ def test_untyped_labels (self ):
329
+ cmf = UntypedMetricFamily ('u' , 'help' , labels = ['a' , 'c' ])
330
+ cmf .add_metric (['b' , 'd' ], 2 )
331
+ self .custom_collector (cmf )
332
+ self .assertEqual (2 , self .registry .get_sample_value ('u' , {'a' : 'b' , 'c' : 'd' }))
333
+
324
334
def test_counter (self ):
325
335
self .custom_collector (CounterMetricFamily ('c' , 'help' , value = 1 ))
326
336
self .assertEqual (1 , self .registry .get_sample_value ('c' , {}))
@@ -370,6 +380,9 @@ def test_histogram_labels(self):
370
380
self .assertEqual (3 , self .registry .get_sample_value ('h_sum' , {'a' : 'b' }))
371
381
372
382
def test_bad_constructors (self ):
383
+ self .assertRaises (ValueError , UntypedMetricFamily , 'u' , 'help' , value = 1 , labels = [])
384
+ self .assertRaises (ValueError , UntypedMetricFamily , 'u' , 'help' , value = 1 , labels = ['a' ])
385
+
373
386
self .assertRaises (ValueError , CounterMetricFamily , 'c' , 'help' , value = 1 , labels = [])
374
387
self .assertRaises (ValueError , CounterMetricFamily , 'c' , 'help' , value = 1 , labels = ['a' ])
375
388
@@ -390,6 +403,8 @@ def test_bad_constructors(self):
390
403
self .assertRaises (KeyError , HistogramMetricFamily , 'h' , 'help' , buckets = {}, sum_value = 1 )
391
404
392
405
def test_labelnames (self ):
406
+ cmf = UntypedMetricFamily ('u' , 'help' , labels = iter (['a' ]))
407
+ self .assertEqual (('a' ,), cmf ._labelnames )
393
408
cmf = CounterMetricFamily ('c' , 'help' , labels = iter (['a' ]))
394
409
self .assertEqual (('a' ,), cmf ._labelnames )
395
410
gmf = GaugeMetricFamily ('g' , 'help' , labels = iter (['a' ]))
0 commit comments