| 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 __builtin__ |
| 6 import mock |
| 7 import os |
| 5 import pickle | 8 import pickle |
| 6 import zlib | 9 import zlib |
| 7 | 10 |
| 8 from google.appengine.api import memcache | 11 from google.appengine.api import memcache |
| 9 | 12 |
| 10 from testing_utils import testing | 13 from testing_utils import testing |
| 11 | 14 |
| 12 from common import cache_decorator | 15 from common import cache_decorator |
| 13 | 16 |
| 14 | 17 |
| (...skipping 140 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 fake_dir = 'fake_dir' |
| 171 cacher = cache_decorator.LocalCacher(cache_dir=fake_dir) |
| 172 def _MockPathExists(path, *_): |
| 173 return False if path == os.path.join( |
| 174 fake_dir, 'uncached_key') else True |
| 175 self.mock(os.path, 'exists', _MockPathExists) |
| 176 |
| 177 value = 'value' |
| 178 with mock.patch('__builtin__.open', mock.mock_open( |
| 179 read_data=zlib.compress(pickle.dumps('value')))) as m: |
| 180 cacher.Set('a', 'b') |
| 181 m.assert_called_once_with(os.path.join(fake_dir, 'a'), 'wb') |
| 182 self.assertEqual(value, cacher.Get('key')) |
| 183 self.assertIsNone(cacher.Get('uncached_key')) |
| OLD | NEW |