diff options
author | Thomas Kemmer <tkemmer@computer.org> | 2014-03-27 06:23:04 +0100 |
---|---|---|
committer | Thomas Kemmer <tkemmer@computer.org> | 2014-04-02 20:38:40 +0200 |
commit | 3b9d81924ae6b4011048096cf12a7cdad5508f30 (patch) | |
tree | 6c4979659e97c4fe4d448574903c51f9863ca9ee /tests/test_cache.py | |
parent | 35f85f2f78f842b15609c5973f1fdd261c0a6476 (diff) | |
download | cachetools-3b9d81924ae6b4011048096cf12a7cdad5508f30.tar.gz |
Prepare v0.2.0
Diffstat (limited to 'tests/test_cache.py')
-rw-r--r-- | tests/test_cache.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/test_cache.py b/tests/test_cache.py new file mode 100644 index 0000000..5c32f2b --- /dev/null +++ b/tests/test_cache.py @@ -0,0 +1,41 @@ +import unittest + +import cachetools +import collections + + +@cachetools.cache +class DictCache(dict): + pass + + +@cachetools.cache +class OrderedDictCache(collections.OrderedDict): + pass + + +class CacheTest(unittest.TestCase): + + def test_dict_cache(self): + cache = DictCache(maxsize=2) + + cache['a'] = 1 + cache['b'] = 2 + cache['c'] = 3 + + self.assertEqual(len(cache), 2) + self.assertTrue('a' in cache or ('b' in cache and 'c' in cache)) + self.assertTrue('b' in cache or ('a' in cache and 'c' in cache)) + self.assertTrue('c' in cache or ('a' in cache and 'b' in cache)) + + def test_ordered_dict_cache(self): + cache = OrderedDictCache(maxsize=2) + + cache['a'] = 1 + cache['b'] = 2 + cache['c'] = 3 + + self.assertEqual(len(cache), 2) + self.assertNotIn('a', cache) + self.assertEqual(cache['b'], 2) + self.assertEqual(cache['c'], 3) |