def test_counters(self): shelf = StatsShelf() self.assertEqual(dict(), shelf.counters()) shelf.add(Counter("mymetric", 3)) shelf.add(Counter("mymetric", 2)) shelf.add(Counter("something.else", 2, 0.5)) expected = {"mymetric": 5, "something.else": 4} self.assertEqual(expected, shelf.counters()) counters = shelf.counters() counters["counters should"] = "not changed" self.assertEqual(expected, shelf.counters())
def test_clear_all_metrics(self): shelf = StatsShelf() shelf.add(Set("users", "me")) shelf.add(Counter("mymetric", 3)) shelf.add(Timer("query", 4.12)) shelf.add(Gauge("cpu%", 38)) shelf.clear() self.assertEqual(dict(), shelf.counters()) self.assertEqual(dict(), shelf.sets()) self.assertEqual(dict(), shelf.timers_data()) self.assertEqual(dict(), shelf.gauges())