Skip to content

Commit

Permalink
feat: add str method to table (googleapis#1199)
Browse files Browse the repository at this point in the history
* feat: add str method to table

* feat: add str method to table

* added tests

* linted

Co-authored-by: Steffany Brown <[email protected]>
  • Loading branch information
2 people authored and waltaskew committed Jul 20, 2022
1 parent e2c5521 commit ccc5646
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions google/cloud/bigquery/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,9 @@ def _build_resource(self, filter_fields):
def __repr__(self):
return "Table({})".format(repr(self.reference))

def __str__(self):
return f"{self.project}.{self.dataset_id}.{self.table_id}"


class TableListItem(_TableBase):
"""A read-only table resource from a list operation.
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

import google.api_core.exceptions

from google.cloud.bigquery.table import TableReference

from google.cloud import bigquery_storage
from google.cloud.bigquery_storage_v1.services.big_query_read.transports import (
grpc as big_query_read_grpc_transport,
Expand Down Expand Up @@ -1410,6 +1412,11 @@ def test___repr__(self):
)
self.assertEqual(repr(table1), expected)

def test___str__(self):
dataset = DatasetReference("project1", "dataset1")
table1 = self._make_one(TableReference(dataset, "table1"))
self.assertEqual(str(table1), "project1.dataset1.table1")


class Test_row_from_mapping(unittest.TestCase, _SchemaBase):

Expand Down

0 comments on commit ccc5646

Please sign in to comment.