Skip to content

Commit c1c7e06

Browse files
authored
Merge branch 'main' into release-please--branches--main
2 parents 29780dd + 06ee3df commit c1c7e06

File tree

6 files changed

+120
-20
lines changed

6 files changed

+120
-20
lines changed

.github/workflows/unittest.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
on:
2+
pull_request:
3+
branches:
4+
- main
5+
name: unittest
6+
jobs:
7+
unit:
8+
# Use `ubuntu-latest` runner.
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
python: ['3.9', '3.11', '3.12', '3.13']
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
- name: Setup Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: ${{ matrix.python }}
20+
- name: Install nox
21+
run: |
22+
python -m pip install --upgrade setuptools pip wheel
23+
python -m pip install nox
24+
- name: Run unit tests
25+
env:
26+
COVERAGE_FILE: .coverage-${{ matrix.python }}
27+
run: |
28+
nox -s unit-${{ matrix.python }}
29+
- name: Upload coverage results
30+
uses: actions/upload-artifact@v4
31+
with:
32+
name: coverage-artifact-${{ matrix.python }}
33+
path: .coverage-${{ matrix.python }}
34+
include-hidden-files: true
35+
36+
unit_noextras:
37+
# Use `ubuntu-latest` runner.
38+
runs-on: ubuntu-latest
39+
strategy:
40+
matrix:
41+
python: ['3.9', '3.13']
42+
steps:
43+
- name: Checkout
44+
uses: actions/checkout@v4
45+
- name: Setup Python
46+
uses: actions/setup-python@v5
47+
with:
48+
python-version: ${{ matrix.python }}
49+
- name: Install nox
50+
run: |
51+
python -m pip install --upgrade setuptools pip wheel
52+
python -m pip install nox
53+
- name: Run unit_noextras tests
54+
env:
55+
COVERAGE_FILE: .coverage-unit-noextras-${{ matrix.python }}
56+
run: |
57+
nox -s unit_noextras-${{ matrix.python }}
58+
- name: Upload coverage results
59+
uses: actions/upload-artifact@v4
60+
with:
61+
name: coverage-artifact-unit-noextras-${{ matrix.python }}
62+
path: .coverage-unit-noextras-${{ matrix.python }}
63+
include-hidden-files: true
64+
65+
cover:
66+
runs-on: ubuntu-latest
67+
needs:
68+
- unit
69+
- unit_noextras
70+
steps:
71+
- name: Checkout
72+
uses: actions/checkout@v4
73+
- name: Setup Python
74+
uses: actions/setup-python@v5
75+
with:
76+
python-version: "3.9"
77+
- name: Install coverage
78+
run: |
79+
python -m pip install --upgrade setuptools pip wheel
80+
python -m pip install coverage
81+
- name: Download coverage results
82+
uses: actions/download-artifact@v4
83+
with:
84+
path: .coverage-results/
85+
- name: Report coverage results
86+
run: |
87+
find .coverage-results -type f -name '*.zip' -exec unzip {} \;
88+
coverage combine .coverage-results/**/.coverage*
89+
coverage report --show-missing --fail-under=100

google/cloud/bigquery/table.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,11 +1897,6 @@ def total_bytes_processed(self) -> Optional[int]:
18971897
"""total bytes processed from job statistics, if present."""
18981898
return self._total_bytes_processed
18991899

