Skip to content

fix: show warning for unknown location set through .ctor #1052

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
merged 5 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion bigframes/_config/bigquery_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def __init__(
):
self._credentials = credentials
self._project = project
self._location = location
self._location = _get_validated_location(location)
self._bq_connection = bq_connection
self._use_regional_endpoints = use_regional_endpoints
self._application_name = application_name
Expand Down
2 changes: 1 addition & 1 deletion tests/system/large/test_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_bq_location_non_canonical(set_location, resolved_location):
context=bigframes.BigQueryOptions(location=set_location)
)

assert session.bqclient.location == set_location
assert session.bqclient.location == resolved_location

# by default global endpoint is used
assert (
Expand Down
50 changes: 34 additions & 16 deletions tests/unit/_config/test_bigquery_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,26 @@ def test_setter_if_session_started_but_setting_the_same_value(attribute):
],
)
def test_location_set_to_valid_no_warning(valid_location):
options = bigquery_options.BigQueryOptions()
# Ensure that no warnings are emitted.
# https://docs.pytest.org/en/7.0.x/how-to/capture-warnings.html#additional-use-cases-of-warnings-in-tests
with warnings.catch_warnings():
# Turn matching UnknownLocationWarning into exceptions.
# https://docs.python.org/3/library/warnings.html#warning-filter
warnings.simplefilter(
"error", category=bigframes.exceptions.UnknownLocationWarning
)
# test setting location through constructor
def set_location_in_ctor():
bigquery_options.BigQueryOptions(location=valid_location)

# test setting location property
def set_location_property():
options = bigquery_options.BigQueryOptions()
options.location = valid_location

for op in [set_location_in_ctor, set_location_property]:
# Ensure that no warnings are emitted.
# https://docs.pytest.org/en/7.0.x/how-to/capture-warnings.html#additional-use-cases-of-warnings-in-tests
with warnings.catch_warnings():
# Turn matching UnknownLocationWarning into exceptions.
# https://docs.python.org/3/library/warnings.html#warning-filter
warnings.simplefilter(
"error", category=bigframes.exceptions.UnknownLocationWarning
)
op()


@pytest.mark.parametrize(
[
Expand All @@ -126,11 +135,20 @@ def test_location_set_to_valid_no_warning(valid_location):
],
)
def test_location_set_to_invalid_warning(invalid_location, possibility):
options = bigquery_options.BigQueryOptions()
with pytest.warns(
bigframes.exceptions.UnknownLocationWarning,
match=re.escape(
f"The location '{invalid_location}' is set to an unknown value. Did you mean '{possibility}'?"
),
):
# test setting location through constructor
def set_location_in_ctor():
bigquery_options.BigQueryOptions(location=invalid_location)

# test setting location property
def set_location_property():
options = bigquery_options.BigQueryOptions()
options.location = invalid_location

for op in [set_location_in_ctor, set_location_property]:
with pytest.warns(
bigframes.exceptions.UnknownLocationWarning,
match=re.escape(
f"The location '{invalid_location}' is set to an unknown value. Did you mean '{possibility}'?"
),
):
op()