ForeverAngry commented on code in PR #1880:
URL: https://github.com/apache/iceberg-python/pull/1880#discussion_r2053170133


##########
tests/table/test_expire_snapshots.py:
##########
@@ -0,0 +1,43 @@
+from unittest.mock import MagicMock
+from uuid import uuid4
+
+from pyiceberg.table import CommitTableResponse, Table
+
+
+def test_expire_snapshot(table_v2: Table) -> None:
+    EXPIRE_SNAPSHOT = 3051729675574597004
+    KEEP_SNAPSHOT = 3055729675574597004
+    # Mock the catalog's commit_table method
+    mock_response = CommitTableResponse(
+        # Use the table's current metadata but keep only the snapshot not to 
be expired
+        metadata=table_v2.metadata.model_copy(update={"snapshots": 
[KEEP_SNAPSHOT]}),
+        metadata_location="mock://metadata/location",
+        uuid=uuid4(),
+    )
+
+    # Mock the commit_table method to return the mock response
+    table_v2.catalog.commit_table = MagicMock(return_value=mock_response)
+
+    # Print snapshot IDs for debugging
+    print(f"Snapshot IDs before expiration: {[snapshot.snapshot_id for 
snapshot in table_v2.metadata.snapshots]}")
+
+    # Assert fixture data to validate test assumptions
+    assert len(table_v2.metadata.snapshots) == 2
+    assert len(table_v2.metadata.snapshot_log) == 2
+    assert len(table_v2.metadata.refs) == 2
+
+    # Expire the snapshot directly without using a transaction
+    try:
+        
table_v2.manage_snapshots().expire_snapshot_by_id(EXPIRE_SNAPSHOT).commit()

Review Comment:
   updated the class for the changes in the the snapshot.py file.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to