def test_load_require_schema(backend): schema_node = schema.Bool() storage = frontend.create(backend.storage_path, schema_node) storage.data.value = True storage.save() frontend.load(backend.storage_path, required_schema=schema_node)
def storage_path_existing(self, request, tmpdir): storage_path = str(tmpdir.join('test_pseudo.' + request.param)) storage = frontend.create(storage_path, schema.Bool()) storage.data.value = True storage.save() del storage return storage_path
def test_create_from(backend, foreign_backend): schema_node = schema.Bool() source_storage = frontend.create(foreign_backend.storage_path, schema_node) source_storage.data.value = True dest_storage = frontend.create_from(backend.storage_path, source_storage) assert dest_storage.schema_node.hash() == source_storage.schema_node.hash() assert dest_storage.data.value is True
def test_load(backend): schema_node = schema.Bool() storage = frontend.create(backend.storage_path, schema_node) storage.data.value = True storage.save() new_storage = frontend.load(backend.storage_path) assert isinstance(new_storage, backend.module.Storage) assert new_storage.data.value is True
def test_load_validation_fail(backend): schema_node = schema.String(max_length=3) storage = frontend.create(backend.storage_path, schema_node) storage.data.value = 'spam' storage.save(force=True) with pytest.raises(exceptions.ValidationError): frontend.load(backend.storage_path) # With force=True, no exception must be raised. frontend.load(backend.storage_path, force=True)
def storage_path(self, request, tmpdir): """Prepare storage path for all valid variants. Variants are tuples ``(backend, existing)``, where ``existing`` indicates whether a storage should be created before the test. """ backend, existing = request.param if backend in ('hdf5', 'npz', 'mat'): # File backends storage_path = str(tmpdir.join('test_pseudo.' + backend)) elif backend == '::inmem::': storage_path = '::inmem::' if existing: storage = frontend.create(storage_path, schema.Bool()) storage.data.value = True if hasattr(storage, 'save') and callable(storage.save): storage.save() del storage return storage_path
def test_create_inmem(): schema_node = schema.Bool() storage = frontend.create('::inmem::', schema_node) assert isinstance(storage, inmem.Storage) assert storage.schema_node == schema_node
def test_create(backend): schema_node = schema.Bool() storage = frontend.create(backend.storage_path, schema_node) assert isinstance(storage, backend.module.Storage) assert storage.schema_node == schema_node
def storage(self, foreign_backend): schema_node = schema.Compilation({ 'spam': schema.Bool(), 'eggs': schema.Bytes(), }) return frontend.create(foreign_backend.storage_path, schema_node)