@@ -97,17 +97,26 @@ def test_setter_if_session_started_but_setting_the_same_value(attribute):
9797 ],
9898)
9999def 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)
128137def 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