Skip to content

Commit 4a29a49

Browse files
committed
MAINT: Handle empty manifest files
1 parent ee50e8b commit 4a29a49

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/fmu/dataio/manifest/_models.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ def __len__(self) -> int:
3737
def from_file(cls, manifest_path: Path) -> Self:
3838
"""Load the export manifest from the JSON file."""
3939
with manifest_path.open("r", encoding="utf-8") as file:
40-
return cls.model_validate(json.load(file))
40+
content = file.read()
41+
42+
if not content.strip():
43+
return cls()
44+
45+
return cls.model_validate(json.loads(content))
4146

4247
def add_entry(self, absolute_path: Path) -> None:
4348
"""Append a new file to the manifest."""

tests/test_units/test_manifest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ def test_export_manifest_from_file_not_exist(tmp_path: Path) -> None:
4949
ExportManifest.from_file(tmp_path / MANIFEST_FILENAME)
5050

5151

52+
def test_export_manifest_from_empty_file(tmp_path: Path) -> None:
53+
"""Test that an empty manifest file is loaded as a new manifest."""
54+
manifest_path = tmp_path / MANIFEST_FILENAME
55+
manifest_path.touch()
56+
57+
manifest = ExportManifest.from_file(manifest_path)
58+
59+
assert len(manifest) == 0
60+
61+
5262
def test_get_manifest_path_realization_context(runpath_no_dotfmu: Path) -> None:
5363
"""Test that the manifest path is correctly derived in a realization context."""
5464
# check test assumption that the fixture points to the runpath

0 commit comments

Comments
 (0)