|
6 | 6 | from pyiceberg.table import Table
|
7 | 7 | from pyiceberg.table.metadata import new_table_metadata
|
8 | 8 | from pyiceberg.table.snapshots import Snapshot, SnapshotLogEntry
|
9 |
| -from pyiceberg.table.update.snapshot import ExpireSnapshots |
| 9 | +from pyiceberg.table.update.snapshot import ManageSnapshots |
10 | 10 |
|
11 | 11 | from pyiceberg.schema import Schema
|
12 | 12 | from pyiceberg.partitioning import PartitionSpec
|
@@ -64,33 +64,14 @@ def test_expire_snapshots_removes_correct_snapshots(mock_table: Mock):
|
64 | 64 | """
|
65 | 65 | Test case for the `ExpireSnapshots` class to ensure that the correct snapshots
|
66 | 66 | 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() |
81 | 67 |
|
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 | + """ |
87 | 69 |
|
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() |
89 | 73 |
|
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 |
94 | 74 |
|
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