Exemplo n.º 1
0
    def test_patch_function(self):

        record_calls = []
        def target(n):
            sleep(n) # sorry, need to sleep a little to get measurable execution time
            record_calls.append(1)

        target(0.05) # should not include totals from before patching
        t = MonkeyTimer()
        subject = t.patch_function(target, "target")

        was_called = False
        subject(0.1)

        self.assertAlmostEqual(0.1, t._clock_time["target"], delta=0.01)
        self.assertEqual(1, t._total_count["target"])
        self.assertEqual(2, len(record_calls))