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

Unified Diff: chrome/common/extensions/docs/server2/test_object_store.py

Issue 14218004: Devserver: only populate data during cron jobs, meaning all data from instances (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: PTAL Created 7 years, 8 months 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: chrome/common/extensions/docs/server2/test_object_store.py
diff --git a/chrome/common/extensions/docs/server2/test_object_store.py b/chrome/common/extensions/docs/server2/test_object_store.py
index d78746224267ddb51ef758efe1114388706b8a01..c1e5bc45a92bca49879c30e1fbd666357f3494f4 100644
--- a/chrome/common/extensions/docs/server2/test_object_store.py
+++ b/chrome/common/extensions/docs/server2/test_object_store.py
@@ -6,19 +6,58 @@ from future import Future
from object_store import ObjectStore
class TestObjectStore(ObjectStore):
- '''An object store which records its namespace and behaves like a dict, for
- testing.
+ '''An object store which records its namespace and behaves like a dict.
+ Specify |init| with an initial object for the object store.
+ Use CheckAndReset to assert how many times Get/Set/Del have been called. Get
+ is a special case; it is only incremented once the future has had Get called.
'''
- def __init__(self, namespace):
+ def __init__(self, namespace, init=None):
self.namespace = namespace
- self._store = {}
+ self._store = init or {}
+ self._get_count = 0
+ self._set_count = 0
+ self._del_count = 0
- def SetMulti(self, mapping, **optarg):
+ #
+ # ObjectStore implementation.
+ #
+
+ def GetMulti(self, keys):
+ class FutureImpl(object):
+ def Get(self2):
+ self._get_count += 1
+ return dict((k, self._store.get(k)) for k in keys if k in self._store)
+ return Future(delegate=FutureImpl())
+
+ def SetMulti(self, mapping):
+ self._set_count += 1
self._store.update(mapping)
- def GetMulti(self, keys, **optargs):
- return Future(value=dict((k, v) for k, v in self._store.items()
- if k in keys))
+ def DelMulti(self, keys):
+ self._del_count += 1
+ for k in keys:
+ self._store.pop(k, None)
+
+ #
+ # Testing methods.
+ #
+
+ def CheckAndReset(self, get_count=0, set_count=0, del_count=0):
+ '''Returns a tuple (success, error). Use in tests like:
cduvall 2013/04/17 23:30:37 This is cool
not at google - send to devlin 2013/04/18 04:05:41 Yah proud of that little pythonism. I'll try to re
+ self.assertTrue(*object_store.CheckAndReset(...))
+ '''
+ errors = []
+ for desc, expected, actual in (('get_count', get_count, self._get_count),
+ ('set_count', set_count, self._set_count),
+ ('del_count', del_count, self._del_count)):
+ if actual != expected:
+ errors.append('%s: expected %s got %s' % (desc, expected, actual))
+ try:
+ return (len(errors) == 0, ','.join(errors))
+ finally:
+ self.Reset()
- def Delete(self, key):
- del self._store[key]
+ def Reset(self):
+ self._get_count = 0
+ self._set_count = 0
+ self._del_count = 0

Powered by Google App Engine
This is Rietveld 408576698