Skip to content

Commit 875b517

Browse files
Update error message in ParticleFile writing (#2698)
* Update error message in ParticleFile writing * Add test
1 parent 1bf140a commit 875b517

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/parcels/_core/particlefile.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,13 @@ def __init__(
106106

107107
if path.exists():
108108
if mode is None:
109-
raise ValueError(f"{path=!r} already exists. Use mode='w' or use a new path.")
109+
msg = f"Path '{path}' already exists. Use mode='w' or use a new path."
110+
raise ValueError(msg)
110111
if mode == "w":
111112
path.unlink()
112113
if not path.parent.exists():
113-
raise ValueError(f"Folder location for {path=!r} does not exist. Create the folder location first.")
114+
msg = f"Folder location for '{path} does not exist. Create the folder location first."
115+
raise ValueError(msg)
114116

115117
self.metadata = {}
116118

tests/test_particlefile.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,18 @@ def test_particlefile_init_existing_path_modes(fieldset, tmp_parquet):
431431
assert len(df_first) == len(df_overwrite)
432432

433433

434+
def test_particlefile_init_existing_path_no_mode(tmp_parquet):
435+
tmp_parquet.touch()
436+
with pytest.raises(ValueError, match="already exists"):
437+
ParticleFile(tmp_parquet, outputdt=np.timedelta64(1, "s"))
438+
439+
440+
def test_particlefile_init_nonexistent_parent(tmp_path):
441+
path = tmp_path / "nonexistent_dir" / "file.parquet"
442+
with pytest.raises(ValueError, match="does not exist"):
443+
ParticleFile(path, outputdt=np.timedelta64(1, "s"))
444+
445+
434446
def test_particlefile_init_invalid_mode(tmp_parquet):
435447
with pytest.raises(ValueError, match="Invalid mode value"):
436448
ParticleFile(tmp_parquet, outputdt=np.timedelta64(1, "s"), mode="something-else")

0 commit comments

Comments
 (0)