Skip to content

Commit f1d11c0

Browse files
committed
Test labels on create, register, and pickle
Create and register hand labels to the same `_response_to_table` as load, but only load was tested. Check all three. Also pin that a pickled table keeps its labels, the one intended difference from Java, where `BaseTable.labels` is transient.
1 parent c93fa5f commit f1d11c0

1 file changed

Lines changed: 19 additions & 12 deletions

File tree

‎tests/catalog/test_rest.py‎

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import base64
2121
import os
22+
import pickle
2223
from collections.abc import Callable, Iterator
2324
from contextlib import contextmanager
2425
from typing import Any, cast
@@ -3736,21 +3737,27 @@ def test_load_responses_parse_labels(
37363737
assert response_type.model_validate({**payload, "labels": invalid}).labels == Labels()
37373738

37383739

3739-
def test_load_table_with_labels(rest_mock: Mocker, example_table_metadata_with_snapshot_v1_rest_json: dict[str, Any]) -> None:
3740-
rest_mock.get(
3741-
f"{TEST_URI}v1/namespaces/fokko/tables/table",
3742-
json={
3743-
**example_table_metadata_with_snapshot_v1_rest_json,
3744-
"labels": {"object-labels": {"owner": "team-a"}, "fields": [{"field-id": 1, "labels": {"classification": "pii"}}]},
3745-
},
3746-
status_code=200,
3747-
request_headers=TEST_HEADERS,
3748-
)
3740+
def test_table_labels_from_rest_responses(
3741+
rest_mock: Mocker, example_table_metadata_with_snapshot_v1_rest_json: dict[str, Any], table_schema_simple: Schema
3742+
) -> None:
3743+
response = {
3744+
**example_table_metadata_with_snapshot_v1_rest_json,
3745+
"labels": {"object-labels": {"owner": "team-a"}, "fields": [{"field-id": 1, "labels": {"classification": "pii"}}]},
3746+
}
3747+
rest_mock.get(f"{TEST_URI}v1/namespaces/fokko/tables/table", json=response, status_code=200, request_headers=TEST_HEADERS)
3748+
rest_mock.post(f"{TEST_URI}v1/namespaces/fokko/tables", json=response, status_code=200, request_headers=TEST_HEADERS)
3749+
rest_mock.post(f"{TEST_URI}v1/namespaces/fokko/register", json=response, status_code=200, request_headers=TEST_HEADERS)
37493750
catalog = RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN)
3751+
expected = Labels(object_labels={"owner": "team-a"}, fields=[FieldLabel(field_id=1, labels={"classification": "pii"})])
3752+
37503753
table = catalog.load_table(("fokko", "table"))
3754+
created = catalog.create_table(("fokko", "table"), schema=table_schema_simple)
3755+
registered = catalog.register_table(("fokko", "table"), metadata_location="s3://warehouse/database/table/metadata.json")
3756+
for actual in (table, created, registered):
3757+
assert actual.labels == expected
37513758

3752-
expected = Labels(object_labels={"owner": "team-a"}, fields=[FieldLabel(field_id=1, labels={"classification": "pii"})])
3753-
assert table.labels == expected
3759+
# A pickled table keeps its labels. Java does not serialize them, because BaseTable.labels is transient.
3760+
assert pickle.loads(pickle.dumps(table)).labels == expected
37543761

37553762
# Labels are not table state, so equality ignores them and refresh() keeps the labels from the first load.
37563763
assert table == Table(

0 commit comments

Comments
 (0)