ENH: Add zipline.utils.cache.

Implements a `CachedObject` utility class for wrapping cached results
with an expiration date.
This commit is contained in:
Scott Sanderson
2015-09-28 14:59:48 -04:00
parent 00c413e9d4
commit b766ce6ebd
3 changed files with 85 additions and 1 deletions
+21
View File
@@ -0,0 +1,21 @@
from unittest import TestCase
from pandas import Timestamp, Timedelta
from zipline.utils.cache import CachedObject, Expired
class CachedObjectTestCase(TestCase):
def test_cached_object(self):
expiry = Timestamp('2014')
before = expiry - Timedelta('1 minute')
after = expiry + Timedelta('1 minute')
obj = CachedObject(1, expiry)
self.assertEqual(obj.unwrap(before), 1)
self.assertEqual(obj.unwrap(expiry), 1) # Unwrap on expiry is allowed.
with self.assertRaises(Expired) as e:
obj.unwrap(after)
self.assertEqual(e.exception.args, (expiry,))