Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add str method to table #1199

Merged
merged 9 commits into from
Apr 16, 2022
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