Esempio n. 1
0
def test_protect_from_overwrite_write_functions(tmp_path: Path):
    """Raise FileExistsError if file exists."""

    file_path = tmp_path / "dummy.foo"
    file_path.touch()

    with pytest.raises(FileExistsError, match="The file .+? already exists"):
        save_dataset(xr.DataArray([1, 2]), str(file_path))  # type:ignore
Esempio n. 2
0
def test_write_dataset_error(tmp_path: Path):
    """Raise ValueError if method isn't implemented in the DataIo class."""
    file_path = tmp_path / "dummy.foo"

    with pytest.raises(ValueError,
                       match="Cannot save data with format: 'foo'"):
        save_dataset(str(file_path), "", "foo")  # type:ignore

    file_path.touch()

    with pytest.raises(ValueError,
                       match="Cannot read data with format: 'foo'"):
        load_dataset(str(file_path))
Esempio n. 3
0
def test_write_dataset(tmp_path: Path):
    """All args and kwargs are passes correctly."""
    file_path = tmp_path / "dummy.mock"

    result: dict[str, Any] = {}
    save_dataset(
        xr.DataArray([1, 2]),
        file_path,
        result_container=result,
        dummy_arg="baz",
    )

    assert len(result) == 3
    assert result["file_name"] == file_path.as_posix()
    assert result["dummy_arg"] == "baz"
    assert np.all(result["dataset"] == xr.DataArray([1, 2]))
Esempio n. 4
0
def test_write_dataset(tmp_path: Path):
    """All args and kwargs are passes correctly."""
    file_path = tmp_path / "dummy.mock"

    result: dict[str, Any] = {}
    save_dataset(
        str(file_path),
        "no_dataset",  # type:ignore
        result_container=result,
        dummy_arg="baz",
    )

    assert result == {
        "file_name": str(file_path),
        "dataset": "no_dataset",
        "dummy_arg": "baz",
    }