Ejemplo n.º 1
0
    def test_save_data(
        self,
        dummy_data,
        tmp_path,
        filepath_json,
        save_version,
    ):
        """Test saving and reloading the data set."""
        metrics_dataset = MetricsDataSet(filepath=filepath_json,
                                         version=Version(None, save_version))
        metrics_dataset.save(dummy_data)

        actual_filepath = Path(metrics_dataset._filepath.as_posix())
        test_filepath = tmp_path / "locally_saved.json"

        test_filepath.parent.mkdir(parents=True, exist_ok=True)
        with open(test_filepath, "w", encoding="utf-8") as file:
            json.dump(dummy_data, file)

        with open(test_filepath, encoding="utf-8") as file:
            test_data = json.load(file)

        with open((actual_filepath / save_version / "test.json"),
                  encoding="utf-8") as actual_file:
            actual_data = json.load(actual_file)

        assert actual_data == test_data
        assert metrics_dataset._fs_open_args_load == {}
        assert metrics_dataset._fs_open_args_save == {"mode": "w"}
Ejemplo n.º 2
0
    def test_protocol_usage(self, filepath, instance_type):
        data_set = MetricsDataSet(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)
Ejemplo n.º 3
0
    def test_not_version_str_repr(self):
        """Test that version is not in string representation of the class instance."""
        filepath = "test.json"
        ds = MetricsDataSet(filepath=filepath)

        assert filepath in str(ds)
        assert "version" not in str(ds)
        assert "MetricsDataSet" in str(ds)
        assert "protocol" in str(ds)
        # Default save_args
        assert "save_args={'indent': 2}" in str(ds)
Ejemplo n.º 4
0
    def test_version_str_repr(self):
        """Test that version is in string representation of the class instance
        when applicable."""
        filepath = "test.json"
        ds_versioned = MetricsDataSet(filepath=filepath)

        assert filepath in str(ds_versioned)
        ver_str = "version=Version(load=None, save=None)"
        assert ver_str in str(ds_versioned)
        assert "MetricsDataSet" in str(ds_versioned)
        assert "protocol" in str(ds_versioned)
        # Default save_args
        assert "save_args={'indent': 2}" in str(ds_versioned)
Ejemplo n.º 5
0
    def test_version_str_repr(self, load_version, save_version):
        """Test that version is in string representation of the class instance."""
        filepath = "test.json"
        ds_versioned = MetricsDataSet(filepath=filepath,
                                      version=Version(load_version,
                                                      save_version))

        assert filepath in str(ds_versioned)
        ver_str = f"version=Version(load={load_version}, save='{save_version}')"
        assert ver_str in str(ds_versioned)
        assert "MetricsDataSet" in str(ds_versioned)
        assert "protocol" in str(ds_versioned)
        # Default save_args
        assert "save_args={'indent': 2}" in str(ds_versioned)
Ejemplo n.º 6
0
def explicit_versioned_metrics_dataset(filepath_json, load_version,
                                       save_version):
    return MetricsDataSet(filepath=filepath_json,
                          version=Version(load_version, save_version))
Ejemplo n.º 7
0
    def test_http_filesystem_no_versioning(self):
        pattern = r"HTTP\(s\) DataSet doesn't support versioning\."

        with pytest.raises(DataSetError, match=pattern):
            MetricsDataSet(filepath="https://example.com/file.json",
                           version=Version(None, None))
Ejemplo n.º 8
0
def metrics_dataset(filepath_json, save_args, fs_args):
    return MetricsDataSet(filepath=filepath_json,
                          save_args=save_args,
                          fs_args=fs_args)
Ejemplo n.º 9
0
 def test_catalog_release(self, mocker):
     fs_mock = mocker.patch("fsspec.filesystem").return_value
     filepath = "test.json"
     data_set = MetricsDataSet(filepath=filepath)
     data_set.release()
     fs_mock.invalidate_cache.assert_called_once_with(filepath)