diff --git a/src/parcels/_core/particlefile.py b/src/parcels/_core/particlefile.py index 7a3fc9d64..0c9173bdf 100644 --- a/src/parcels/_core/particlefile.py +++ b/src/parcels/_core/particlefile.py @@ -106,11 +106,13 @@ def __init__( if path.exists(): if mode is None: - raise ValueError(f"{path=!r} already exists. Use mode='w' or use a new path.") + msg = f"Path '{path}' already exists. Use mode='w' or use a new path." + raise ValueError(msg) if mode == "w": path.unlink() if not path.parent.exists(): - raise ValueError(f"Folder location for {path=!r} does not exist. Create the folder location first.") + msg = f"Folder location for '{path} does not exist. Create the folder location first." + raise ValueError(msg) self.metadata = {} diff --git a/tests/test_particlefile.py b/tests/test_particlefile.py index dc0e232c1..c98385d48 100755 --- a/tests/test_particlefile.py +++ b/tests/test_particlefile.py @@ -431,6 +431,18 @@ def test_particlefile_init_existing_path_modes(fieldset, tmp_parquet): assert len(df_first) == len(df_overwrite) +def test_particlefile_init_existing_path_no_mode(tmp_parquet): + tmp_parquet.touch() + with pytest.raises(ValueError, match="already exists"): + ParticleFile(tmp_parquet, outputdt=np.timedelta64(1, "s")) + + +def test_particlefile_init_nonexistent_parent(tmp_path): + path = tmp_path / "nonexistent_dir" / "file.parquet" + with pytest.raises(ValueError, match="does not exist"): + ParticleFile(path, outputdt=np.timedelta64(1, "s")) + + def test_particlefile_init_invalid_mode(tmp_parquet): with pytest.raises(ValueError, match="Invalid mode value"): ParticleFile(tmp_parquet, outputdt=np.timedelta64(1, "s"), mode="something-else")