-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: copy magics unit tests from google-cloud-bigquery
- Loading branch information
Showing
17 changed files
with
2,616 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
name: docs | ||
jobs: | ||
docs: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.9" | ||
- name: Install nox | ||
run: | | ||
python -m pip install --upgrade setuptools pip wheel | ||
python -m pip install nox | ||
- name: Run docs | ||
run: | | ||
nox -s docs | ||
docfx: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.10" | ||
- name: Install nox | ||
run: | | ||
python -m pip install --upgrade setuptools pip wheel | ||
python -m pip install nox | ||
- name: Run docfx | ||
run: | | ||
nox -s docfx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
name: lint | ||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.8" | ||
- name: Install nox | ||
run: | | ||
python -m pip install --upgrade setuptools pip wheel | ||
python -m pip install nox | ||
- name: Run lint | ||
run: | | ||
nox -s lint | ||
- name: Run lint_setup_py | ||
run: | | ||
nox -s lint_setup_py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
name: unittest | ||
jobs: | ||
unit: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python: ['3.8', '3.9', '3.10', '3.11', '3.12'] | ||
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 }} | ||
|
||
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.8" | ||
- 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=96 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
__version__ = "0.0.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
grpcio==1.47.0 | ||
# IMPORTANT: When Python 3.9 support is dropped, update these to | ||
# match the minimums in setup.py. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# IMPORTANT: When Python 3.10 support is dropped, update these to | ||
# match the minimums in setup.py. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# IMPORTANT: When Python 3.11 support is dropped, update these to | ||
# match the minimums in setup.py. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
grpcio==1.47.0 | ||
pandas==1.2.0 | ||
# IMPORTANT: When Python 3.7 support is dropped, update these to | ||
# match the minimums in setup.py. | ||
# | ||
# We try to test across major versions of our dependencies. | ||
# This is the last ipython 7.x release | ||
ipython==7.34.0 | ||
# This is the last pandas 1.5.x release. | ||
pandas==1.5.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
# This constraints file is used to make sure that the latest dependency versions | ||
# we claim to support in setup.py are indeed installed in test sessions in the most | ||
# recent Python version supported (3.9 at the time of writing - 2021-05-05). | ||
# IMPORTANT: When Python 3.8 support is dropped, update these to | ||
# match the minimums in setup.py. | ||
# | ||
# NOTE: Not comprehensive yet, will eventually be maintained semi-automatically by | ||
# the renovate bot. | ||
grpcio==1.47.0 | ||
pyarrow>=4.0.0 | ||
# We try to test across major versions of our dependencies. | ||
# This is the last pandas 2.0.x release. | ||
pandas==2.0.3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""System tests for Jupyter/IPython connector.""" | ||
|
||
import re | ||
|
||
import pytest | ||
import psutil | ||
|
||
|
||
IPython = pytest.importorskip("IPython") | ||
io = pytest.importorskip("IPython.utils.io") | ||
pandas = pytest.importorskip("pandas") | ||
tools = pytest.importorskip("IPython.testing.tools") | ||
interactiveshell = pytest.importorskip("IPython.terminal.interactiveshell") | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def ipython(): | ||
config = tools.default_config() | ||
config.TerminalInteractiveShell.simple_prompt = True | ||
shell = interactiveshell.TerminalInteractiveShell.instance(config=config) | ||
return shell | ||
|
||
|
||
@pytest.fixture() | ||
def ipython_interactive(ipython): | ||
"""Activate IPython's builtin hooks | ||
for the duration of the test scope. | ||
""" | ||
with ipython.builtin_trap: | ||
yield ipython | ||
|
||
|
||
def test_bigquery_magic(ipython_interactive): | ||
ip = IPython.get_ipython() | ||
current_process = psutil.Process() | ||
conn_count_start = len(current_process.connections()) | ||
|
||
ip.extension_manager.load_extension("google.cloud.bigquery") | ||
sql = """ | ||
SELECT | ||
CONCAT( | ||
'https://stackoverflow.com/questions/', | ||
CAST(id as STRING)) as url, | ||
view_count | ||
FROM `bigquery-public-data.stackoverflow.posts_questions` | ||
WHERE tags like '%google-bigquery%' | ||
ORDER BY view_count DESC | ||
LIMIT 10 | ||
""" | ||
with io.capture_output() as captured: | ||
result = ip.run_cell_magic("bigquery", "--use_rest_api", sql) | ||
|
||
conn_count_end = len(current_process.connections()) | ||
|
||
lines = re.split("\n|\r", captured.stdout) | ||
# Removes blanks & terminal code (result of display clearing) | ||
updates = list(filter(lambda x: bool(x) and x != "\x1b[2K", lines)) | ||
assert re.match("Executing query with job ID: .*", updates[0]) | ||
assert (re.match("Query executing: .*s", line) for line in updates[1:-1]) | ||
assert isinstance(result, pandas.DataFrame) | ||
assert len(result) == 10 # verify row count | ||
assert list(result) == ["url", "view_count"] # verify column names | ||
|
||
# NOTE: For some reason, the number of open sockets is sometimes one *less* | ||
# than expected when running system tests on Kokoro, thus using the <= assertion. | ||
# That's still fine, however, since the sockets are apparently not leaked. | ||
assert conn_count_end <= conn_count_start # system resources are released |
Oops, something went wrong.