aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorThomas Kemmer <tkemmer@computer.org>2016-10-03 13:43:18 +0200
committerThomas Kemmer <tkemmer@computer.org>2016-10-03 13:43:18 +0200
commit1770a71f3e441edd6c636412d2309cbcf9ec931b (patch)
tree35c294a71a1850cadbc4e7dacff7bf7e26930477 /tests
parentbb87402d379dceff5309acfc71a1b335fbca787e (diff)
downloadcachetools-1770a71f3e441edd6c636412d2309cbcf9ec931b.tar.gz
Fix #74: Move key functions to separate package.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_keys.py8
-rw-r--r--tests/test_method.py4
-rw-r--r--tests/test_wrapper.py40
3 files changed, 24 insertions, 28 deletions
diff --git a/tests/test_keys.py b/tests/test_keys.py
index 94184a5..2b9ced6 100644
--- a/tests/test_keys.py
+++ b/tests/test_keys.py
@@ -1,11 +1,11 @@
import unittest
-import cachetools
+import cachetools.keys
class CacheKeysTest(unittest.TestCase):
- def test_hashkey(self, key=cachetools.hashkey):
+ def test_hashkey(self, key=cachetools.keys.hashkey):
self.assertEqual(key(), key())
self.assertEqual(hash(key()), hash(key()))
self.assertEqual(key(1, 2, 3), key(1, 2, 3))
@@ -22,7 +22,7 @@ class CacheKeysTest(unittest.TestCase):
self.assertEqual(key(1, 2, 3), key(1.0, 2.0, 3.0))
self.assertEqual(hash(key(1, 2, 3)), hash(key(1.0, 2.0, 3.0)))
- def test_typedkey(self, key=cachetools.typedkey):
+ def test_typedkey(self, key=cachetools.keys.typedkey):
self.assertEqual(key(), key())
self.assertEqual(hash(key()), hash(key()))
self.assertEqual(key(1, 2, 3), key(1, 2, 3))
@@ -38,7 +38,7 @@ class CacheKeysTest(unittest.TestCase):
# typed keys compare unequal
self.assertNotEqual(key(1, 2, 3), key(1.0, 2.0, 3.0))
- def test_addkeys(self, key=cachetools.hashkey):
+ def test_addkeys(self, key=cachetools.keys.hashkey):
self.assertIsInstance(key(), tuple)
self.assertIsInstance(key(1, 2, 3) + key(4, 5, 6), type(key()))
self.assertIsInstance(key(1, 2, 3) + (4, 5, 6), type(key()))
diff --git a/tests/test_method.py b/tests/test_method.py
index cf53536..db810b6 100644
--- a/tests/test_method.py
+++ b/tests/test_method.py
@@ -1,7 +1,7 @@
import operator
import unittest
-from cachetools import LRUCache, cachedmethod, typedkey
+from cachetools import LRUCache, cachedmethod, keys
class Cached(object):
@@ -16,7 +16,7 @@ class Cached(object):
self.count += 1
return count
- @cachedmethod(operator.attrgetter('cache'), key=typedkey)
+ @cachedmethod(operator.attrgetter('cache'), key=keys.typedkey)
def get_typed(self, value):
count = self.count
self.count += 1
diff --git a/tests/test_wrapper.py b/tests/test_wrapper.py
index 1d03fb2..a6e649c 100644
--- a/tests/test_wrapper.py
+++ b/tests/test_wrapper.py
@@ -1,6 +1,7 @@
import unittest
import cachetools
+import cachetools.keys
class DecoratorTestMixin(object):
@@ -24,15 +25,15 @@ class DecoratorTestMixin(object):
self.assertEqual(wrapper(0), 0)
self.assertEqual(len(cache), 1)
- self.assertIn(cachetools.hashkey(0), cache)
- self.assertNotIn(cachetools.hashkey(1), cache)
- self.assertNotIn(cachetools.hashkey(1.0), cache)
+ self.assertIn(cachetools.keys.hashkey(0), cache)
+ self.assertNotIn(cachetools.keys.hashkey(1), cache)
+ self.assertNotIn(cachetools.keys.hashkey(1.0), cache)
self.assertEqual(wrapper(1), 1)
self.assertEqual(len(cache), 2)
- self.assertIn(cachetools.hashkey(0), cache)
- self.assertIn(cachetools.hashkey(1), cache)
- self.assertIn(cachetools.hashkey(1.0), cache)
+ self.assertIn(cachetools.keys.hashkey(0), cache)
+ self.assertIn(cachetools.keys.hashkey(1), cache)
+ self.assertIn(cachetools.keys.hashkey(1.0), cache)
self.assertEqual(wrapper(1), 1)
self.assertEqual(len(cache), 2)
@@ -45,37 +46,32 @@ class DecoratorTestMixin(object):
def test_decorator_typed(self):
cache = self.cache(3)
-
- def typedkey(*args, **kwargs):
- key = cachetools.hashkey(*args, **kwargs)
- key += tuple(type(v) for v in args)
- key += tuple(type(v) for _, v in sorted(kwargs.items()))
- return key
- wrapper = cachetools.cached(cache, key=typedkey)(self.func)
+ key = cachetools.keys.typedkey
+ wrapper = cachetools.cached(cache, key=key)(self.func)
self.assertEqual(len(cache), 0)
self.assertEqual(wrapper.__wrapped__, self.func)
self.assertEqual(wrapper(0), 0)
self.assertEqual(len(cache), 1)
- self.assertIn(typedkey(0), cache)
- self.assertNotIn(typedkey(1), cache)
- self.assertNotIn(typedkey(1.0), cache)
+ self.assertIn(cachetools.keys.typedkey(0), cache)
+ self.assertNotIn(cachetools.keys.typedkey(1), cache)
+ self.assertNotIn(cachetools.keys.typedkey(1.0), cache)
self.assertEqual(wrapper(1), 1)
self.assertEqual(len(cache), 2)
- self.assertIn(typedkey(0), cache)
- self.assertIn(typedkey(1), cache)
- self.assertNotIn(typedkey(1.0), cache)
+ self.assertIn(cachetools.keys.typedkey(0), cache)
+ self.assertIn(cachetools.keys.typedkey(1), cache)
+ self.assertNotIn(cachetools.keys.typedkey(1.0), cache)
self.assertEqual(wrapper(1), 1)
self.assertEqual(len(cache), 2)
self.assertEqual(wrapper(1.0), 2)
self.assertEqual(len(cache), 3)
- self.assertIn(typedkey(0), cache)
- self.assertIn(typedkey(1), cache)
- self.assertIn(typedkey(1.0), cache)
+ self.assertIn(cachetools.keys.typedkey(0), cache)
+ self.assertIn(cachetools.keys.typedkey(1), cache)
+ self.assertIn(cachetools.keys.typedkey(1.0), cache)
self.assertEqual(wrapper(1.0), 2)
self.assertEqual(len(cache), 3)