Skip to content

Commit 36e1b9e

Browse files
added tests
1 parent 6892b57 commit 36e1b9e

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/unit/test_to_gbq.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,55 @@ def custom_import_module_side_effect(name, package=None):
271271
create_user_agent()
272272
== f"pandas-{pd.__version__} jupyter bigquery_jupyter_plugin"
273273
)
274+
275+
def test_to_gbq_with_clustering(mock_bigquery_client):
276+
mock_bigquery_client.get_table.side_effect = google.api_core.exceptions.NotFound(
277+
"my_table"
278+
)
279+
gbq.to_gbq(
280+
DataFrame([[1]]),
281+
"my_dataset.my_table",
282+
project_id="1234",
283+
clustering_columns=["col_a", "col_b"],
284+
)
285+
mock_bigquery_client.create_table.assert_called_with(mock.ANY)
286+
table = mock_bigquery_client.create_table.call_args[0][0]
287+
assert table.clustering_fields == ["col_a", "col_b"]
288+
289+
290+
def test_to_gbq_with_time_partitioning(mock_bigquery_client):
291+
mock_bigquery_client.get_table.side_effect = google.api_core.exceptions.NotFound(
292+
"my_table"
293+
)
294+
gbq.to_gbq(
295+
DataFrame([[1]]),
296+
"my_dataset.my_table",
297+
project_id="1234",
298+
time_partitioning_column="time_col",
299+
time_partitioning_type="DAY",
300+
time_partitioning_expiration_ms=100,
301+
)
302+
mock_bigquery_client.create_table.assert_called_with(mock.ANY)
303+
table = mock_bigquery_client.create_table.call_args[0][0]
304+
assert table.time_partitioning.type_ == "DAY"
305+
assert table.time_partitioning.field == "time_col"
306+
assert table.time_partitioning.expiration_ms == 100
307+
308+
309+
def test_to_gbq_with_range_partitioning(mock_bigquery_client):
310+
mock_bigquery_client.get_table.side_effect = google.api_core.exceptions.NotFound(
311+
"my_table"
312+
)
313+
gbq.to_gbq(
314+
DataFrame([[1]]),
315+
"my_dataset.my_table",
316+
project_id="1234",
317+
range_partitioning_column="range_col",
318+
range_partitioning_range={"start": 0, "end": 100, "interval": 10},
319+
)
320+
mock_bigquery_client.create_table.assert_called_with(mock.ANY)
321+
table = mock_bigquery_client.create_table.call_args[0][0]
322+
assert table.range_partitioning.field == "range_col"
323+
assert table.range_partitioning.range_.start == 0
324+
assert table.range_partitioning.range_.end == 100
325+
assert table.range_partitioning.range_.interval == 10

0 commit comments

Comments
 (0)