def nested_store(self, request): prefixes = request.param[0].split('/') namess = request.param[1:] self.coords = ParameterList() store = MemoryStore() for prefix, names in zip(prefixes, namess): coords = ParameterList( Parameter(name, value=name) for name in names) store = MeasurementStore(store, prefix=prefix, coordinates=coords) self.coords.extend(coords) return store
def test_save(self, csvstore, frame): store = MeasurementStore(csvstore, '/data', ParameterList(), save=False) store.put(frame) assert len(store.store) == 0 assert store.directory() is None
def test_append(self, frame): pidx = Parameter('idx') coords = ParameterList((pidx, )) store = MeasurementStore(MemoryStore(), '/data', coords) for idx in range(5): pidx.set(idx) store.append(frame) for idx in range(5): pidx.set(idx) pframe = store.get().loc[(idx, slice(None), slice(None)), :] self.check_coords(frame, pframe, coords)
def test_on_new_item(self, frame): self.new_item_count = 0 def on_new_item(store, key): self.new_item_count += 1 MeasurementStore.on_new_item.append(on_new_item) store = MeasurementStore(MemoryStore(), '/data', ParameterList()) store.append(frame) assert self.new_item_count == 1, 'on_new_item did not fire' store.append(frame) assert self.new_item_count == 1, 'on_new_item fired more than once'
def test_directory(self, csvstore): store = MeasurementStore(csvstore, '/data', ParameterList()) assert os.path.isdir(store.directory())
def test_prepend_coordinates(self, frame, names): coords = ParameterList([Parameter(name, value=name) for name in names]) store = MeasurementStore(MemoryStore(), '/data', coords) self.check_coords(frame, store._prepend_coordinates(frame), coords)
class TestMeasurementStore(object): @fixture( params=[ # prefix, l0 coordinates, l1 coordinates, ... ('l0', ()), ('l0', ('a', )), ('l0', ('a', 'b')), ('l0/l1', (), ('a', )), ('l0/l1', ('a', ), ()), ('l0/l1', ('a', ), ('b', )), ('l0/l1', ('a', 'b'), ('c', )), ('l0/l1', ('a', ), ('b', 'c')), ('l0/l1/l2', ('a', ), ('b', ), ('c', )) ], ids=['0', '1', '2', '01', '10', '11', '21', '12', '111']) def nested_store(self, request): prefixes = request.param[0].split('/') namess = request.param[1:] self.coords = ParameterList() store = MemoryStore() for prefix, names in zip(prefixes, namess): coords = ParameterList( Parameter(name, value=name) for name in names) store = MeasurementStore(store, prefix=prefix, coordinates=coords) self.coords.extend(coords) return store def check_coords(self, original, appended, coords): # index has coordinate axes preprended assert appended.index.names == coords.names() + original.index.names for level, value in enumerate(coords.values()): assert np.all(appended.index.get_level_values(level) == value) # value matrix is unchanged assert np.all(appended.values == original.values) def test_nesting(self, nested_store, frame): nested_store.put(frame) self.check_coords(frame, nested_store.get(), self.coords) @mark.parametrize('names', ['', 'a', 'ab']) def test_prepend_coordinates(self, frame, names): coords = ParameterList([Parameter(name, value=name) for name in names]) store = MeasurementStore(MemoryStore(), '/data', coords) self.check_coords(frame, store._prepend_coordinates(frame), coords) def test_save(self, csvstore, frame): store = MeasurementStore(csvstore, '/data', ParameterList(), save=False) store.put(frame) assert len(store.store) == 0 assert store.directory() is None def test_directory(self, csvstore): store = MeasurementStore(csvstore, '/data', ParameterList()) assert os.path.isdir(store.directory()) def test_append(self, frame): pidx = Parameter('idx') coords = ParameterList((pidx, )) store = MeasurementStore(MemoryStore(), '/data', coords) for idx in range(5): pidx.set(idx) store.append(frame) for idx in range(5): pidx.set(idx) pframe = store.get().loc[(idx, slice(None), slice(None)), :] self.check_coords(frame, pframe, coords) def test_on_new_item(self, frame): self.new_item_count = 0 def on_new_item(store, key): self.new_item_count += 1 MeasurementStore.on_new_item.append(on_new_item) store = MeasurementStore(MemoryStore(), '/data', ParameterList()) store.append(frame) assert self.new_item_count == 1, 'on_new_item did not fire' store.append(frame) assert self.new_item_count == 1, 'on_new_item fired more than once'