Skip to content

Commit

Permalink
update test for __repr__ of Table class
Browse files Browse the repository at this point in the history
  • Loading branch information
tlm365 committed Sep 1, 2023
1 parent fd9e7c0 commit 01a7479
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
10 changes: 5 additions & 5 deletions python/pyiceberg/table/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,12 +541,12 @@ def __eq__(self, other: Any) -> bool:
)

def __repr__(self) -> str:
"""Returns the string representation of the Table class."""
"""Return the string representation of the Table class."""
table_name = self.catalog.table_name_from(self.identifier)
schema_str = ',\n '.join(f'{column.name}: {column.field_type}' for column in self.schema().columns)
partition_str = ', '.join(field.name for field in self.spec().fields)
snapshot_str = str(self.current_snapshot()) if self.current_snapshot() else 'null'
result_str = f'{table_name}(\n {schema_str}\n),\npartition by: [{partition_str}],\nsnapshot: {snapshot_str}'
schema_str = ",\n ".join(f"{column.name}: {column.field_type}" for column in self.schema().columns)
partition_str = ", ".join(field.name for field in self.spec().fields)
snapshot_str = str(self.current_snapshot()) if self.current_snapshot() else "null"
result_str = f"{table_name}(\n {schema_str}\n),\npartition by: [{partition_str}],\nsnapshot: {snapshot_str}"
return result_str


Expand Down
11 changes: 11 additions & 0 deletions python/tests/table/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ def test_snapshot_by_name_does_not_exist(table: Table) -> None:
assert table.snapshot_by_name("doesnotexist") is None


def test_repr(table: Table) -> None:
expected = """table(
x: long,
y: long,
z: long
),
partition by: [x],
snapshot: Operation.APPEND: id=3055729675574597004, parent_id=3051729675574597004, schema_id=1"""
assert repr(table) == expected


def test_history(table: Table) -> None:
assert table.history() == [
SnapshotLogEntry(snapshot_id=3051729675574597004, timestamp_ms=1515100955770),
Expand Down

0 comments on commit 01a7479

Please sign in to comment.