Skip to content

Commit 0d7d7e4

Browse files
authored
chore: make labels tests more robust to test order (#2246)
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/python-bigquery-dataframes/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes internal issue b/459432106 🦕
1 parent 24ba4a1 commit 0d7d7e4

File tree

6 files changed

+37
-30
lines changed

6 files changed

+37
-30
lines changed

.github/workflows/docs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ on:
22
pull_request:
33
branches:
44
- main
5+
push:
6+
branches:
7+
- main
58
name: docs
69
jobs:
710
docs:

.github/workflows/lint.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ on:
22
pull_request:
33
branches:
44
- main
5+
push:
6+
branches:
7+
- main
58
name: lint
69
jobs:
710
lint:

.github/workflows/mypy.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ on:
22
pull_request:
33
branches:
44
- main
5+
push:
6+
branches:
7+
- main
58
name: mypy
69
jobs:
710
mypy:

.github/workflows/unittest.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ on:
22
pull_request:
33
branches:
44
- main
5+
push:
6+
branches:
7+
- main
58
name: unittest
69
jobs:
710
unit:

owlbot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@
5858
".kokoro/build.sh",
5959
".kokoro/continuous/common.cfg",
6060
".kokoro/presubmit/common.cfg",
61-
# Temporary workaround to update docs job to use python 3.10
6261
".github/workflows/docs.yml",
62+
".github/workflows/lint.yml",
63+
".github/workflows/unittest.yml",
6364
],
6465
)
6566

tests/unit/session/test_io_bigquery.py

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818
from unittest import mock
1919

2020
import google.cloud.bigquery as bigquery
21+
import google.cloud.bigquery.job
22+
import google.cloud.bigquery.table
2123
import pytest
2224

2325
import bigframes
2426
from bigframes.core import log_adapter
2527
import bigframes.core.events
2628
import bigframes.pandas as bpd
29+
import bigframes.session._io.bigquery
2730
import bigframes.session._io.bigquery as io_bq
2831
from bigframes.testing import mocks
2932

@@ -32,7 +35,7 @@
3235
def mock_bq_client():
3336
mock_client = mock.create_autospec(bigquery.Client)
3437
mock_query_job = mock.create_autospec(bigquery.QueryJob)
35-
mock_row_iterator = mock.create_autospec(bigquery.table.RowIterator)
38+
mock_row_iterator = mock.create_autospec(google.cloud.bigquery.table.RowIterator)
3639

3740
mock_query_job.result.return_value = mock_row_iterator
3841

@@ -98,14 +101,12 @@ def test_create_job_configs_labels_log_adaptor_call_method_under_length_limit():
98101
cur_labels = {
99102
"source": "bigquery-dataframes-temp",
100103
}
101-
df = bpd.DataFrame(
102-
{"col1": [1, 2], "col2": [3, 4]}, session=mocks.create_bigquery_session()
103-
)
104-
# Test running two methods
105-
df.head()
106-
df.max()
107-
df.columns
108-
api_methods = log_adapter._api_methods
104+
api_methods = [
105+
"dataframe-columns",
106+
"dataframe-max",
107+
"dataframe-head",
108+
"dataframe-__init__",
109+
]
109110

110111
labels = io_bq.create_job_configs_labels(
111112
job_configs_labels=cur_labels, api_methods=api_methods
@@ -123,17 +124,13 @@ def test_create_job_configs_labels_log_adaptor_call_method_under_length_limit():
123124

124125
def test_create_job_configs_labels_length_limit_met_and_labels_is_none():
125126
log_adapter.get_and_reset_api_methods()
126-
df = bpd.DataFrame(
127-
{"col1": [1, 2], "col2": [3, 4]}, session=mocks.create_bigquery_session()
128-
)
129127
# Test running methods more than the labels' length limit
130-
for i in range(100):
131-
df.head()
132-
api_methods = log_adapter._api_methods
128+
api_methods = list(["dataframe-head"] * 100)
133129

134-
labels = io_bq.create_job_configs_labels(
135-
job_configs_labels=None, api_methods=api_methods
136-
)
130+
with bpd.option_context("compute.extra_query_labels", {}):
131+
labels = io_bq.create_job_configs_labels(
132+
job_configs_labels=None, api_methods=api_methods
133+
)
137134
assert labels is not None
138135
assert len(labels) == log_adapter.MAX_LABELS_COUNT
139136
assert "dataframe-head" in labels.values()
@@ -150,17 +147,14 @@ def test_create_job_configs_labels_length_limit_met():
150147
value = f"test{i}"
151148
cur_labels[key] = value
152149
# If cur_labels length is 62, we can only add one label from api_methods
153-
df = bpd.DataFrame(
154-
{"col1": [1, 2], "col2": [3, 4]}, session=mocks.create_bigquery_session()
155-
)
156150
# Test running two methods
157-
df.head()
158-
df.max()
159-
api_methods = log_adapter._api_methods
151+
api_methods = ["dataframe-max", "dataframe-head"]
152+
153+
with bpd.option_context("compute.extra_query_labels", {}):
154+
labels = io_bq.create_job_configs_labels(
155+
job_configs_labels=cur_labels, api_methods=api_methods
156+
)
160157

161-
labels = io_bq.create_job_configs_labels(
162-
job_configs_labels=cur_labels, api_methods=api_methods
163-
)
164158
assert labels is not None
165159
assert len(labels) == 56
166160
assert "dataframe-max" in labels.values()
@@ -184,7 +178,7 @@ def test_add_and_trim_labels_length_limit_met():
184178
{"col1": [1, 2], "col2": [3, 4]}, session=mocks.create_bigquery_session()
185179
)
186180

187-
job_config = bigquery.job.QueryJobConfig()
181+
job_config = google.cloud.bigquery.job.QueryJobConfig()
188182
job_config.labels = cur_labels
189183

190184
df.max()
@@ -221,7 +215,7 @@ def test_start_query_with_client_labels_length_limit_met(
221215
{"col1": [1, 2], "col2": [3, 4]}, session=mocks.create_bigquery_session()
222216
)
223217

224-
job_config = bigquery.job.QueryJobConfig()
218+
job_config = google.cloud.bigquery.job.QueryJobConfig()
225219
job_config.labels = cur_labels
226220

227221
df.max()

0 commit comments

Comments
 (0)