1900-
@property
1901-
def page_size(self) -> Optional[int]:
1902-
"""The maximum number of rows in each page of results from this request, if present."""
1903-
return self._page_size
1904-
19051900
def _is_almost_completely_cached(self):
19061901
"""Check if all results are completely cached.
19071902
@@ -1953,7 +1948,7 @@ def _should_use_bqstorage(self, bqstorage_client, create_bqstorage_client):
19531948
if self._is_almost_completely_cached():
19541949
return False
19551950

1956-
if self.max_results is not None or self.page_size is not None:
1951+
if self.max_results is not None:
19571952
return False
19581953

19591954
try:
@@ -2023,9 +2018,7 @@ def _maybe_warn_max_results(
20232018
bqstorage_client:
20242019
The BigQuery Storage client intended to use for downloading result rows.
20252020
"""
2026-
if bqstorage_client is not None and (
2027-
self.max_results is not None or self.page_size is not None
2028-
):
2021+
if bqstorage_client is not None and self.max_results is not None:
20292022
warnings.warn(
20302023
"Cannot use bqstorage_client if max_results is set, "
20312024
"reverting to fetching data with the REST endpoint.",

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def default(session, install_extras=True):
128128
# Run py.test against the unit tests.
129129
session.run(
130130
"py.test",
131-
"-n=auto",
131+
"-n=8",
132132
"--quiet",
133133
"-W default::PendingDeprecationWarning",
134134
"--cov=google/cloud/bigquery",

tests/unit/test_dbapi_cursor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ def _mock_rows(
161161
mock_rows,
162162
)
163163
mock_rows.max_results = None
164-
mock_rows.page_size = None
165164
type(mock_rows).job_id = mock.PropertyMock(return_value="test-job-id")
166165
type(mock_rows).location = mock.PropertyMock(return_value="test-location")
167166
type(mock_rows).num_dml_affected_rows = mock.PropertyMock(

tests/unit/test_magics.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ def test_bigquery_magic_without_optional_arguments(monkeypatch):
480480
run_query_patch = mock.patch(
481481
"google.cloud.bigquery.magics.magics._run_query", autospec=True
482482
)
483+
magics.context.project = "unit-test-project"
483484
query_job_mock = mock.create_autospec(
484485
google.cloud.bigquery.job.QueryJob, instance=True
485486
)
@@ -831,6 +832,7 @@ def test_bigquery_magic_w_max_results_query_job_results_fails(monkeypatch):
831832
assert close_transports.called
832833

833834

835+
@pytest.mark.usefixtures("ipython_interactive")
834836
def test_bigquery_magic_w_table_id_invalid(monkeypatch):
835837
ip = IPython.get_ipython()
836838
monkeypatch.setattr(bigquery, "bigquery_magics", None)
@@ -861,6 +863,7 @@ def test_bigquery_magic_w_table_id_invalid(monkeypatch):
861863
assert "Traceback (most recent call last)" not in output
862864

863865

866+
@pytest.mark.usefixtures("ipython_interactive")
864867
def test_bigquery_magic_w_missing_query(monkeypatch):
865868
ip = IPython.get_ipython()
866869
monkeypatch.setattr(bigquery, "bigquery_magics", None)
@@ -1354,6 +1357,8 @@ def test_bigquery_magic_w_progress_bar_type_w_context_setter(monkeypatch):
13541357
run_query_patch = mock.patch(
13551358
"google.cloud.bigquery.magics.magics._run_query", autospec=True
13561359
)
1360+
magics.context.project = "unit-test-project"
1361+
13571362
query_job_mock = mock.create_autospec(
13581363
google.cloud.bigquery.job.QueryJob, instance=True
13591364
)
@@ -1383,6 +1388,8 @@ def test_bigquery_magic_with_progress_bar_type(monkeypatch):
13831388
run_query_patch = mock.patch(
13841389
"google.cloud.bigquery.magics.magics._run_query", autospec=True
13851390
)
1391+
magics.context.project = "unit-test-project"
1392+
13861393
with run_query_patch as run_query_mock:
13871394
ip.run_cell_magic(
13881395
"bigquery", "--progress_bar_type=tqdm_gui", "SELECT 17 as num"
@@ -1565,6 +1572,8 @@ def test_bigquery_magic_with_string_params(ipython_ns_cleanup, monkeypatch):
15651572
run_query_patch = mock.patch(
15661573
"google.cloud.bigquery.magics.magics._run_query", autospec=True
15671574
)
1575+
magics.context.project = "unit-test-project"
1576+
15681577
query_job_mock = mock.create_autospec(
15691578
google.cloud.bigquery.job.QueryJob, instance=True
15701579
)
@@ -1605,6 +1614,8 @@ def test_bigquery_magic_with_dict_params(ipython_ns_cleanup, monkeypatch):
16051614
run_query_patch = mock.patch(
16061615
"google.cloud.bigquery.magics.magics._run_query", autospec=True
16071616
)
1617+
magics.context.project = "unit-test-project"
1618+
16081619
query_job_mock = mock.create_autospec(
16091620
google.cloud.bigquery.job.QueryJob, instance=True
16101621
)
@@ -1689,6 +1700,7 @@ def test_bigquery_magic_with_option_value_incorrect(monkeypatch):
16891700
magics.context.credentials = mock.create_autospec(
16901701
google.auth.credentials.Credentials, instance=True
16911702
)
1703+
magics.context.project = "unit-test-project"
16921704

16931705
sql = "SELECT @foo AS foo"
16941706

@@ -1719,6 +1731,8 @@ def test_bigquery_magic_with_dict_params_negative_value(
17191731
run_query_patch = mock.patch(
17201732
"google.cloud.bigquery.magics.magics._run_query", autospec=True
17211733
)
1734+
magics.context.project = "unit-test-project"
1735+
17221736
query_job_mock = mock.create_autospec(
17231737
google.cloud.bigquery.job.QueryJob, instance=True
17241738
)
@@ -1760,6 +1774,8 @@ def test_bigquery_magic_with_dict_params_array_value(ipython_ns_cleanup, monkeyp
17601774
run_query_patch = mock.patch(
17611775
"google.cloud.bigquery.magics.magics._run_query", autospec=True
17621776
)
1777+
magics.context.project = "unit-test-project"
1778+
17631779
query_job_mock = mock.create_autospec(
17641780
google.cloud.bigquery.job.QueryJob, instance=True
17651781
)
@@ -1801,6 +1817,8 @@ def test_bigquery_magic_with_dict_params_tuple_value(ipython_ns_cleanup, monkeyp
18011817
run_query_patch = mock.patch(
18021818
"google.cloud.bigquery.magics.magics._run_query", autospec=True
18031819
)
1820+
magics.context.project = "unit-test-project"
1821+
18041822
query_job_mock = mock.create_autospec(
18051823
google.cloud.bigquery.job.QueryJob, instance=True
18061824
)
@@ -1852,6 +1870,7 @@ def test_bigquery_magic_valid_query_in_existing_variable(
18521870
magics.context.credentials = mock.create_autospec(
18531871
google.auth.credentials.Credentials, instance=True
18541872
)
1873+
magics.context.project = "unit-test-project"
18551874

18561875
ipython_ns_cleanup.append((ip, "custom_query"))
18571876
ipython_ns_cleanup.append((ip, "query_results_df"))
@@ -1892,6 +1911,7 @@ def test_bigquery_magic_nonexisting_query_variable(monkeypatch):
18921911
magics.context.credentials = mock.create_autospec(
18931912
google.auth.credentials.Credentials, instance=True
18941913
)
1914+
magics.context.project = "unit-test-project"
18951915

18961916
run_query_patch = mock.patch(
18971917
"google.cloud.bigquery.magics.magics._run_query", autospec=True
@@ -1917,7 +1937,7 @@ def test_bigquery_magic_empty_query_variable_name(monkeypatch):
19171937
magics.context.credentials = mock.create_autospec(
19181938
google.auth.credentials.Credentials, instance=True
19191939
)
1920-
1940+
magics.context.project = "unit-test-project"
19211941
run_query_patch = mock.patch(
19221942
"google.cloud.bigquery.magics.magics._run_query", autospec=True
19231943
)
@@ -1940,6 +1960,7 @@ def test_bigquery_magic_query_variable_non_string(ipython_ns_cleanup, monkeypatc
19401960
magics.context.credentials = mock.create_autospec(
19411961
google.auth.credentials.Credentials, instance=True
19421962
)
1963+
magics.context.project = "unit-test-project"
19431964

19441965
run_query_patch = mock.patch(
19451966
"google.cloud.bigquery.magics.magics._run_query", autospec=True
@@ -1968,9 +1989,14 @@ def test_bigquery_magic_query_variable_not_identifier(monkeypatch):
19681989
google.auth.credentials.Credentials, instance=True
19691990
)
19701991

1992+
magics.context.project = "unit-test-project"
19711993
cell_body = "$123foo" # 123foo is not valid Python identifier
19721994

1973-
with io.capture_output() as captured_io:
1995+
run_query_patch = mock.patch(
1996+
"google.cloud.bigquery.magics.magics._run_query", autospec=True
1997+
)
1998+
1999+
with run_query_patch, io.capture_output() as captured_io:
19742000
ip.run_cell_magic("bigquery", "", cell_body)
19752001

19762002
# If "$" prefixes a string that is not a Python identifier, we do not treat such

tests/unit/test_table.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2858,13 +2858,6 @@ def test__should_use_bqstorage_returns_false_if_max_results_set(self):
28582858
)
28592859
self.assertFalse(result)
28602860

2861-
def test__should_use_bqstorage_returns_false_if_page_size_set(self):
2862-
iterator = self._make_one(page_size=10, first_page_response=None) # not cached
2863-
result = iterator._should_use_bqstorage(
2864-
bqstorage_client=None, create_bqstorage_client=True
2865-
)
2866-
self.assertFalse(result)
2867-
28682861
def test__should_use_bqstorage_returns_false_w_warning_if_missing_dependency(self):
28692862
iterator = self._make_one(first_page_response=None) # not cached
28702863

0 commit comments

Comments
 (0)