Skip to content

Commit 41eb549

Browse files
committed
test: Fix cast errors
1 parent 87f6848 commit 41eb549

File tree

1 file changed

+25
-21
lines changed

1 file changed

+25
-21
lines changed

tests/table/test_replace.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17+
from typing import cast
1718
import pytest
1819
from pyiceberg.catalog import Catalog
1920
from pyiceberg.manifest import (
@@ -25,7 +26,7 @@
2526
ManifestEntryStatus,
2627
)
2728
from pyiceberg.schema import Schema
28-
from pyiceberg.table.snapshots import Operation
29+
from pyiceberg.table.snapshots import Operation, Snapshot, Summary
2930
from pyiceberg.typedef import Record
3031

3132

@@ -76,18 +77,19 @@ def test_replace_internally(catalog: Catalog) -> None:
7677
append_snapshot.append_data_file(file_to_delete)
7778
append_snapshot.append_data_file(file_to_keep)
7879

79-
old_snapshot = table.current_snapshot()
80+
old_snapshot = cast(Snapshot, table.current_snapshot())
8081
old_snapshot_id = old_snapshot.snapshot_id
81-
old_sequence_number = old_snapshot.sequence_number
82+
old_sequence_number = cast(int, old_snapshot.sequence_number)
8283

8384
# Call the internal replace API
8485
with table.transaction() as tx:
8586
with tx.update_snapshot().replace() as rewrite:
8687
rewrite.delete_data_file(file_to_delete)
8788
rewrite.append_data_file(file_to_add)
8889

89-
snapshot = table.current_snapshot()
90-
90+
snapshot = cast(Snapshot, table.current_snapshot())
91+
summary = cast(Summary, snapshot.summary)
92+
9193
# 1. Has a unique snapshot ID
9294
assert snapshot.snapshot_id is not None
9395
assert snapshot.snapshot_id != old_snapshot_id
@@ -99,22 +101,22 @@ def test_replace_internally(catalog: Catalog) -> None:
99101
assert snapshot.sequence_number == old_sequence_number + 1
100102

101103
# 4. Operation type is set to "replace"
102-
assert snapshot.summary["operation"] == Operation.REPLACE
104+
assert summary["operation"] == Operation.REPLACE
103105

104106
# 5. Manifest list path is correct (just verify it exists and is a string path)
105107
assert snapshot.manifest_list is not None
106108
assert isinstance(snapshot.manifest_list, str)
107109

108110
# 6. Summary counts are accurate
109-
assert snapshot.summary["added-data-files"] == "1"
110-
assert snapshot.summary["deleted-data-files"] == "1"
111-
assert snapshot.summary["added-records"] == "100"
112-
assert snapshot.summary["deleted-records"] == "100"
113-
assert snapshot.summary["total-records"] == "150"
111+
assert summary["added-data-files"] == "1"
112+
assert summary["deleted-data-files"] == "1"
113+
assert summary["added-records"] == "100"
114+
assert summary["deleted-records"] == "100"
115+
assert summary["total-records"] == "150"
114116

115117
# Fetch all entries from the new manifests
116118
manifest_files = snapshot.manifests(table.io)
117-
entries = []
119+
entries: list[ManifestEntry] = []
118120
for manifest in manifest_files:
119121
entries.extend(manifest.fetch_manifest_entry(table.io, discard_deleted=False))
120122

@@ -188,7 +190,7 @@ def test_replace_reuses_unaffected_manifests(catalog: Catalog) -> None:
188190
with tx.update_snapshot().fast_append() as append_snapshot:
189191
append_snapshot.append_data_file(file_b)
190192

191-
snapshot_before = table.current_snapshot()
193+
snapshot_before = cast(Snapshot, table.current_snapshot())
192194
manifests_before = snapshot_before.manifests(table.io)
193195
assert len(manifests_before) == 2
194196

@@ -211,7 +213,7 @@ def test_replace_reuses_unaffected_manifests(catalog: Catalog) -> None:
211213
rewrite.delete_data_file(file_a)
212214
rewrite.append_data_file(file_c)
213215

214-
snapshot_after = table.current_snapshot()
216+
snapshot_after = cast(Snapshot, table.current_snapshot())
215217
assert snapshot_after is not None
216218
manifests_after = snapshot_after.manifests(table.io)
217219

@@ -367,10 +369,12 @@ def test_replace_allows_shrinking_for_soft_deletes(catalog: Catalog) -> None:
367369
rewrite.delete_data_file(file_to_delete)
368370
rewrite.append_data_file(shrunk_file_to_add)
369371

370-
snapshot = table.current_snapshot()
371-
assert snapshot.summary["operation"] == Operation.REPLACE
372-
assert snapshot.summary["added-records"] == "90"
373-
assert snapshot.summary["deleted-records"] == "100"
372+
snapshot = cast(Snapshot, table.current_snapshot())
373+
summary = cast(Summary, snapshot.summary)
374+
375+
assert summary["operation"] == Operation.REPLACE
376+
assert summary["added-records"] == "90"
377+
assert summary["deleted-records"] == "100"
374378

375379

376380
def test_replace_passes_through_delete_manifests(catalog: Catalog) -> None:
@@ -425,9 +429,9 @@ def test_replace_passes_through_delete_manifests(catalog: Catalog) -> None:
425429
append_snapshot.append_data_file(file_a_deletes)
426430

427431
# Find the path of the delete manifest so we can verify it survives
428-
snapshot_before = table.current_snapshot()
432+
snapshot_before = cast(Snapshot, table.current_snapshot())
429433
manifests_before = snapshot_before.manifests(table.io)
430-
434+
431435
delete_manifest_path = None
432436
for m in manifests_before:
433437
if m.content == ManifestContent.DELETES:
@@ -442,7 +446,7 @@ def test_replace_passes_through_delete_manifests(catalog: Catalog) -> None:
442446
rewrite.append_data_file(file_b)
443447

444448
# Verify the delete manifest was passed through unchanged
445-
snapshot_after = table.current_snapshot()
449+
snapshot_after = cast(Snapshot, table.current_snapshot())
446450
assert snapshot_after is not None
447451
manifests_after = snapshot_after.manifests(table.io)
448452
manifest_paths_after = [m.manifest_path for m in manifests_after]

0 commit comments

Comments
 (0)