Skip to content

Commit

Permalink
chore: copy %%bigquery magics tests from google-cloud-bigquery (#8)
Browse files Browse the repository at this point in the history
* chore: copy magics unit tests from google-cloud-bigquery

* update tests to use bigquery_magics module

* remove auth from unit tests

* fix coverage
  • Loading branch information
tswast authored and ashleyxuu committed Apr 12, 2024
1 parent e555729 commit 111a92f
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions bigquery_magics/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,17 @@
import time
import warnings

import IPython # type: ignore
from IPython import display # type: ignore
from IPython.core import magic_arguments # type: ignore
import IPython # type: ignore
from IPython import display # type: ignore
from IPython.core import magic_arguments # type: ignore
from google.api_core import client_info
from google.api_core.exceptions import NotFound
from google.cloud import bigquery
from google.cloud.bigquery import _versions_helpers, exceptions
from google.cloud.bigquery import exceptions
from google.cloud.bigquery.dbapi import _helpers
from google.cloud.bigquery import _versions_helpers

from bigquery_magics import line_arg_parser as lap
import bigquery_magics.config
Expand All @@ -112,6 +114,7 @@

IPYTHON_USER_AGENT = "ipython-{}".format(IPython.__version__)
context = bigquery_magics.config.context
context = bigquery_magics.config.context


def _handle_error(error, destination_var=None):
Expand Down Expand Up @@ -348,6 +351,15 @@ def _create_dataset_if_necessary(client, dataset_id):
"Defaults to location set in query setting in console."
),
)
@magic_arguments.argument(
"--location",
type=str,
default=None,
help=(
"Set the location to execute query."
"Defaults to location set in query setting in console."
),
)
def _cell_magic(line, query):
"""Underlying function for bigquery cell magic
Expand Down Expand Up @@ -392,6 +404,8 @@ def _cell_magic(line, query):
)
use_bqstorage_api = not args.use_rest_api and (bigquery_storage is not None)
location = args.location
use_bqstorage_api = not args.use_rest_api and (bigquery_storage is not None)
location = args.location

params = []
if params_option_value:
Expand Down Expand Up @@ -421,6 +435,7 @@ def _cell_magic(line, query):
client_info=client_info.ClientInfo(user_agent=IPYTHON_USER_AGENT),
client_options=bigquery_client_options,
location=location,
location=location,
)
if context._connection:
client._connection = context._connection
Expand Down Expand Up @@ -611,7 +626,7 @@ def _make_bqstorage_client(client, use_bqstorage_api, client_options):
return None

try:
_versions_helpers.BQ_STORAGE_VERSIONS.try_import(
bigquery_magics._versions_helpers.BQ_STORAGE_VERSIONS.try_import(
raise_if_error=True
)
except exceptions.BigQueryStorageNotFoundError as err:
Expand Down

0 comments on commit 111a92f

Please sign in to comment.