def test_cache_time(self): self.mox.StubOutWithMock(time, 'clock') time.clock().AndReturn(0.1) time.clock().AndReturn(0.2) time.clock().AndReturn(1.501) time.clock().AndReturn(1.503) self.mox.ReplayAll() self.assertIsNone(memcache.get('timed foo')) self.assertIsNone(memcache.get('timed foo size')) with util.cache_time('foo'): pass self.assertEquals(100, memcache.get('timed foo')) self.assertIsNone(memcache.get('timed foo size')) with util.cache_time('foo', 3): pass self.assertEquals(102, memcache.get('timed foo')) self.assertEquals(3, memcache.get('timed foo size'))