OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 from future import Future | 5 from future import Future |
6 from object_store import ObjectStore | 6 from object_store import ObjectStore |
7 | 7 |
8 class TestObjectStore(ObjectStore): | 8 class TestObjectStore(ObjectStore): |
9 '''An object store which records its namespace and behaves like a dict. | 9 '''An object store which records its namespace and behaves like a dict. |
10 Specify |init| with an initial object for the object store. | 10 Specify |init| with an initial object for the object store. |
11 Use CheckAndReset to assert how many times Get/Set/Del have been called. Get | 11 Use CheckAndReset to assert how many times Get/Set/Del have been called. Get |
12 is a special case; it is only incremented once the future has had Get called. | 12 is a special case; it is only incremented once the future has had Get called. |
13 ''' | 13 ''' |
14 def __init__(self, namespace, init=None, **optargs): | 14 def __init__(self, namespace, start_empty=False, init=None): |
15 self.namespace = namespace | 15 self.namespace = namespace |
| 16 self.start_empty = start_empty |
16 self._store = {} if init is None else init | 17 self._store = {} if init is None else init |
| 18 if start_empty: |
| 19 assert not self._store |
17 self._get_count = 0 | 20 self._get_count = 0 |
18 self._set_count = 0 | 21 self._set_count = 0 |
19 self._del_count = 0 | 22 self._del_count = 0 |
20 | 23 |
21 # | 24 # |
22 # ObjectStore implementation. | 25 # ObjectStore implementation. |
23 # | 26 # |
24 | 27 |
25 def GetMulti(self, keys): | 28 def GetMulti(self, keys): |
26 class FutureImpl(object): | 29 class FutureImpl(object): |
(...skipping 27 matching lines...) Expand all Loading... |
54 errors.append('%s: expected %s got %s' % (desc, expected, actual)) | 57 errors.append('%s: expected %s got %s' % (desc, expected, actual)) |
55 try: | 58 try: |
56 return (len(errors) == 0, ', '.join(errors)) | 59 return (len(errors) == 0, ', '.join(errors)) |
57 finally: | 60 finally: |
58 self.Reset() | 61 self.Reset() |
59 | 62 |
60 def Reset(self): | 63 def Reset(self): |
61 self._get_count = 0 | 64 self._get_count = 0 |
62 self._set_count = 0 | 65 self._set_count = 0 |
63 self._del_count = 0 | 66 self._del_count = 0 |
OLD | NEW |