18
18
19
19
from pyiceberg .catalog import Catalog
20
20
from pyiceberg .table .refs import SnapshotRef
21
+ from pyiceberg .table .snapshots import ancestors_of
21
22
22
23
23
24
@pytest .mark .integration
@@ -54,7 +55,7 @@ def test_manage_snapshots_context_manager(catalog: Catalog) -> None:
54
55
ms .create_tag (snapshot_id = current_snapshot_id , tag_name = "testing" )
55
56
ms .set_current_snapshot (snapshot_id = expected_snapshot_id )
56
57
ms .create_branch (snapshot_id = expected_snapshot_id , branch_name = "testing2" )
57
- assert tbl .current_snapshot ().snapshot_id is not current_snapshot_id # type: ignore
58
+ assert tbl .current_snapshot ().snapshot_id != current_snapshot_id # type: ignore
58
59
assert tbl .metadata .refs ["testing" ].snapshot_id == current_snapshot_id
59
60
assert tbl .metadata .refs ["main" ] == SnapshotRef (snapshot_id = expected_snapshot_id , snapshot_ref_type = "branch" )
60
61
assert tbl .metadata .refs ["testing2" ].snapshot_id == expected_snapshot_id
@@ -69,7 +70,7 @@ def test_rollback_to_snapshot(catalog: Catalog) -> None:
69
70
rollback_snapshot_id = tbl .current_snapshot ().parent_snapshot_id # type: ignore
70
71
current_snapshot_id = tbl .current_snapshot ().snapshot_id # type: ignore
71
72
tbl .manage_snapshots ().rollback_to_snapshot (snapshot_id = rollback_snapshot_id ).commit () # type: ignore
72
- assert tbl .current_snapshot ().snapshot_id is not current_snapshot_id # type: ignore
73
+ assert tbl .current_snapshot ().snapshot_id != current_snapshot_id # type: ignore
73
74
assert tbl .metadata .refs ["main" ] == SnapshotRef (snapshot_id = rollback_snapshot_id , snapshot_ref_type = "branch" )
74
75
75
76
@@ -79,11 +80,11 @@ def test_rollback_to_timestamp(catalog: Catalog) -> None:
79
80
identifier = "default.test_table_rollback_to_snapshot_id"
80
81
tbl = catalog .load_table (identifier )
81
82
assert len (tbl .history ()) > 4
82
- current_snapshot_id , timestamp = tbl .history ()[- 1 ].snapshot_id , tbl .history ()[- 1 ].timestamp_ms
83
- expected_snapshot_id = tbl .snapshot_by_id (current_snapshot_id ).parent_snapshot_id # type: ignore
83
+ ancestors = list (ancestor for ancestor in ancestors_of (tbl .current_snapshot (), tbl .metadata )) # noqa
84
+ ancestor_to_rollback_to = ancestors [- 1 ]
85
+ expected_snapshot_id , timestamp = ancestor_to_rollback_to .snapshot_id , ancestor_to_rollback_to .timestamp_ms + 1
84
86
# not inclusive of rollback_timestamp
85
87
tbl .manage_snapshots ().rollback_to_timestamp (timestamp = timestamp ).commit ()
86
- assert tbl .current_snapshot ().snapshot_id is not current_snapshot_id # type: ignore
87
88
assert tbl .metadata .refs ["main" ] == SnapshotRef (snapshot_id = expected_snapshot_id , snapshot_ref_type = "branch" )
88
89
89
90
@@ -96,7 +97,7 @@ def test_set_current_snapshot_with_snapshot_id(catalog: Catalog) -> None:
96
97
current_snapshot_id = tbl .current_snapshot ().snapshot_id # type: ignore
97
98
expected_snapshot_id = tbl .history ()[- 3 ].snapshot_id
98
99
tbl .manage_snapshots ().set_current_snapshot (snapshot_id = expected_snapshot_id ).commit ()
99
- assert tbl .current_snapshot ().snapshot_id is not current_snapshot_id # type: ignore
100
+ assert tbl .current_snapshot ().snapshot_id != current_snapshot_id # type: ignore
100
101
assert tbl .metadata .refs ["main" ] == SnapshotRef (snapshot_id = expected_snapshot_id , snapshot_ref_type = "branch" )
101
102
102
103
@@ -110,5 +111,5 @@ def test_set_current_snapshot_with_ref_name(catalog: Catalog) -> None:
110
111
expected_snapshot_id = tbl .history ()[- 3 ].snapshot_id
111
112
tbl .manage_snapshots ().create_tag (snapshot_id = expected_snapshot_id , tag_name = "test-tag" ).commit ()
112
113
tbl .manage_snapshots ().set_current_snapshot (ref_name = "test-tag" ).commit ()
113
- assert tbl .current_snapshot ().snapshot_id is not current_snapshot_id # type: ignore
114
+ assert tbl .current_snapshot ().snapshot_id != current_snapshot_id # type: ignore
114
115
assert tbl .metadata .refs ["main" ] == SnapshotRef (snapshot_id = expected_snapshot_id , snapshot_ref_type = "branch" )
0 commit comments