Beispiel #1
0
 def test_reraise_exception(self):
     '''If the provided factory returns an exception, reraise it.'''
     factory = mock.Mock(return_value=(10, ValueError('Kaboom!')))
     obj = cache.ExpiringObject(factory)
     with self.assertRaises(ValueError):
         obj.get()
     self.assertEqual(obj.expires, 10)
Beispiel #2
0
 def test_memoizes_cached_result(self):
     '''Memoizes what's returned by the factory.'''
     factory = mock.Mock(return_value=(10, 'result'))
     obj = cache.ExpiringObject(factory)
     with mock.patch.object(cache.time, 'time', return_value=0):
         for _ in range(10):
             obj.get()
     self.assertEqual(factory.call_count, 1)
Beispiel #3
0
 def test_uses_factory(self):
     '''Uses the result from the factory.'''
     factory = mock.Mock(return_value=(10, 'result'))
     obj = cache.ExpiringObject(factory)
     self.assertEqual(obj.get(), 'result')
     self.assertEqual(obj.expires, 10)