def test_delete(client, database, cleanup): disk_store = DiskObjectStore(database) _id = UID() storable = StorableObject(id=_id, data=tensor1) disk_store.__setitem__(_id, storable) bin_obj = database.session.query(BinObject).get(str(_id.value)) metadata = (database.session.query(ObjectMetadata).filter_by( obj=str(_id.value)).one()) assert bin_obj is not None assert th.all(th.eq(bin_obj.object, tensor1)) assert metadata is not None assert metadata.tags == [] assert metadata.description == "" assert metadata.read_permissions == {} assert metadata.search_permissions == {} disk_store.delete(_id) assert database.session.query(BinObject).get(str(_id.value)) is None with pytest.raises(NoResultFound) as e_info: database.session.query(ObjectMetadata).filter_by( obj=str(_id.value)).one()
def test_clear(client, database, cleanup): disk_store = DiskObjectStore(database) _id = UID() storable = StorableObject(id=_id, data=tensor1) disk_store.__setitem__(_id, storable) bin_obj = database.session.query(BinObject).get(str(_id.value)) metadata = (database.session.query(ObjectMetadata).filter_by( obj=str(_id.value)).one()) assert bin_obj is not None assert th.all(th.eq(bin_obj.object, tensor1)) assert metadata is not None assert metadata.tags == [] assert metadata.description == "" assert metadata.read_permissions == {} assert metadata.search_permissions == {} retrieved = disk_store.get_object(_id) assert th.all(th.eq(retrieved.data, tensor1)) assert retrieved.id == _id disk_store.clear() assert database.session.query(BinObject).count() == 0 assert database.session.query(ObjectMetadata).count() == 0
def test_keys(client, database, cleanup): disk_store = DiskObjectStore(database) a_id = UID() id1 = UID() id2 = UID() storable1 = StorableObject(id=id1, data=tensor1) disk_store.__setitem__(id1, storable1) storable2 = StorableObject(id=id2, data=tensor2) disk_store.__setitem__(id2, storable2) keys = disk_store.keys() assert any(id1 == k for k in keys) assert any(id2 == k for k in keys) assert len(keys) == 2
def test_values(client, database, cleanup): disk_store = DiskObjectStore(database) a_id = UID() id1 = UID() id2 = UID() storable1 = StorableObject(id=id1, data=tensor1) disk_store.__setitem__(id1, storable1) storable2 = StorableObject(id=id2, data=tensor2) disk_store.__setitem__(id2, storable2) values = disk_store.values() values_data = [v.data for v in values] assert any(th.all(th.eq(tensor1, v)) for v in values_data) assert any(th.all(th.eq(tensor2, v)) for v in values_data) assert len(values_data) == 2
def test_get_objects_of_type(client, database, cleanup): disk_store = DiskObjectStore(database) a_id = UID() id1 = UID() id2 = UID() storable1 = StorableObject(id=id1, data=tensor1) disk_store.__setitem__(id1, storable1) storable2 = StorableObject(id=id2, data=tensor2) disk_store.__setitem__(id2, storable2) selected = disk_store.get_objects_of_type(th.Tensor) selected_data = [x.data for x in selected] assert any(th.all(th.eq(tensor1, d_)) for d_ in selected_data) assert any(th.all(th.eq(tensor2, d_)) for d_ in selected_data) assert len(selected_data) == 2