8000 update sample tests to use correct fixture · googleapis/python-bigquery@ead525a · GitHub
[go: up one dir, main page]

Skip to content

Commit ead525a

Browse files
committed
update sample tests to use correct fixture
1 parent b4fd4bf commit ead525a

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

docs/snippets.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ def test_create_partitioned_table(client, to_delete):
125125
dataset = client.create_dataset(dataset_ref)
126126
to_delete.append(dataset)
127127

128+
# TODO(tswast): remove this snippet once cloud.google.com is updated to use
129+
# samples/snippets/create_partitioned_table.py
128130
# [START bigquery_create_table_partitioned]
129131
# from google.cloud import bigquery
130132
# client = bigquery.Client()

samples/snippets/create_partitioned_table.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
def create_partitioned_table(client, to_delete):
16-
17-
#[START bigquery_create_table_partitioned]
15+
16+
def create_partitioned_table(table_id):
17+
your_fully_qualified_table_id = table_id
18+
19+
# [START bigquery_create_table_partitioned]
1820
from google.cloud import bigquery
19-
21+
2022
client = bigquery.Client()
2123

22-
table_id = "your-project.your_dataset.your_table_name"
24+
# Use format "your-project.your_dataset.your_table_name" for table_id
25+
table_id = your_fully_qualified_table_id
2326
schema = [
2427
bigquery.SchemaField("name", "STRING"),
2528
bigquery.SchemaField("post_abbr", "STRING"),
@@ -34,7 +37,9 @@ def create_partitioned_table(client, to_delete):
3437

3538
table = client.create_table(table)
3639

37-
print(f"Created table {table.table_id}, partitioned on column {table.time_partitioning.field}.")
40+
print(
41+
f"Created table {table.project}.{table.dataset_id}.{table.table_id}, "
42+
f"partitioned on column {table.time_partitioning.field}."
43+
)
3844
# [END bigquery_create_table_partitioned]
39-
40-
45+
return table

samples/snippets/create_partitioned_table_test.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,18 @@
1717
import create_partitioned_table
1818

1919
if typing.TYPE_CHECKING:
20-
import pathlib
21-
2220
import pytest
2321

2422

2523
def test_create_partitioned_table(
2624
capsys: "pytest.CaptureFixture[str]",
27-
table_id: str,
28-
tmp_path: "pathlib.Path",
25+
random_table_id: str,
2926
) -> None:
30-
schema_path = str(tmp_path / "test_schema.json")
27+
table = create_partitioned_table.create_partitioned_table(random_table_id)
3128

32-
create_partitioned_table.create_partitioned_table(client, to_delete)
29+
out, _ = capsys.readouterr()
30+
assert "Created" in out
31+
assert random_table_id in out
3332

3433
assert table.time_partitioning.type_ == "DAY"
3534
assert table.time_partitioning.field == "date"
36-
assert table.time_partitioning.expiration_ms == 7776000000

0 commit comments

Comments
 (0)
0