def test_if_exists(self): source = self.source dest = dict() dest['bar/baz'] = b'mmm' # default ('raise') with pytest.raises(CopyError): copy_store(source, dest) # explicit 'raise' with pytest.raises(CopyError): copy_store(source, dest, if_exists='raise') # skip copy_store(source, dest, if_exists='skip') assert 3 == len(dest) assert dest['foo'] == b'xxx' assert dest['bar/baz'] == b'mmm' assert dest['bar/qux'] == b'zzz' # replace copy_store(source, dest, if_exists='replace') assert 3 == len(dest) assert dest['foo'] == b'xxx' assert dest['bar/baz'] == b'yyy' assert dest['bar/qux'] == b'zzz' # invalid option with pytest.raises(ValueError): copy_store(source, dest, if_exists='foobar')
def test_no_paths(self): source = self.source dest = dict() copy_store(source, dest) assert len(source) == len(dest) for key in source: assert source[key] == dest[key]
def test_if_exists(self): source = self.source dest = self._get_dest_store() root = '' if self._version == 2 else meta_root dest[root + 'bar/baz'] = b'mmm' # default ('raise') with pytest.raises(CopyError): copy_store(source, dest) # explicit 'raise' with pytest.raises(CopyError): copy_store(source, dest, if_exists='raise') # skip copy_store(source, dest, if_exists='skip') assert 3 == len(dest) assert dest[root + 'foo'] == b'xxx' assert dest[root + 'bar/baz'] == b'mmm' assert dest[root + 'bar/qux'] == b'zzz' # replace copy_store(source, dest, if_exists='replace') assert 3 == len(dest) assert dest[root + 'foo'] == b'xxx' assert dest[root + 'bar/baz'] == b'yyy' assert dest[root + 'bar/qux'] == b'zzz' # invalid option with pytest.raises(ValueError): copy_store(source, dest, if_exists='foobar')
def test_dest_path(self): source = self.source # paths should be normalized for dest_path in 'new', 'new/', '/new', '/new/': dest = dict() copy_store(source, dest, dest_path=dest_path) assert len(source) == len(dest) for key in source: dest_key = 'new/' + key assert source[key] == dest[dest_key]
def test_source_path(self): source = self.source # paths should be normalized for source_path in 'bar', 'bar/', '/bar', '/bar/': dest = dict() copy_store(source, dest, source_path=source_path) assert 2 == len(dest) for key in source: if key.startswith('bar/'): dest_key = key.split('bar/')[1] assert source[key] == dest[dest_key] else: assert key not in dest
def test_dest_path(self): source = self.source # paths should be normalized for dest_path in 'new', 'new/', '/new', '/new/': dest = self._get_dest_store() copy_store(source, dest, dest_path=dest_path) assert len(source) == len(dest) for key in source: if self._version == 3: dest_key = key[:10] + 'new/' + key[10:] else: dest_key = 'new/' + key assert source[key] == dest[dest_key]
def test_excludes_includes(self): source = self.source # single excludes dest = dict() excludes = 'f.*' copy_store(source, dest, excludes=excludes) assert len(dest) == 2 assert 'foo' not in dest # multiple excludes dest = dict() excludes = 'b.z', '.*x' copy_store(source, dest, excludes=excludes) assert len(dest) == 1 assert 'foo' in dest assert 'bar/baz' not in dest assert 'bar/qux' not in dest # excludes and includes dest = dict() excludes = 'b.*' includes = '.*x' copy_store(source, dest, excludes=excludes, includes=includes) assert len(dest) == 2 assert 'foo' in dest assert 'bar/baz' not in dest assert 'bar/qux' in dest
def test_excludes_includes(self): source = self.source # single excludes dest = self._get_dest_store() excludes = 'f.*' copy_store(source, dest, excludes=excludes) assert len(dest) == 2 root = '' if self._version == 2 else meta_root assert root + 'foo' not in dest # multiple excludes dest = self._get_dest_store() excludes = 'b.z', '.*x' copy_store(source, dest, excludes=excludes) assert len(dest) == 1 assert root + 'foo' in dest assert root + 'bar/baz' not in dest assert root + 'bar/qux' not in dest # excludes and includes dest = self._get_dest_store() excludes = 'b.*' includes = '.*x' copy_store(source, dest, excludes=excludes, includes=includes) assert len(dest) == 2 assert root + 'foo' in dest assert root + 'bar/baz' not in dest assert root + 'bar/qux' in dest
def test_dry_run(self): source = self.source dest = dict() copy_store(source, dest, dry_run=True) assert 0 == len(dest)
def test_mismatched_store_versions(self): # cannot copy between stores of mixed Zarr versions dest = KVStore(dict()) with pytest.raises(ValueError): copy_store(self.source, dest)