| Index: appengine/findit/common/test/cache_decorator_test.py
|
| diff --git a/appengine/findit/common/test/cache_decorator_test.py b/appengine/findit/common/test/cache_decorator_test.py
|
| index a3a2fd467c7e0b29790a484bd2e45b31d958614c..2be1439799f2c522ace750facf404cef44a7b1ba 100644
|
| --- a/appengine/findit/common/test/cache_decorator_test.py
|
| +++ b/appengine/findit/common/test/cache_decorator_test.py
|
| @@ -2,6 +2,9 @@
|
| # Use of this source code is governed by a BSD-style license that can be
|
| # found in the LICENSE file.
|
|
|
| +import __builtin__
|
| +import mock
|
| +import os
|
| import pickle
|
| import zlib
|
|
|
| @@ -162,3 +165,19 @@ class CacheDecoratorTest(testing.AppengineTestCase):
|
| a2 = A('http://test', 5)
|
| self.assertEqual('http://test/p1', a2.Func('p1'))
|
| self.assertEqual(0, a2.runs)
|
| +
|
| + def testLocalCacher(self):
|
| + fake_dir = 'fake_dir'
|
| + cacher = cache_decorator.LocalCacher(cache_dir=fake_dir)
|
| + def _MockPathExists(path, *_):
|
| + return False if path == os.path.join(
|
| + fake_dir, 'uncached_key') else True
|
| + self.mock(os.path, 'exists', _MockPathExists)
|
| +
|
| + value = 'value'
|
| + with mock.patch('__builtin__.open', mock.mock_open(
|
| + read_data=zlib.compress(pickle.dumps('value')))) as m:
|
| + cacher.Set('a', 'b')
|
| + m.assert_called_once_with(os.path.join(fake_dir, 'a'), 'wb')
|
| + self.assertEqual(value, cacher.Get('key'))
|
| + self.assertIsNone(cacher.Get('uncached_key'))
|
|
|