def test_inc_with_labels_in_different_order_increase_same_counter( self, counter: instrumentor.Counter): counter.inc(3, labels={"code": "200", "path": "/api"}) counter.inc(3, labels={"path": "/api", "code": "200"}) assert counter.counts['code="200",path="/api"'] == 6
def test_register_counter(self, registry: CollectorRegistry): counter = Counter(name="http_requests_total", description="Total HTTP Requests") registry.register(counter) assert registry.metrics[counter.name] == counter assert registry.metrics[counter.name].registry == registry
def test_eager(self, registry: CollectorRegistry, redis: StrictRedis): counter = Counter(name="http_requests_total", description="Total HTTP Requests") registry.eager = True registry.register(counter) assert registry.eager counter.inc() assert redis.hgetall("testing") != {}
def test_reset(self, counter: instrumentor.Counter): counter.inc() counter.inc(3, labels={"code": "200", "path": "/api"}) counter.inc(3, labels={"path": "/api", "code": "200"}) assert counter.counts != {"__": 0} counter.reset() assert counter.counts == {"__": 0}
def test_unregister_counter(self, registry: CollectorRegistry): counter = Counter(name="http_requests_total", description="Total HTTP Requests") registry.register(counter) assert registry.metrics[counter.name] == counter assert registry.metrics[counter.name].registry == registry registry.unregister(counter) with pytest.raises(KeyError): x = registry.metrics[counter.name] assert counter.registry is None
def test_using_reserved_labels_raises_value_error( self, counter: instrumentor.Counter): with pytest.raises(ValueError): counter.inc(3, labels={"le": "200"})
def test_inc_by_negative_raises_value_error(self, counter: instrumentor.Counter): with pytest.raises(ValueError): counter.inc(-1)
def test_inc_by_1(self, counter: instrumentor.Counter): counter.inc() assert counter.counts["__"] == 1
def test_inc_with_labels(self, counter: instrumentor.Counter): counter.inc(3, labels={"code": "200", "path": "/api"}) assert counter.counts['code="200",path="/api"'] == 3
def test_inc_by_float(self, counter: instrumentor.Counter): counter.inc(3.5) assert counter.counts["__"] == 3.5