Skip to content

Commit 02c2da7

Browse files
authored
fix: show warning for unknown location set through .ctor (#1052)
* fix: show warning for unknown location set through .ctor * update expected location in bigframes session
1 parent 1162b3b commit 02c2da7

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

bigframes/_config/bigquery_options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def __init__(
9494
):
9595
self._credentials = credentials
9696
self._project = project
97-
self._location = location
97+
self._location = _get_validated_location(location)
9898
self._bq_connection = bq_connection
9999
self._use_regional_endpoints = use_regional_endpoints
100100
self._application_name = application_name

tests/system/large/test_location.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def test_bq_location_non_canonical(set_location, resolved_location):
101101
context=bigframes.BigQueryOptions(location=set_location)
102102
)
103103

104-
assert session.bqclient.location == set_location
104+
assert session.bqclient.location == resolved_location
105105

106106
# by default global endpoint is used
107107
assert (

tests/unit/_config/test_bigquery_options.py

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,26 @@ def test_setter_if_session_started_but_setting_the_same_value(attribute):
9797
],
9898
)
9999
def test_location_set_to_valid_no_warning(valid_location):
100-
options = bigquery_options.BigQueryOptions()
101-
# Ensure that no warnings are emitted.
102-
# https://docs.pytest.org/en/7.0.x/how-to/capture-warnings.html#additional-use-cases-of-warnings-in-tests
103-
with warnings.catch_warnings():
104-
# Turn matching UnknownLocationWarning into exceptions.
105-
# https://docs.python.org/3/library/warnings.html#warning-filter
106-
warnings.simplefilter(
107-
"error", category=bigframes.exceptions.UnknownLocationWarning
108-
)
100+
# test setting location through constructor
101+
def set_location_in_ctor():
102+
bigquery_options.BigQueryOptions(location=valid_location)
103+
104+
# test setting location property
105+
def set_location_property():
106+
options = bigquery_options.BigQueryOptions()
109107
options.location = valid_location
110108

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

112121
@pytest.mark.parametrize(
113122
[
@@ -126,11 +135,20 @@ def test_location_set_to_valid_no_warning(valid_location):
126135
],
127136
)
128137
def test_location_set_to_invalid_warning(invalid_location, possibility):
129-
options = bigquery_options.BigQueryOptions()
130-
with pytest.warns(
131-
bigframes.exceptions.UnknownLocationWarning,
132-
match=re.escape(
133-
f"The location '{invalid_location}' is set to an unknown value. Did you mean '{possibility}'?"
134-
),
135-
):
138+
# test setting location through constructor
139+
def set_location_in_ctor():
140+
bigquery_options.BigQueryOptions(location=invalid_location)
141+
142+
# test setting location property
143+
def set_location_property():
144+
options = bigquery_options.BigQueryOptions()
136145
options.location = invalid_location
146+
147+
for op in [set_location_in_ctor, set_location_property]:
148+
with pytest.warns(
149+
bigframes.exceptions.UnknownLocationWarning,
150+
match=re.escape(
151+
f"The location '{invalid_location}' is set to an unknown value. Did you mean '{possibility}'?"
152+
),
153+
):
154+
op()

0 commit comments

Comments
 (0)