コード例 #1
0
 def test_record_multiple(self):
     t = Timer(TimerTest.tid)
     t.record(42)
     t.record(2)
     t.record(7)
     self.assertEqual(t.count(), 3)
     self.assertEqual(t.total_time(), 51)
コード例 #2
0
    def test_count_and_total_time(self):
        """Avoid breaking the API."""
        t = Timer(self.tid, writer=MemoryWriter())
        self.assertTrue(t._writer.is_empty())

        t.record(42)
        self.assertEqual(0, t.count())
        self.assertEqual(0, t.total_time())
コード例 #3
0
    def test_measure(self):
        t = Timer(TimerTest.tid)
        t.record(42)
        t.record(2)
        t.record(7)
        ms = t._measure()

        def get_stat(s):
            return ms[TimerTest.tid.with_stat(s)]

        self.assertEqual(len(ms), 4)
        self.assertEqual(get_stat('count'), 3)
        self.assertEqual(get_stat('totalTime'), 51)
        self.assertEqual(get_stat('max'), 42)
        self.assertEqual(get_stat('totalOfSquares'), 42**2 + 2**2 + 7**2)

        self.assertEqual(t.count(), 0)
        self.assertEqual(t.total_time(), 0)
コード例 #4
0
 def test_record_zero(self):
     t = Timer(self.tid, meter_type="T", writer=MemoryWriter())
     t.record(0)
     self.assertEqual("T:test:0", t._writer.last_line())
コード例 #5
0
 def test_record_negative(self):
     t = Timer(self.tid, meter_type="T", writer=MemoryWriter())
     t.record(-42)
     self.assertTrue(t._writer.is_empty())
コード例 #6
0
    def test_record(self):
        t = Timer(self.tid, meter_type="T", writer=MemoryWriter())
        self.assertTrue(t._writer.is_empty())

        t.record(42)
        self.assertEqual("T:test:42", t._writer.last_line())
コード例 #7
0
 def test_record(self):
     t = Timer(TimerTest.tid)
     t.record(42)
     self.assertEqual(t.count(), 1)
     self.assertEqual(t.total_time(), 42)
コード例 #8
0
 def test_record_negative(self):
     t = Timer(TimerTest.tid)
     t.record(-42)
     self.assertEqual(t.count(), 0)
     self.assertEqual(t.total_time(), 0)