def test_timing_reset(self): x = 0 with stats.time("hundred"): for i in xrange(100): x += i self.assertEqual(1, stats.get_timing_stats(reset=False)["hundred"].count) with stats.time("hundred"): for i in xrange(100): x += i self.assertEqual(2, stats.get_timing_stats(reset=False)["hundred"].count) self.assertEqual(2, stats.get_timing_stats(reset=True)["hundred"].count) with stats.time("hundred"): for i in xrange(100): x += i self.assertEqual(1, stats.get_timing_stats(reset=False)["hundred"].count)
def test_timings_report(self): x = 0 with stats.time("hundred"): for i in xrange(100): x += i timings = stats.get_timing_stats() self.assertEquals(["hundred"], timings.keys()) self.assertEquals(1, timings["hundred"].count) self.assertEquals(timings["hundred"].average, timings["hundred"].min) self.assertEquals(timings["hundred"].average, timings["hundred"].max)
def test_timing_add(self): x = 0 with stats.time("hundred"): for i in xrange(100): x += 1 self.assertEquals(1, len(stats.get_timing_stats(reset=False))) stats.add_timing("foobar", timing.TimingStat(1, 0, 0)) self.assertEquals(2, len(stats.get_timing_stats(reset=False))) self.assertEquals(1, stats.get_timing_stats(reset=True)["foobar"].count) stats.add_timing("foobar", timing.TimingStat(3, 0, 0)) self.assertEquals(3, stats.get_timing_stats(reset=False)["foobar"].count)
def test_timing_with(self): with stats.time("test"): time.sleep(0.01) test = stats.get_timing("test") self.assertTrue(test.get().average >= 10)