Skip to content
This repository was archived by the owner on Mar 6, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Generalize valid option values
The parser should accept as wide a range of values as possible and let
the code that delas with the semantics to decide whether the values are
good or not.
  • Loading branch information
plamut committed Sep 2, 2020
commit f57c6cd5f317a781a4a1f124ba4cf7eb76599eb1
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@
),
("OPTION_SPEC", r"(?P<OPTION_SPEC>--\w+)"),
("OPTION_EQ", r"(?P<OPTION_EQ>=)"),
# NOTE: Currently the only valid value for a non "--params" option is
# either a project/table name or an integer (e.g. max_results).
("OPT_VAL", r"(?P<OPT_VAL>(?:\w|\.|-(?!-))+)"),
("OPT_VAL", r"(?P<OPT_VAL>\S+?(?=\s|--|$))"),
]
),
),
Expand Down
21 changes: 19 additions & 2 deletions tests/unit/test_magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1361,8 +1361,7 @@ def test_bigquery_magic_with_option_value_incorrect():

sql = "SELECT @foo AS foo"

exc_pattern = r".*[Uu]nrecognized input.*option values correct\?.*"
with pytest.raises(ValueError, match=exc_pattern):
with pytest.raises(ValueError, match=r".*invalid literal.*\[PLENTY!\].*"):
cell_magic_args = "params_dict_df --max_results [PLENTY!]"
ip.run_cell_magic("bigquery", cell_magic_args, sql)

Expand Down Expand Up @@ -1502,6 +1501,24 @@ def test_bigquery_magic_with_improperly_formatted_params():
ip.run_cell_magic("bigquery", "--params {17}", sql)


@pytest.mark.usefixtures("ipython_interactive")
@pytest.mark.skipif(pandas is None, reason="Requires `pandas`")
def test_bigquery_magic_with_invalid_multiple_option_values():
ip = IPython.get_ipython()
ip.extension_manager.load_extension("google.cloud.bigquery")
magics.context.credentials = mock.create_autospec(
google.auth.credentials.Credentials, instance=True
)

sql = "SELECT @foo AS foo"

exc_pattern = r".*[Uu]nrecognized input.*option values correct\?.*567.*"

with pytest.raises(ValueError, match=exc_pattern):
cell_magic_args = "params_dict_df --max_results 10 567"
ip.run_cell_magic("bigquery", cell_magic_args, sql)


@pytest.mark.usefixtures("ipython_interactive")
def test_bigquery_magic_omits_tracebacks_from_error_message():
ip = IPython.get_ipython()
Expand Down