Skip to content

Commit f995daa

Browse files
committed
Update test_expire_snapshots.py
1 parent 5f0b62b commit f995daa

File tree

1 file changed

+8
-27
lines changed

1 file changed

+8
-27
lines changed

tests/table/test_expire_snapshots.py

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from pyiceberg.table import Table
77
from pyiceberg.table.metadata import new_table_metadata
88
from pyiceberg.table.snapshots import Snapshot, SnapshotLogEntry
9-
from pyiceberg.table.update.snapshot import ExpireSnapshots
9+
from pyiceberg.table.update.snapshot import ManageSnapshots
1010

1111
from pyiceberg.schema import Schema
1212
from pyiceberg.partitioning import PartitionSpec
@@ -64,33 +64,14 @@ def test_expire_snapshots_removes_correct_snapshots(mock_table: Mock):
6464
"""
6565
Test case for the `ExpireSnapshots` class to ensure that the correct snapshots
6666
are removed and the delete function is called the expected number of times.
67-
Args:
68-
mock_table (Mock): A mock object representing the table.
69-
Test Steps:
70-
1. Create a mock delete function and a mock transaction.
71-
2. Instantiate the `ExpireSnapshots` class with the mock transaction.
72-
3. Configure the `ExpireSnapshots` instance to expire snapshots with IDs 1 and 2,
73-
and set the delete function to the mock delete function.
74-
4. Commit the changes using the `_commit` method with the mock table's metadata.
75-
5. Validate that the mock delete function is called for the correct snapshots.
76-
6. Verify that the delete function is called exactly twice.
77-
7. Ensure that the updated metadata returned by `_commit` is not `None`.
78-
"""
79-
mock_delete_func = Mock()
80-
mock_transaction = Mock()
8167
82-
expire_snapshots = ExpireSnapshots(mock_transaction)
83-
expire_snapshots \
84-
.expire_snapshot_id(1) \
85-
.expire_snapshot_id(2) \
86-
.delete_with(mock_delete_func)
68+
"""
8769

88-
updated_metadata = expire_snapshots._commit(mock_table.metadata)
70+
with ManageSnapshots(mock_table) as transaction:
71+
# Mock the transaction to return the mock table
72+
transaction.exipre_snapshot_by_id(1).exipre_snapshot_by_id(2).expire_snapshots().cleanup_files()
8973

90-
# Validate delete calls
91-
mock_delete_func.assert_any_call(mock_table.return_value.snapshots[0])
92-
mock_delete_func.assert_any_call(mock_table.metadata.snapshots[1])
93-
assert mock_delete_func.call_count == 2
9474

95-
# Verify updated metadata returned
96-
assert updated_metadata is not None
75+
for snapshot in mock_table.metadata.snapshots:
76+
# Verify that the snapshot is removed from the metadata
77+
assert snapshot.snapshot_id not in [1, 2]

0 commit comments

Comments
 (0)