You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by bl...@apache.org on 2022/08/18 16:42:31 UTC

[iceberg] branch master updated: Python: Implement __repr__ for SnapshotRefType (#5564)

This is an automated email from the ASF dual-hosted git repository.

blue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/master by this push:
     new 16dbdeee8c Python: Implement __repr__ for SnapshotRefType (#5564)
16dbdeee8c is described below

commit 16dbdeee8c2ab22cff586c8db028f5ec785dfe78
Author: Fokko Driesprong <fo...@apache.org>
AuthorDate: Thu Aug 18 18:42:25 2022 +0200

    Python: Implement __repr__ for SnapshotRefType (#5564)
---
 python/pyiceberg/table/refs.py                     |  3 ++
 .../table/refs.py => tests/table/test_refs.py}     | 33 ++++++++++------------
 2 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/python/pyiceberg/table/refs.py b/python/pyiceberg/table/refs.py
index ab8c03fc37..58f6121ed9 100644
--- a/python/pyiceberg/table/refs.py
+++ b/python/pyiceberg/table/refs.py
@@ -28,6 +28,9 @@ class SnapshotRefType(str, Enum):
     BRANCH = "branch"
     TAG = "tag"
 
+    def __repr__(self) -> str:
+        return f"SnapshotRefType.{self.name}"
+
 
 class SnapshotRef(IcebergBaseModel):
     snapshot_id: int = Field(alias="snapshot-id")
diff --git a/python/pyiceberg/table/refs.py b/python/tests/table/test_refs.py
similarity index 54%
copy from python/pyiceberg/table/refs.py
copy to python/tests/table/test_refs.py
index ab8c03fc37..abd71ee110 100644
--- a/python/pyiceberg/table/refs.py
+++ b/python/tests/table/test_refs.py
@@ -14,24 +14,21 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-from enum import Enum
-from typing import Optional
+# pylint:disable=eval-used
+from pyiceberg.table.refs import SnapshotRef, SnapshotRefType
 
-from pydantic import Field
 
-from pyiceberg.utils.iceberg_base_model import IcebergBaseModel
+def test_snapshot_with_properties_repr():
+    snapshot_ref = SnapshotRef(
+        snapshot_id=3051729675574597004,
+        snapshot_ref_type=SnapshotRefType.TAG,
+        min_snapshots_to_keep=None,
+        max_snapshot_age_ms=None,
+        max_ref_age_ms=10000000,
+    )
 
-MAIN_BRANCH = "main"
-
-
-class SnapshotRefType(str, Enum):
-    BRANCH = "branch"
-    TAG = "tag"
-
-
-class SnapshotRef(IcebergBaseModel):
-    snapshot_id: int = Field(alias="snapshot-id")
-    snapshot_ref_type: SnapshotRefType = Field(alias="type")
-    min_snapshots_to_keep: Optional[int] = Field(alias="min-snapshots-to-keep", default=None)
-    max_snapshot_age_ms: Optional[int] = Field(alias="max-snapshot-age-ms", default=None)
-    max_ref_age_ms: Optional[int] = Field(alias="max-ref-age-ms", default=None)
+    assert (
+        repr(snapshot_ref)
+        == """SnapshotRef(snapshot_id=3051729675574597004, snapshot_ref_type=SnapshotRefType.TAG, min_snapshots_to_keep=None, max_snapshot_age_ms=None, max_ref_age_ms=10000000)"""
+    )
+    assert snapshot_ref == eval(repr(snapshot_ref))