Skip to content

Commit

Permalink
chore: add bigquery-magics samples (#9)
Browse files Browse the repository at this point in the history
* chore: add the sample test for magics

* re-arrange directory and make nox -s pass

* chore: add the sample test for magics

* chore: copy `%%bigquery` magics tests from google-cloud-bigquery (#8)

* chore: copy magics unit tests from google-cloud-bigquery

* update tests to use bigquery_magics module

* remove auth from unit tests

* fix coverage

* re-arrange directory and make nox -s pass

* delete files

* test the version

* chore: add the sample test for magics

* re-arrange directory and make nox -s pass

* chore: add the sample test for magics

* chore: copy `%%bigquery` magics tests from google-cloud-bigquery (#8)

* chore: copy magics unit tests from google-cloud-bigquery

* update tests to use bigquery_magics module

* remove auth from unit tests

* fix coverage

* re-arrange directory and make nox -s pass

* delete files

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* delete files

* address comments

* fix the merging conflicts

* set local version of variables

* address comments

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Tim Sweña (Swast) <swast@google.com>
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 15, 2024
1 parent 8a7cb5f commit dfc64b8
Show file tree
Hide file tree
Showing 14 changed files with 519 additions and 3 deletions.
1 change: 1 addition & 0 deletions bigquery_magics/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
from google.cloud.bigquery.dbapi import _helpers

from bigquery_magics import line_arg_parser as lap
import bigquery_magics._versions_helpers
import bigquery_magics.config
import bigquery_magics.line_arg_parser.exceptions

Expand Down
1 change: 0 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ of this library (from ``1.x`` to ``2.x``, or from ``2.x`` to ``3.x``).
.. toctree::
:maxdepth: 2

UPGRADING

Changelog
---------
Expand Down
4 changes: 2 additions & 2 deletions docs/magics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ Code Samples

Running a query:

.. literalinclude:: ./samples/magics/query.py
.. literalinclude:: ./samples/snippets/query.py
:dedent: 4
:start-after: [START bigquery_jupyter_query]
:end-before: [END bigquery_jupyter_query]

Running a parameterized query:

.. literalinclude:: ./samples/magics/query_params_scalars.py
.. literalinclude:: ./samples/snippets/query_params_scalars.py
:dedent: 4
:start-after: [START bigquery_jupyter_query_params_scalars]
:end-before: [END bigquery_jupyter_query_params_scalars]
Expand Down
13 changes: 13 additions & 0 deletions samples/snippets/__init__.py
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.
21 changes: 21 additions & 0 deletions samples/snippets/_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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.


def strip_region_tags(sample_text: str) -> str:
"""Remove blank lines and region tags from sample text"""
magic_lines = [
line for line in sample_text.split("\n") if len(line) > 0 and "# [" not in line
]
return "\n".join(magic_lines)
44 changes: 44 additions & 0 deletions samples/snippets/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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.

import typing
from typing import Iterator

import pytest

if typing.TYPE_CHECKING:
from IPython.core.interactiveshell import TerminalInteractiveShell

interactiveshell = pytest.importorskip("IPython.terminal.interactiveshell")
tools = pytest.importorskip("IPython.testing.tools")


@pytest.fixture(scope="session")
def ipython() -> "TerminalInteractiveShell":
config = tools.default_config()
config.TerminalInteractiveShell.simple_prompt = True
shell = interactiveshell.TerminalInteractiveShell.instance(config=config)
return shell


@pytest.fixture(autouse=True)
def ipython_interactive(
ipython: "TerminalInteractiveShell",
) -> Iterator["TerminalInteractiveShell"]:
"""Activate IPython's builtin hooks
for the duration of the test scope.
"""
with ipython.builtin_trap:
yield ipython
8 changes: 8 additions & 0 deletions samples/snippets/mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[mypy]
; We require type annotations in all samples.
strict = True
exclude = noxfile\.py
warn_unused_configs = True

[mypy-IPython.*,nox,noxfile_config,pandas]
ignore_missing_imports = True
Loading

0 comments on commit dfc64b8

Please sign in to comment.