def test_object_attrs(setup_teardown_folder): obj = Object(setup_teardown_folder[2], pathlib.PurePosixPath(""), "test_object", io_mode=None) _create_object_directory(setup_teardown_folder[2], DATASET_TYPENAME) _create_object_directory(setup_teardown_folder[2] / "test_object", GROUP_TYPENAME) assert isinstance(obj.attrs, Attribute) assert obj.attrs.mode.value == 1 obj.attrs = "test value" assert is_nonraw_object_directory(setup_teardown_folder[2] / "test_object") with (setup_teardown_folder[2] / "test_object" / ATTRIBUTES_FILENAME).open("r") as meta_file: meta_data = yaml.safe_load(meta_file) assert meta_data == "test value"
def test_file_init(setup_teardown_folder): no_exdir = setup_teardown_folder[0] / "no_exdir" f = File(no_exdir, mode="w") f.close() assert is_nonraw_object_directory(no_exdir.with_suffix(".exdir")) remove(setup_teardown_folder[1]) f = File(setup_teardown_folder[1], mode="w") f.close() assert is_nonraw_object_directory(setup_teardown_folder[1]) remove(setup_teardown_folder[1]) f = File(setup_teardown_folder[1], mode="a") f.close() assert is_nonraw_object_directory(setup_teardown_folder[1]) remove(setup_teardown_folder[1]) f = File(setup_teardown_folder[1], mode="a") f.close() assert is_nonraw_object_directory(setup_teardown_folder[1]) remove(setup_teardown_folder[1]) setup_teardown_folder[1].mkdir(parents=True) with pytest.raises(FileExistsError): f = File(setup_teardown_folder[1], mode="w") remove(setup_teardown_folder[1]) _create_object_directory(pathlib.Path(setup_teardown_folder[1]), exob._default_metadata(DATASET_TYPENAME)) with pytest.raises(FileExistsError): f = File(setup_teardown_folder[1], mode="w") remove(setup_teardown_folder[1]) with pytest.raises(IOError): f = File(setup_teardown_folder[1], mode="r") with pytest.raises(IOError): f = File(setup_teardown_folder[1], mode="r+") _create_object_directory(pathlib.Path(setup_teardown_folder[1]), exob._default_metadata(FILE_TYPENAME)) with pytest.raises(FileExistsError): f = File(setup_teardown_folder[1], mode="w") remove(setup_teardown_folder[1]) _create_object_directory(pathlib.Path(setup_teardown_folder[1]), exob._default_metadata(FILE_TYPENAME)) f = File(setup_teardown_folder[1], mode="w", allow_remove=True) remove(setup_teardown_folder[1]) _create_object_directory(pathlib.Path(setup_teardown_folder[1]), exob._default_metadata(FILE_TYPENAME)) with pytest.raises(IOError): f = File(setup_teardown_folder[1], mode="w-") with pytest.raises(IOError): f = File(setup_teardown_folder[1], mode="x") with pytest.raises(ValueError): f = File(setup_teardown_folder[1], mode="not existing")
def test_is_nonraw_object_directory(setup_teardown_folder): setup_teardown_folder[2].mkdir() result = exob.is_nonraw_object_directory(setup_teardown_folder[2]) assert result is False compare_metafile = setup_teardown_folder[2] / exob.META_FILENAME with compare_metafile.open("w", encoding="utf-8") as f: pass result = exob.is_nonraw_object_directory(setup_teardown_folder[2]) assert result is False remove(setup_teardown_folder[1]) with compare_metafile.open("w", encoding="utf-8") as meta_file: metadata = { exob.EXDIR_METANAME: { exob.VERSION_METANAME: 1} } yaml.safe_dump(metadata, meta_file, default_flow_style=False, allow_unicode=True) result = exob.is_nonraw_object_directory(setup_teardown_folder[2]) assert result is False remove(setup_teardown_folder[1]) with compare_metafile.open("w", encoding="utf-8") as meta_file: metadata = { exob.EXDIR_METANAME: { exob.TYPE_METANAME: "wrong_typename", exob.VERSION_METANAME: 1} } yaml.safe_dump(metadata, meta_file, default_flow_style=False, allow_unicode=True) result = exob.is_nonraw_object_directory(setup_teardown_folder[2]) assert result is False remove(setup_teardown_folder[1]) with compare_metafile.open("w", encoding="utf-8") as meta_file: metadata = { exob.EXDIR_METANAME: { exob.TYPE_METANAME: exob.DATASET_TYPENAME, exob.VERSION_METANAME: 1} } yaml.safe_dump(metadata, meta_file, default_flow_style=False, allow_unicode=True) result = exob.is_nonraw_object_directory(setup_teardown_folder[2]) assert result is True remove(setup_teardown_folder[2]) exob._create_object_directory(pathlib.Path(setup_teardown_folder[2]), exob._default_metadata(exob.DATASET_TYPENAME)) result = exob.is_nonraw_object_directory(setup_teardown_folder[2]) assert result is True