-
Notifications
You must be signed in to change notification settings - Fork 317
refactor: move system tests into tests/system
directory
#475
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
Merged
gcf-merge-on-green
merged 8 commits into
googleapis:master
from
tswast:system.py-step1-move
Jan 20, 2021
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
db45efb
refactor: move system tests into `tests/system` directory
tswast 95ae6bb
refactor: use pathlib for data directory
tswast 7e13b3c
typo
tswast 9485f0f
refactor: add missing dependencies to prerelease_deps
tswast d4eed7f
typo
tswast 8c5d825
tests: add google-cloud-storage to prerelease_deps
tswast 4d0ae0c
test: run unit tests separately from system tests
tswast 6a778a5
Update tests/system/__init__.py
tswast File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,13 @@ | ||
# Copyright 2021 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. |
This file contains hidden or 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 hidden or 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,83 @@ | ||
# 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") | ||
Comment on lines
+23
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, this is IMO more clean that those |
||
|
||
|
||
@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 all(re.match("Query executing: .*s", line) for line in updates[1:-1]) | ||
assert re.match("Query complete after .*s", updates[-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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love these small improvements and utilizing the goodies Python 3 offers!