def test_on_instance_method__no_args(self): counter = Counter() method = counter.count self.assertEquals(method(), 1) self.assertEquals(method(), 1) clear_cached_entry(method) self.assertEquals(method(), 2)
def test_clear_cached_entry_with_mismatching_args_does_nothing(self): counter = Counter() method = counter.sum self.assertEquals(method(1), 1) counter.count() self.assertEquals(method(1), 1) clear_cached_entry(method, 3) self.assertEquals(method(1), 1)
def test_on_instance_method__with_args(self): counter = Counter() method = counter.sum self.assertEquals(method(1), 1) counter.count() self.assertEquals(method(1), 1) clear_cached_entry(method, 1) self.assertEquals(method(1), 2)
def test_on_function__with_args(self): count = 0 @cached_function def sum(num): return num + count self.assertEquals(sum(1), 1) self.assertEquals(sum(1), 1) count = 2 self.assertEquals(sum(1), 1) clear_cached_entry(sum, 1) self.assertEquals(sum(1), 3)