From a700350fe7b4fd1d7f39ff5c19b0f9f7beb4e21a Mon Sep 17 00:00:00 2001 From: chalmer lowe Date: Fri, 16 May 2025 13:05:53 +0000 Subject: [PATCH 01/11] ci: adds a github workflow for experimental purposes --- .github/workflows/unittest.yml | 59 ++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 .github/workflows/unittest.yml diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml new file mode 100644 index 000000000..21509b42f --- /dev/null +++ b/.github/workflows/unittest.yml @@ -0,0 +1,59 @@ +on: + pull_request: + branches: + - main +name: unittest +jobs: + unit: + # Use `ubuntu-latest` runner. + runs-on: ubuntu-latest + strategy: + matrix: + python: ['3.9', '3.10', '3.11', '3.12', '3.13'] + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python }} + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run unit tests + env: + COVERAGE_FILE: .coverage-${{ matrix.python }} + run: | + nox -s unit-${{ matrix.python }} + - name: Upload coverage results + uses: actions/upload-artifact@v4 + with: + name: coverage-artifact-${{ matrix.python }} + path: .coverage-${{ matrix.python }} + include-hidden-files: true + + cover: + runs-on: ubuntu-latest + needs: + - unit + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: "3.9" + - name: Install coverage + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install coverage + - name: Download coverage results + uses: actions/download-artifact@v4 + with: + path: .coverage-results/ + - name: Report coverage results + run: | + find .coverage-results -type f -name '*.zip' -exec unzip {} \; + coverage combine .coverage-results/**/.coverage* + coverage report --show-missing --fail-under=100 From 195e353425ccfe793673d9d028552e93c7dce6c1 Mon Sep 17 00:00:00 2001 From: chalmer lowe Date: Fri, 16 May 2025 13:10:12 +0000 Subject: [PATCH 02/11] matches python versions to those in noxfile.py --- .github/workflows/unittest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index 21509b42f..fdf7dcbf4 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python: ['3.9', '3.10', '3.11', '3.12', '3.13'] + python: ['3.9', '3.11', '3.12', '3.13'] steps: - name: Checkout uses: actions/checkout@v4 From a9ecf1442f0dff68850545cad334673fbc53dc5d Mon Sep 17 00:00:00 2001 From: chalmer lowe Date: Fri, 16 May 2025 13:16:37 +0000 Subject: [PATCH 03/11] remove magics to confirm test blocker --- tests/unit/{test_magics.py => temp_block_magics.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/unit/{test_magics.py => temp_block_magics.py} (100%) diff --git a/tests/unit/test_magics.py b/tests/unit/temp_block_magics.py similarity index 100% rename from tests/unit/test_magics.py rename to tests/unit/temp_block_magics.py From 0599746ea6c0cc7e93eee9cd4aee13d1c94d520f Mon Sep 17 00:00:00 2001 From: chalmer lowe Date: Fri, 16 May 2025 16:59:39 +0000 Subject: [PATCH 04/11] updates to magics handling: ensures interactive shell is present --- tests/unit/{temp_block_magics.py => test_magics.py} | 2 ++ 1 file changed, 2 insertions(+) rename tests/unit/{temp_block_magics.py => test_magics.py} (99%) diff --git a/tests/unit/temp_block_magics.py b/tests/unit/test_magics.py similarity index 99% rename from tests/unit/temp_block_magics.py rename to tests/unit/test_magics.py index 0f1e030cb..8f4972f63 100644 --- a/tests/unit/temp_block_magics.py +++ b/tests/unit/test_magics.py @@ -831,6 +831,7 @@ def test_bigquery_magic_w_max_results_query_job_results_fails(monkeypatch): assert close_transports.called +@pytest.mark.usefixtures("ipython_interactive") def test_bigquery_magic_w_table_id_invalid(monkeypatch): ip = IPython.get_ipython() monkeypatch.setattr(bigquery, "bigquery_magics", None) @@ -861,6 +862,7 @@ def test_bigquery_magic_w_table_id_invalid(monkeypatch): assert "Traceback (most recent call last)" not in output +@pytest.mark.usefixtures("ipython_interactive") def test_bigquery_magic_w_missing_query(monkeypatch): ip = IPython.get_ipython() monkeypatch.setattr(bigquery, "bigquery_magics", None) From 4975589034bcf6b75329af2364a83505ed214a4f Mon Sep 17 00:00:00 2001 From: chalmer lowe Date: Fri, 16 May 2025 17:09:01 +0000 Subject: [PATCH 05/11] testing run_query_patch --- tests/unit/test_magics.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_magics.py b/tests/unit/test_magics.py index 8f4972f63..98406e36c 100644 --- a/tests/unit/test_magics.py +++ b/tests/unit/test_magics.py @@ -1972,7 +1972,11 @@ def test_bigquery_magic_query_variable_not_identifier(monkeypatch): cell_body = "$123foo" # 123foo is not valid Python identifier - with io.capture_output() as captured_io: + run_query_patch = mock.patch( + "google.cloud.bigquery.magics.magics._run_query", autospec=True + ) + + with run_query_patch, io.capture_output() as captured_io: ip.run_cell_magic("bigquery", "", cell_body) # If "$" prefixes a string that is not a Python identifier, we do not treat such From dff59f86b28436bd28f54928e5f02a12305b4727 Mon Sep 17 00:00:00 2001 From: chalmer lowe Date: Fri, 16 May 2025 17:56:35 +0000 Subject: [PATCH 06/11] comment out n=auto for testing purposes --- noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 1922a68a5..0c2d28412 100644 --- a/noxfile.py +++ b/noxfile.py @@ -128,7 +128,7 @@ def default(session, install_extras=True): # Run py.test against the unit tests. session.run( "py.test", - "-n=auto", + # "-n=8", "--quiet", "-W default::PendingDeprecationWarning", "--cov=google/cloud/bigquery", From a0c3bc8f57eac4dbd7c79535377733789f78becf Mon Sep 17 00:00:00 2001 From: chalmer lowe Date: Fri, 16 May 2025 18:07:51 +0000 Subject: [PATCH 07/11] testing fails versus passes --- noxfile.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 0c2d28412..cda8fe055 100644 --- a/noxfile.py +++ b/noxfile.py @@ -129,7 +129,8 @@ def default(session, install_extras=True): session.run( "py.test", # "-n=8", - "--quiet", + # "--quiet", + "-vv", "-W default::PendingDeprecationWarning", "--cov=google/cloud/bigquery", "--cov=tests/unit", From 427904b8bf0656695ff3e48ffa7d75d3a740ac3e Mon Sep 17 00:00:00 2001 From: chalmer lowe Date: Fri, 16 May 2025 18:44:51 +0000 Subject: [PATCH 08/11] testing explicit project --- tests/unit/test_magics.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/test_magics.py b/tests/unit/test_magics.py index 98406e36c..61b3e691f 100644 --- a/tests/unit/test_magics.py +++ b/tests/unit/test_magics.py @@ -1970,6 +1970,7 @@ def test_bigquery_magic_query_variable_not_identifier(monkeypatch): google.auth.credentials.Credentials, instance=True ) + magics.context.project = "unit-test-project" cell_body = "$123foo" # 123foo is not valid Python identifier run_query_patch = mock.patch( From e06d93a002d16d515d55662ca95e1812b1e6bf41 Mon Sep 17 00:00:00 2001 From: chalmer lowe Date: Fri, 16 May 2025 18:52:36 +0000 Subject: [PATCH 09/11] testing explicit project with additional tests --- tests/unit/test_magics.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_magics.py b/tests/unit/test_magics.py index 61b3e691f..275ee23d8 100644 --- a/tests/unit/test_magics.py +++ b/tests/unit/test_magics.py @@ -1762,6 +1762,8 @@ def test_bigquery_magic_with_dict_params_array_value(ipython_ns_cleanup, monkeyp run_query_patch = mock.patch( "google.cloud.bigquery.magics.magics._run_query", autospec=True ) + magics.context.project = "unit-test-project" + query_job_mock = mock.create_autospec( google.cloud.bigquery.job.QueryJob, instance=True ) @@ -1803,6 +1805,8 @@ def test_bigquery_magic_with_dict_params_tuple_value(ipython_ns_cleanup, monkeyp run_query_patch = mock.patch( "google.cloud.bigquery.magics.magics._run_query", autospec=True ) + magics.context.project = "unit-test-project" + query_job_mock = mock.create_autospec( google.cloud.bigquery.job.QueryJob, instance=True ) @@ -1854,6 +1858,7 @@ def test_bigquery_magic_valid_query_in_existing_variable( magics.context.credentials = mock.create_autospec( google.auth.credentials.Credentials, instance=True ) + magics.context.project = "unit-test-project" ipython_ns_cleanup.append((ip, "custom_query")) ipython_ns_cleanup.append((ip, "query_results_df")) @@ -1894,6 +1899,7 @@ def test_bigquery_magic_nonexisting_query_variable(monkeypatch): magics.context.credentials = mock.create_autospec( google.auth.credentials.Credentials, instance=True ) + magics.context.project = "unit-test-project" run_query_patch = mock.patch( "google.cloud.bigquery.magics.magics._run_query", autospec=True @@ -1919,7 +1925,7 @@ def test_bigquery_magic_empty_query_variable_name(monkeypatch): magics.context.credentials = mock.create_autospec( google.auth.credentials.Credentials, instance=True ) - + magics.context.project = "unit-test-project" run_query_patch = mock.patch( "google.cloud.bigquery.magics.magics._run_query", autospec=True ) @@ -1942,6 +1948,7 @@ def test_bigquery_magic_query_variable_non_string(ipython_ns_cleanup, monkeypatc magics.context.credentials = mock.create_autospec( google.auth.credentials.Credentials, instance=True ) + magics.context.project = "unit-test-project" run_query_patch = mock.patch( "google.cloud.bigquery.magics.magics._run_query", autospec=True From 1d95d9c07d5f865eefdbc669b412c8980bc1699a Mon Sep 17 00:00:00 2001 From: chalmer lowe Date: Fri, 16 May 2025 18:57:31 +0000 Subject: [PATCH 10/11] testing explicit project with remaining failing tests --- tests/unit/test_magics.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/unit/test_magics.py b/tests/unit/test_magics.py index 275ee23d8..4c3d4d415 100644 --- a/tests/unit/test_magics.py +++ b/tests/unit/test_magics.py @@ -1356,6 +1356,8 @@ def test_bigquery_magic_w_progress_bar_type_w_context_setter(monkeypatch): run_query_patch = mock.patch( "google.cloud.bigquery.magics.magics._run_query", autospec=True ) + magics.context.project = "unit-test-project" + query_job_mock = mock.create_autospec( google.cloud.bigquery.job.QueryJob, instance=True ) @@ -1385,6 +1387,8 @@ def test_bigquery_magic_with_progress_bar_type(monkeypatch): run_query_patch = mock.patch( "google.cloud.bigquery.magics.magics._run_query", autospec=True ) + magics.context.project = "unit-test-project" + with run_query_patch as run_query_mock: ip.run_cell_magic( "bigquery", "--progress_bar_type=tqdm_gui", "SELECT 17 as num" @@ -1567,6 +1571,8 @@ def test_bigquery_magic_with_string_params(ipython_ns_cleanup, monkeypatch): run_query_patch = mock.patch( "google.cloud.bigquery.magics.magics._run_query", autospec=True ) + magics.context.project = "unit-test-project" + query_job_mock = mock.create_autospec( google.cloud.bigquery.job.QueryJob, instance=True ) @@ -1607,6 +1613,8 @@ def test_bigquery_magic_with_dict_params(ipython_ns_cleanup, monkeypatch): run_query_patch = mock.patch( "google.cloud.bigquery.magics.magics._run_query", autospec=True ) + magics.context.project = "unit-test-project" + query_job_mock = mock.create_autospec( google.cloud.bigquery.job.QueryJob, instance=True ) @@ -1691,6 +1699,7 @@ def test_bigquery_magic_with_option_value_incorrect(monkeypatch): magics.context.credentials = mock.create_autospec( google.auth.credentials.Credentials, instance=True ) + magics.context.project = "unit-test-project" sql = "SELECT @foo AS foo" @@ -1721,6 +1730,8 @@ def test_bigquery_magic_with_dict_params_negative_value( run_query_patch = mock.patch( "google.cloud.bigquery.magics.magics._run_query", autospec=True ) + magics.context.project = "unit-test-project" + query_job_mock = mock.create_autospec( google.cloud.bigquery.job.QueryJob, instance=True ) From 675e491f3742fb20188ab0279d385e70d6fdf8d3 Mon Sep 17 00:00:00 2001 From: chalmer lowe Date: Fri, 16 May 2025 19:07:20 +0000 Subject: [PATCH 11/11] update unittest.yml with unit_noextras --- .github/workflows/unittest.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml index fdf7dcbf4..463a17182 100644 --- a/.github/workflows/unittest.yml +++ b/.github/workflows/unittest.yml @@ -33,10 +33,40 @@ jobs: path: .coverage-${{ matrix.python }} include-hidden-files: true + unit_noextras: + # Use `ubuntu-latest` runner. + runs-on: ubuntu-latest + strategy: + matrix: + python: ['3.9', '3.13'] + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python }} + - name: Install nox + run: | + python -m pip install --upgrade setuptools pip wheel + python -m pip install nox + - name: Run unit_noextras tests + env: + COVERAGE_FILE: .coverage-${{ matrix.python }} + run: | + nox -s unit_noextras-${{ matrix.python }} + - name: Upload coverage results + uses: actions/upload-artifact@v4 + with: + name: coverage-artifact-${{ matrix.python }} + path: .coverage-${{ matrix.python }} + include-hidden-files: true + cover: runs-on: ubuntu-latest needs: - unit + - unit_noextras steps: - name: Checkout uses: actions/checkout@v4