diff --git a/bigframes/_config/bigquery_options.py b/bigframes/_config/bigquery_options.py index 42007a388e..afb0f00a27 100644 --- a/bigframes/_config/bigquery_options.py +++ b/bigframes/_config/bigquery_options.py @@ -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 diff --git a/tests/system/large/test_location.py b/tests/system/large/test_location.py index 2ef002d7e0..3521e4cd20 100644 --- a/tests/system/large/test_location.py +++ b/tests/system/large/test_location.py @@ -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 ( diff --git a/tests/unit/_config/test_bigquery_options.py b/tests/unit/_config/test_bigquery_options.py index f40c140a9e..d04b5bd575 100644 --- a/tests/unit/_config/test_bigquery_options.py +++ b/tests/unit/_config/test_bigquery_options.py @@ -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( [ @@ -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()