Skip to content

Commit

Permalink
Test the new decorators.
Browse files Browse the repository at this point in the history
  • Loading branch information
coleifer committed Jan 13, 2015
1 parent 8c8a044 commit 3cdf6ca
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions walrus/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class Stat(BaseModel):
def now(seed=None):
return datetime.datetime.now()

class Clock(object):
@cache.cached_property()
def now(self):
return datetime.datetime.now()


class WalrusTestCase(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -462,6 +467,24 @@ def test_cache_decorator(self):
self.assertNotEqual(now(1), n2)
self.assertEqual(now(1), now(1))

def test_cached_property(self):
c = Clock()
n1 = c.now
n2 = c.now
self.assertEqual(n1, n2)

def test_cached_async(self):
@cache.cache_async()
def double_value(value):
return value * 2

res = double_value(3)
self.assertEqual(res(), 6)
self.assertEqual(res(), 6)

self.assertEqual(double_value(3)(), 6)
self.assertEqual(double_value(4)(), 8)


class TestHash(WalrusTestCase):
def setUp(self):
Expand Down

0 comments on commit 3cdf6ca

Please sign in to comment.