Skip to content

Commit a74d7a9

Browse files
committed
add test that ensures we raise an error
1 parent e2bba3f commit a74d7a9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/table/test_validate.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,33 @@ def test_validation_history_fails_on_snapshot_with_no_summary(
106106
{Operation.APPEND},
107107
ManifestContent.DATA,
108108
)
109+
110+
111+
def test_validation_history_fails_on_from_snapshot_not_matching_last_snapshot(
112+
table_v2_with_extensive_snapshots_and_manifests: tuple[Table, dict[int, list[ManifestFile]]],
113+
) -> None:
114+
"""Test the validation history function fails when from_snapshot doesn't match last_snapshot."""
115+
table, mock_manifests = table_v2_with_extensive_snapshots_and_manifests
116+
117+
oldest_snapshot = table.snapshots()[0]
118+
newest_snapshot = cast(Snapshot, table.current_snapshot())
119+
120+
def mock_read_manifest_side_effect(self: Snapshot, io: FileIO) -> list[ManifestFile]:
121+
"""Mock the manifests method to use the snapshot_id for lookup."""
122+
snapshot_id = self.snapshot_id
123+
if snapshot_id in mock_manifests:
124+
return mock_manifests[snapshot_id]
125+
return []
126+
127+
missing_oldest_snapshot = table.snapshots()[1:]
128+
129+
with patch("pyiceberg.table.snapshots.Snapshot.manifests", new=mock_read_manifest_side_effect):
130+
with patch("pyiceberg.table.update.validate.ancestors_between", return_value=missing_oldest_snapshot):
131+
with pytest.raises(ValidationException):
132+
validation_history(
133+
table,
134+
newest_snapshot,
135+
oldest_snapshot,
136+
{Operation.APPEND},
137+
ManifestContent.DATA,
138+
)

0 commit comments

Comments
 (0)