@@ -15,34 +15,34 @@ def test_invalid_credentials(
1515 engine_url : str , database_name : str , username : str , password : str , api_endpoint : str
1616) -> None :
1717 """Connection properly reacts to invalid credentials error"""
18- connection = connect (
18+ with connect (
1919 engine_url = engine_url ,
2020 database = database_name ,
2121 username = username + "_" ,
2222 password = password + "_" ,
2323 api_endpoint = api_endpoint ,
24- )
25- with raises (AuthenticationError ) as exc_info :
26- connection .cursor ().execute ("show tables" )
24+ ) as connection :
25+ with raises (AuthenticationError ) as exc_info :
26+ connection .cursor ().execute ("show tables" )
2727
28- assert str (exc_info .value ).startswith (
29- "Failed to authenticate"
30- ), "Invalid authentication error message"
28+ assert str (exc_info .value ).startswith (
29+ "Failed to authenticate"
30+ ), "Invalid authentication error message"
3131
3232
3333def test_engine_url_not_exists (
3434 engine_url : str , database_name : str , username : str , password : str , api_endpoint : str
3535) -> None :
3636 """Connection properly reacts to invalid engine url error"""
37- connection = connect (
37+ with connect (
3838 engine_url = engine_url + "_" ,
3939 database = database_name ,
4040 username = username ,
4141 password = password ,
4242 api_endpoint = api_endpoint ,
43- )
44- with raises (ConnectError ):
45- connection .cursor ().execute ("show tables" )
43+ ) as connection :
44+ with raises (ConnectError ):
45+ connection .cursor ().execute ("show tables" )
4646
4747
4848def test_engine_name_not_exists (
@@ -54,14 +54,14 @@ def test_engine_name_not_exists(
5454) -> None :
5555 """Connection properly reacts to invalid engine name error"""
5656 with raises (FireboltEngineError ):
57- connection = connect (
57+ with connect (
5858 engine_name = engine_name + "_________" ,
5959 database = database_name ,
6060 username = username ,
6161 password = password ,
6262 api_endpoint = api_endpoint ,
63- )
64- connection .cursor ().execute ("show tables" )
63+ ) as connection :
64+ connection .cursor ().execute ("show tables" )
6565
6666
6767def test_engine_stopped (
@@ -73,34 +73,34 @@ def test_engine_stopped(
7373) -> None :
7474 """Connection properly reacts to engine not running error"""
7575 with raises (EngineNotRunningError ):
76- connection = connect (
76+ with connect (
7777 engine_url = stopped_engine_url ,
7878 database = database_name ,
7979 username = username ,
8080 password = password ,
8181 api_endpoint = api_endpoint ,
82- )
83- connection .cursor ().execute ("show tables" )
82+ ) as connection :
83+ connection .cursor ().execute ("show tables" )
8484
8585
8686def test_database_not_exists (
8787 engine_url : str , database_name : str , username : str , password : str , api_endpoint : str
8888) -> None :
8989 """Connection properly reacts to invalid database error"""
9090 new_db_name = database_name + "_"
91- connection = connect (
91+ with connect (
9292 engine_url = engine_url ,
9393 database = new_db_name ,
9494 username = username ,
9595 password = password ,
9696 api_endpoint = api_endpoint ,
97- )
98- with raises (FireboltDatabaseError ) as exc_info :
99- connection .cursor ().execute ("show tables" )
97+ ) as connection :
98+ with raises (FireboltDatabaseError ) as exc_info :
99+ connection .cursor ().execute ("show tables" )
100100
101- assert (
102- str (exc_info .value ) == f"Database { new_db_name } does not exist"
103- ), "Invalid database name error message"
101+ assert (
102+ str (exc_info .value ) == f"Database { new_db_name } does not exist"
103+ ), "Invalid database name error message"
104104
105105
106106def test_sql_error (connection : Connection ) -> None :
0 commit comments