Skip to content

Commit

Permalink
chore: delete duplicate code from snippets.py (#1481)
Browse files Browse the repository at this point in the history
* chore: delete duplicate code from snippets.py

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
Mattix23 and gcf-owl-bot[bot] authored Jan 30, 2023
1 parent f32df1f commit 2479394
Showing 1 changed file with 0 additions and 60 deletions.
60 changes: 0 additions & 60 deletions docs/snippets.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,66 +164,6 @@ def test_create_partitioned_table(client, to_delete):
"https://github.com/GoogleCloudPlatform/google-cloud-python/issues/5589"
)
)
def test_manage_table_labels(client, to_delete):
dataset_id = "label_table_dataset_{}".format(_millis())
table_id = "label_table_{}".format(_millis())
project = client.project
dataset_ref = bigquery.DatasetReference(project, dataset_id)
dataset = bigquery.Dataset(dataset_ref)
client.create_dataset(dataset)
to_delete.append(dataset)

table = bigquery.Table(dataset.table(table_id), schema=SCHEMA)

labels = {"color": "green"}
table.labels = labels
table = client.create_table(table)

# TODO(Mattix23): After code sample is updated from cloud.google.com delete this

# [START bigquery_get_table_labels]
# from google.cloud import bigquery
# client = bigquery.Client()
# dataset_id = 'my_dataset'
# table_id = 'my_table'

project = client.project
dataset_ref = bigquery.DatasetReference(project, dataset_id)
table_ref = dataset_ref.table(table_id)
table = client.get_table(table_ref) # API Request

# View table labels
print("Table ID: {}".format(table_id))
print("Labels:")
if table.labels:
for label, value in table.labels.items():
print("\t{}: {}".format(label, value))
else:
print("\tTable has no labels defined.")
# [END bigquery_get_table_labels]
assert table.labels == labels

# TODO(Mattix23): After code sample is updated from cloud.google.com delete this

# [START bigquery_delete_label_table]
# from google.cloud import bigquery
# client = bigquery.Client()
# project = client.project
# dataset_ref = bigquery.DatasetReference(project, dataset_id)
# table_ref = dataset_ref.table('my_table')
# table = client.get_table(table_ref) # API request

# This example table starts with one label
assert table.labels == {"color": "green"}
# To delete a label from a table, set its value to None
table.labels["color"] = None

table = client.update_table(table, ["labels"]) # API request

assert table.labels == {}
# [END bigquery_delete_label_table]


@pytest.mark.skip(
reason=(
"update_table() is flaky "
Expand Down

0 comments on commit 2479394

Please sign in to comment.