Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Unified Diff: appengine/findit/util_scripts/test/local_cache_test.py

Issue 2456603003: [Predator] Add local cache for get command output. (Closed)
Patch Set: Rebase. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/findit/util_scripts/test/local_cache_test.py
diff --git a/appengine/findit/util_scripts/test/local_cache_test.py b/appengine/findit/util_scripts/test/local_cache_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..b8eff03cefde6c993d2486086fd0cd633c4b979d
--- /dev/null
+++ b/appengine/findit/util_scripts/test/local_cache_test.py
@@ -0,0 +1,32 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# 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
+
+from testing_utils import testing
+
+import local_cache
+
+
+class LocalCacheTest(testing.AppengineTestCase):
+
+ def testLocalCacher(self):
+ fake_dir = 'fake_dir'
+ cacher = local_cache.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 = 'val'
+ 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'))
« no previous file with comments | « appengine/findit/util_scripts/script_util.py ('k') | appengine/findit/util_scripts/test/script_util_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698