Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ci: adds a github workflow for experimental purposes #2189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
89 changes: 89 additions & 0 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
on:
pull_request:
branches:
- main
name: unittest
jobs:
unit:
# Use `ubuntu-latest` runner.
runs-on: ubuntu-latest
strategy:
matrix:
python: ['3.9', '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

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
- 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
5 changes: 3 additions & 2 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@ def default(session, install_extras=True):
# Run py.test against the unit tests.
session.run(
"py.test",
"-n=auto",
"--quiet",
# "-n=8",
# "--quiet",
"-vv",
"-W default::PendingDeprecationWarning",
"--cov=google/cloud/bigquery",
"--cov=tests/unit",
Expand Down
29 changes: 27 additions & 2 deletions tests/unit/test_magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1354,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
)
Expand Down Expand Up @@ -1383,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"
Expand Down Expand Up @@ -1565,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
)
Expand Down Expand Up @@ -1605,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
)
Expand Down Expand Up @@ -1689,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"

Expand Down Expand Up @@ -1719,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
)
Expand Down Expand Up @@ -1760,6 +1773,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
)
Expand Down Expand Up @@ -1801,6 +1816,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
)
Expand Down Expand Up @@ -1852,6 +1869,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"))
Expand Down Expand Up @@ -1892,6 +1910,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
Expand All @@ -1917,7 +1936,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
)
Expand All @@ -1940,6 +1959,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
Expand Down Expand Up @@ -1968,9 +1988,14 @@ 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

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
Expand Down
Loading