def test_http_filesystem_no_versioning(self):
        pattern = r"HTTP\(s\) DataSet doesn't support versioning\."

        with pytest.raises(DataSetError, match=pattern):
            ImageDataSet(
                filepath="https://example.com/file.png", version=Version(None, None)
            )
Exemple #2
0
    def test_protocol_usage(self, filepath, instance_type):
        data_set = ImageDataSet(filepath=filepath)
        assert isinstance(data_set._fs, instance_type)

        path = filepath.split(PROTOCOL_DELIMITER, 1)[-1]

        assert str(data_set._filepath) == path
        assert isinstance(data_set._filepath, PurePosixPath)
    def test_version_str_repr(self, load_version, save_version):
        """Test that version is in string representation of the class instance
        when applicable."""
        filepath = "/tmp/test.png"
        ds = ImageDataSet(filepath=filepath)
        ds_versioned = ImageDataSet(filepath=filepath,
                                    version=Version(load_version,
                                                    save_version))
        assert filepath in str(ds)
        assert filepath in str(ds_versioned)

        assert "version" not in str(ds)
        ver_str = f"version=Version(load={load_version}, save='{save_version}')"
        assert ver_str in str(ds_versioned)
        assert "ImageDataSet" in str(ds_versioned)
        assert "ImageDataSet" in str(ds)
        assert "protocol" in str(ds_versioned)
        assert "protocol" in str(ds)
    def test_multiple_loads(self, versioned_image_dataset, image_object,
                            filepath_png):
        """Test that if a new version is created mid-run, by an
        external system, it won't be loaded in the current run."""
        versioned_image_dataset.save(image_object)
        v1 = versioned_image_dataset.resolve_load_version()

        # force-drop a newer version into the same location
        v_new = generate_timestamp()
        ImageDataSet(filepath=filepath_png,
                     version=Version(v_new, v_new)).save(image_object)

        v2 = versioned_image_dataset.resolve_load_version()

        assert v2 == v1  # v2 should not be v_new!
        ds_new = ImageDataSet(filepath=filepath_png,
                              version=Version(None, None))
        assert (ds_new.resolve_load_version() == v_new
                )  # new version is discoverable by a new instance
    def test_protocol_usage(self, filepath, instance_type):
        data_set = ImageDataSet(filepath=filepath)
        assert isinstance(data_set._fs, instance_type)

        # _strip_protocol() doesn't strip http(s) protocol
        if data_set._protocol == "https":
            path = filepath.split("://")[-1]
        else:
            path = data_set._fs._strip_protocol(filepath)

        assert str(data_set._filepath) == path
        assert isinstance(data_set._filepath, PurePosixPath)
Exemple #6
0
def versioned_image_dataset(filepath_png, load_version, save_version):
    return ImageDataSet(filepath=filepath_png,
                        version=Version(load_version, save_version))
Exemple #7
0
def image_dataset(filepath_png, save_args, fs_args):
    return ImageDataSet(filepath=filepath_png,
                        save_args=save_args,
                        fs_args=fs_args)
Exemple #8
0
 def test_catalog_release(self, mocker):
     fs_mock = mocker.patch("fsspec.filesystem").return_value
     filepath = "test.png"
     data_set = ImageDataSet(filepath=filepath)
     data_set.release()
     fs_mock.invalidate_cache.assert_called_once_with(filepath)
Exemple #9
0
def affiche_image(rawda):
    data_set = ImageDataSet(filepath="data/01_raw/elephant.jpg")
    image = data_set.load()
    image.show()