Skip to content

Commit 5766f8a

Browse files
chore: update system tests (#1105)
1 parent 3e58322 commit 5766f8a

1 file changed

Lines changed: 12 additions & 25 deletions

File tree

tests/system/test_connector_object.py

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
"""
16+
1617
import asyncio
1718
import concurrent.futures
1819
import datetime
19-
import logging
2020
import os
2121
from threading import Thread
2222

@@ -55,17 +55,13 @@ def test_connector_with_credentials() -> None:
5555
credentials, _ = google.auth.load_credentials_from_file(
5656
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]
5757
)
58-
custom_connector = Connector(credentials=credentials)
59-
try:
60-
pool = init_connection_engine(custom_connector)
58+
with Connector(credentials=credentials) as connector:
59+
pool = init_connection_engine(connector)
6160

6261
with pool.connect() as conn:
63-
conn.execute(sqlalchemy.text("SELECT 1"))
64-
65-
except Exception as e:
66-
logging.exception("Failed to connect with credentials from file!", e)
67-
# close connector
68-
custom_connector.close()
62+
result = conn.execute(sqlalchemy.text("SELECT 1")).fetchone()
63+
assert isinstance(result[0], int)
64+
assert result[0] == 1
6965

7066

7167
def test_multiple_connectors() -> None:
@@ -89,12 +85,12 @@ def test_multiple_connectors() -> None:
8985
first_connector._cache[instance_connection_string]
9086
!= second_connector._cache[instance_connection_string]
9187
)
92-
except Exception as e:
93-
logging.exception("Failed to connect with multiple Connector objects!", e)
94-
95-
# close connectors
96-
first_connector.close()
97-
second_connector.close()
88+
except Exception:
89+
raise
90+
finally:
91+
# close connectors
92+
first_connector.close()
93+
second_connector.close()
9894

9995

10096
def test_connector_in_ThreadPoolExecutor() -> None:
@@ -122,15 +118,6 @@ def get_time() -> datetime.datetime:
122118
assert isinstance(return_value, datetime.datetime)
123119

124120

125-
def test_connector_as_context_manager() -> None:
126-
"""Test that Connector can be used as a context manager."""
127-
with Connector() as connector:
128-
pool = init_connection_engine(connector)
129-
130-
with pool.connect() as conn:
131-
conn.execute(sqlalchemy.text("SELECT 1"))
132-
133-
134121
def test_connector_with_custom_loop() -> None:
135122
"""Test that Connector can be used with custom loop in background thread."""
136123
# create new event loop and start it in thread

0 commit comments

Comments
 (0)