All pastes #467275 Raw Edit

Untitled

public python v1 · immutable
·published 2007-05-02 12:51 UTC
rendered paste body
@memoizedef empty_function():    global has_been_called    has_been_called = True    return 'empty_function'class EcsCacheTest(unittest.TestCase):    @memoize    def empty_method(self):        global has_been_called        has_been_called = True        return 'empty_method'    def test_empty_functions(self):        # test with an empty function        # first call: we will use the real function        self.assertEqual(empty_function(), 'empty_function')        self.assertEqual(has_been_called, True)        # Second call: we will use the cache        self.assertEqual(empty_function(), 'empty_function')        self.assertEqual(has_been_called, False)        # test with an empty method        # first call: we will use the real method        self.assertEqual(self.empty_method(), 'empty_method')        self.assertEqual(has_been_called, True)        # Second call: we will use the cache        self.assertEqual(self.empty_method(), 'empty_method')        self.assertEqual(has_been_called, False)