Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import os | |
| 5 import pickle | 6 import pickle |
| 6 import zlib | 7 import zlib |
| 7 | 8 |
| 8 from google.appengine.api import memcache | 9 from google.appengine.api import memcache |
| 9 | 10 |
| 10 from testing_utils import testing | 11 from testing_utils import testing |
| 11 | 12 |
| 12 from common import cache_decorator | 13 from common import cache_decorator |
| 13 | 14 |
| 15 _LOCAL_CACHE_TEST_DIR = os.path.join(os.path.expanduser('~'), '.test_cache') | |
|
Martin Barbella
2016/10/26 23:21:20
Could you use https://pypi.python.org/pypi/pyfakef
Sharu Jiang
2016/10/27 21:59:05
The pyfakefs is third_party libs, use mock instead
| |
| 16 | |
| 14 | 17 |
| 15 class _DummyCacher(cache_decorator.Cacher): | 18 class _DummyCacher(cache_decorator.Cacher): |
| 16 def __init__(self, cached_data): | 19 def __init__(self, cached_data): |
| 17 self.cached_data = cached_data | 20 self.cached_data = cached_data |
| 18 | 21 |
| 19 def Get(self, key): | 22 def Get(self, key): |
| 20 return self.cached_data.get(key) | 23 return self.cached_data.get(key) |
| 21 | 24 |
| 22 def Set(self, key, data, expire_time=0): | 25 def Set(self, key, data, expire_time=0): |
| 23 self.cached_data[key] = data | 26 self.cached_data[key] = data |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 return self.url + '/' + path | 158 return self.url + '/' + path |
| 156 | 159 |
| 157 a1 = A('http://test', 3) | 160 a1 = A('http://test', 3) |
| 158 self.assertEqual('http://test/p1', a1.Func('p1')) | 161 self.assertEqual('http://test/p1', a1.Func('p1')) |
| 159 self.assertEqual('http://test/p1', a1.Func('p1')) | 162 self.assertEqual('http://test/p1', a1.Func('p1')) |
| 160 self.assertEqual(1, a1.runs) | 163 self.assertEqual(1, a1.runs) |
| 161 | 164 |
| 162 a2 = A('http://test', 5) | 165 a2 = A('http://test', 5) |
| 163 self.assertEqual('http://test/p1', a2.Func('p1')) | 166 self.assertEqual('http://test/p1', a2.Func('p1')) |
| 164 self.assertEqual(0, a2.runs) | 167 self.assertEqual(0, a2.runs) |
| 168 | |
| 169 def testLocalCacher(self): | |
| 170 cacher = cache_decorator.LocalCacher(cache_dir=_LOCAL_CACHE_TEST_DIR) | |
| 171 cacher.Set('a', 'b') | |
| 172 self.assertEqual('b', cacher.Get('a')) | |
| 173 cacher.Set('c', 'd') | |
| 174 self.assertEqual('d', cacher.Get('c')) | |
| 175 self.assertIsNone(cacher.Get('uncached_key')) | |
| OLD | NEW |