Skip to content

WIP: Include some tests of store equality #357

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions zarr/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,8 @@ def __contains__(self, item):
def __eq__(self, other):
return (
isinstance(other, DictStore) and
self.root == other.root and
self.cls == other.cls
self.cls == other.cls and
self.root is other.root
)

def keys(self):
Expand Down Expand Up @@ -1843,6 +1843,13 @@ def _invalidate_value(self, key):
value = self._values_cache.pop(key)
self._current_size -= buffer_size(value)

def __eq__(self, other):
return (
isinstance(other, LRUStoreCache) and
self._store is other._store and
self._values_cache is other._values_cache
)

def __getitem__(self, key):
try:
# first try to obtain the value from the cache
Expand Down Expand Up @@ -1968,6 +1975,14 @@ def close(self):
self.cursor.close()
self.db.close()

def __eq__(self, other):
return (
isinstance(other, SQLiteStore) and
self.path == other.path and
self.kwargs == other.kwargs and
self.db == other.db
)

def __getitem__(self, key):
value = self.cursor.execute('SELECT v FROM zarr WHERE (k = ?)', (key,))
for v, in value:
Expand Down
29 changes: 29 additions & 0 deletions zarr/tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,35 @@ def test_writeable_values(self):
store['foo3'] = array.array('B', b'bar')
store['foo4'] = np.frombuffer(b'bar', dtype='u1')

def test_compare_eq(self):
store1 = self.create_store()
store2 = self.create_store()

assert store1 == store1
store2['foo'] = b'abcde'
assert store2 == store2

store1 = self.create_store()
store2 = self.create_store()

store1['foo'] = b'abcde'
store2['foo'] = b'abcde'
assert store1 != store2

store1 = self.create_store()
store2 = self.create_store()

store1['foo'] = b'abcde'
store2['baz'] = b'abcde'
assert store1 != store2

store1 = self.create_store()
store2 = self.create_store()

store1['foo'] = b'abcde'
store2['foo'] = b'uvwxy'
assert store1 != store2

def test_update(self):
store = self.create_store()
assert 'foo' not in store
Expand Down