diff --git a/src/firebolt/async_db/connection.py b/src/firebolt/async_db/connection.py index 88230455ee3..70235ead0d2 100644 --- a/src/firebolt/async_db/connection.py +++ b/src/firebolt/async_db/connection.py @@ -48,15 +48,15 @@ async def _resolve_engine_url( response.raise_for_status() return response.json()["engine"]["endpoint"] except HTTPStatusError as e: - # Engine error would be 404 + # Engine error would be 404. if e.response.status_code != 404: - raise InterfaceError(f"unable to retrieve engine endpoint: {e}") + raise InterfaceError(f"Unable to retrieve engine endpoint: {e}.") # Once this is point is reached we've already authenticated with # the backend so it's safe to assume the cause of the error is - # missing engine - raise FireboltEngineError(f"Firebolt engine {engine_name} does not exist") + # missing engine. + raise FireboltEngineError(f"Firebolt engine {engine_name} does not exist.") except (JSONDecodeError, RequestError, RuntimeError, HTTPStatusError) as e: - raise InterfaceError(f"unable to retrieve engine endpoint: {e}") + raise InterfaceError(f"Unable to retrieve engine endpoint: {e}.") def async_connect_factory(connection_class: Type) -> Callable: @@ -82,25 +82,25 @@ async def connect_inner( api_endpoint(optional): Firebolt API endpoint. Used for authentication. Note: - either `engine_name` or `engine_url` should be provided, but not both + Either `engine_name` or `engine_url` should be provided, but not both. """ if engine_name and engine_url: raise InterfaceError( - "Both engine_name and engine_url are provided." + "Both engine_name and engine_url are provided. " "Provide only one to connect." ) if not engine_name and not engine_url: raise InterfaceError( - "Neither engine_name nor engine_url are provided." + "Neither engine_name nor engine_url is provided. " "Provide one to connect." ) api_endpoint = fix_url_schema(api_endpoint) - # This parameters are optional in function signature, + # These parameters are optional in function signature # but are required to connect. - # It's recommended to make them kwargs by PEP 249 + # PEP 249 recommends making them kwargs. for param, name in ( (database, "database"), (username, "username"), diff --git a/src/firebolt/async_db/cursor.py b/src/firebolt/async_db/cursor.py index 8e837db15d9..2418bd4d4a2 100644 --- a/src/firebolt/async_db/cursor.py +++ b/src/firebolt/async_db/cursor.py @@ -202,7 +202,7 @@ async def _raise_if_error(self, resp: Response) -> None: if not await is_engine_running(self.connection, self.connection.engine_url): raise EngineNotRunningError( f"Firebolt engine {self.connection.engine_url} " - "needs to be running to run queries against it" + "needs to be running to run queries against it." ) resp.raise_for_status() diff --git a/src/firebolt/common/exception.py b/src/firebolt/common/exception.py index 60f58d7fbde..bae353289bb 100644 --- a/src/firebolt/common/exception.py +++ b/src/firebolt/common/exception.py @@ -16,8 +16,8 @@ def __init__(self, method_name: str): def __str__(self) -> str: return ( - f"unable to call {self.method_name}: " - f"engine must to be attached to a database first." + f"Unable to call {self.method_name}: " + f"Engine must to be attached to a database first." ) @@ -43,8 +43,8 @@ def __init__(self, method_name: str): def __str__(self) -> str: return ( - f"unable to call {self.method_name}: " - f"engine must not be in starting or stopping state." + f"Unable to call {self.method_name}: " + f"Engine must not be in starting or stopping state." ) @@ -65,7 +65,7 @@ def __init__(self, method_name: str): self.method_name = method_name def __str__(self) -> str: - return f"unable to call {self.method_name}: cursor closed" + return f"Unable to call {self.method_name}: cursor closed." class QueryNotRunError(CursorError): @@ -73,7 +73,7 @@ def __init__(self, method_name: str): self.method_name = method_name def __str__(self) -> str: - return f"unable to call {self.method_name}: need to run a query first" + return f"Unable to call {self.method_name}: need to run a query first." class QueryError(CursorError): @@ -90,7 +90,7 @@ def __init__(self, cause: str, api_endpoint: str): self.api_endpoint = api_endpoint def __str__(self) -> str: - return f"Failed to authenticate at {self.api_endpoint}: {self.cause}" + return f"Failed to authenticate at {self.api_endpoint}: {self.cause}." # PEP-249 diff --git a/src/firebolt/db/connection.py b/src/firebolt/db/connection.py index 27fc197c51c..dff31a3a48a 100644 --- a/src/firebolt/db/connection.py +++ b/src/firebolt/db/connection.py @@ -58,7 +58,7 @@ def close(self) -> None: # Context manager support def __enter__(self) -> Connection: if self.closed: - raise ConnectionClosedError("Connection is already closed") + raise ConnectionClosedError("Connection is already closed.") return self def __exit__( diff --git a/tests/integration/dbapi/async/test_auth_async.py b/tests/integration/dbapi/async/test_auth_async.py index 351cfc7c655..5038cb7e956 100644 --- a/tests/integration/dbapi/async/test_auth_async.py +++ b/tests/integration/dbapi/async/test_auth_async.py @@ -23,10 +23,10 @@ async def test_refresh_token(connection: Connection) -> None: old = c._client.auth.token c._client.auth._expires = int(time()) - 1 - # Still works fine + # Still works fine. await c.execute("show tables") - assert c._client.auth.token != old, "Auth didn't update token on expiration" + assert c._client.auth.token != old, "Auth didn't update token on expiration." @mark.asyncio diff --git a/tests/integration/dbapi/async/test_errors_async.py b/tests/integration/dbapi/async/test_errors_async.py index 1aee08187de..b995b5f3142 100644 --- a/tests/integration/dbapi/async/test_errors_async.py +++ b/tests/integration/dbapi/async/test_errors_async.py @@ -16,7 +16,7 @@ async def test_invalid_credentials( engine_url: str, database_name: str, username: str, password: str, api_endpoint: str ) -> None: - """Connection properly reacts to invalid credentials error""" + """Connection properly reacts to invalid credentials error.""" async with await connect( engine_url=engine_url, database=database_name, @@ -67,7 +67,7 @@ async def test_engine_url_not_exists( account_name: str, api_endpoint: str, ) -> None: - """Connection properly reacts to invalid engine url error""" + """Connection properly reacts to invalid engine url error.""" async with await connect( engine_url=engine_url + "_", database=database_name, @@ -89,7 +89,7 @@ async def test_engine_name_not_exists( account_name: str, api_endpoint: str, ) -> None: - """Connection properly reacts to invalid engine name error""" + """Connection properly reacts to invalid engine name error.""" with raises(FireboltEngineError): async with await connect( engine_name=engine_name + "_________", @@ -111,7 +111,7 @@ async def test_engine_stopped( account_name: str, api_endpoint: str, ) -> None: - """Connection properly reacts to invalid engine name error""" + """Connection properly reacts to invalid engine name error.""" with raises(EngineNotRunningError): async with await connect( engine_url=stopped_engine_url, @@ -128,7 +128,7 @@ async def test_engine_stopped( async def test_database_not_exists( engine_url: str, database_name: str, username: str, password: str, api_endpoint: str ) -> None: - """Connection properly reacts to invalid database error""" + """Connection properly reacts to invalid database error.""" new_db_name = database_name + "_" async with await connect( engine_url=engine_url, @@ -142,16 +142,16 @@ async def test_database_not_exists( assert ( str(exc_info.value) == f"Database {new_db_name} does not exist" - ), "Invalid database name error message" + ), "Invalid database name error message." @mark.asyncio async def test_sql_error(connection: Connection) -> None: - """Connection properly reacts to sql execution error""" + """Connection properly reacts to SQL execution error.""" with connection.cursor() as c: with raises(OperationalError) as exc_info: await c.execute("select ]") assert str(exc_info.value).startswith( "Error executing query" - ), "Invalid SQL error message" + ), "Invalid SQL error message." diff --git a/tests/integration/dbapi/async/test_queries_async.py b/tests/integration/dbapi/async/test_queries_async.py index 74357856f54..e7c24c33880 100644 --- a/tests/integration/dbapi/async/test_queries_async.py +++ b/tests/integration/dbapi/async/test_queries_async.py @@ -69,17 +69,17 @@ async def test_select( async def test_drop_create( connection: Connection, create_drop_description: List[Column] ) -> None: - """Create and drop table/index queries are handled propperly""" + """Create and drop table/index queries are handled properly.""" async def test_query(c: Cursor, query: str) -> None: - assert await c.execute(query) == 1, "Invalid row count returned" - assert c.rowcount == 1, "Invalid rowcount value" + assert await c.execute(query) == 1, "Invalid row count returned." + assert c.rowcount == 1, "Invalid rowcount value." assert_deep_eq( c.description, create_drop_description, - "Invalid create table query description", + "Invalid create table query description.", ) - assert len(await c.fetchall()) == 1, "Invalid data returned" + assert len(await c.fetchall()) == 1, "Invalid data returned." """Create table query is handled properly""" with connection.cursor() as c: @@ -131,12 +131,12 @@ async def test_query(c: Cursor, query: str) -> None: @mark.asyncio async def test_insert(connection: Connection) -> None: - """Insert and delete queries are handled propperly""" + """Insert and delete queries are handled properly.""" async def test_empty_query(c: Cursor, query: str) -> None: - assert await c.execute(query) == -1, "Invalid row count returned" - assert c.rowcount == -1, "Invalid rowcount value" - assert c.description is None, "Invalid description" + assert await c.execute(query) == -1, "Invalid row count returned." + assert c.rowcount == -1, "Invalid rowcount value." + assert c.description is None, "Invalid description." with raises(DataError): await c.fetchone() @@ -161,7 +161,7 @@ async def test_empty_query(c: Cursor, query: str) -> None: assert ( await c.execute("SELECT * FROM test_tb ORDER BY test_tb.id") == 1 - ), "Invalid data length in table after insert" + ), "Invalid data length in table after insert." assert_deep_eq( await c.fetchall(), @@ -176,7 +176,7 @@ async def test_empty_query(c: Cursor, query: str) -> None: [1, 2, 3], ], ], - "Invalid data in table after insert", + "Invalid data in table after insert.", ) diff --git a/tests/integration/dbapi/sync/test_errors.py b/tests/integration/dbapi/sync/test_errors.py index 1da62711823..caf0300bcf4 100644 --- a/tests/integration/dbapi/sync/test_errors.py +++ b/tests/integration/dbapi/sync/test_errors.py @@ -112,7 +112,7 @@ def test_engine_stopped( def test_database_not_exists( engine_url: str, database_name: str, username: str, password: str, api_endpoint: str ) -> None: - """Connection properly reacts to invalid database error""" + """Connection properly reacts to invalid database error.""" new_db_name = database_name + "_" with connect( engine_url=engine_url, @@ -130,7 +130,7 @@ def test_database_not_exists( def test_sql_error(connection: Connection) -> None: - """Connection properly reacts to sql execution error""" + """Connection properly reacts to sql execution error.""" with connection.cursor() as c: with raises(OperationalError) as exc_info: c.execute("select ]") diff --git a/tests/integration/dbapi/sync/test_queries.py b/tests/integration/dbapi/sync/test_queries.py index 6f68a304cc0..fa00f9b129f 100644 --- a/tests/integration/dbapi/sync/test_queries.py +++ b/tests/integration/dbapi/sync/test_queries.py @@ -65,7 +65,7 @@ def test_select( def test_drop_create( connection: Connection, create_drop_description: List[Column] ) -> None: - """Create and drop table/index queries are handled propperly""" + """Create and drop table/index queries are handled properly.""" def test_query(c: Cursor, query: str) -> None: assert c.execute(query) == 1, "Invalid row count returned" @@ -124,7 +124,7 @@ def test_query(c: Cursor, query: str) -> None: def test_insert(connection: Connection) -> None: - """Insert and delete queries are handled propperly""" + """Insert and delete queries are handled properly.""" def test_empty_query(c: Cursor, query: str) -> None: assert c.execute(query) == -1, "Invalid row count returned" diff --git a/tests/unit/async_db/test_connection.py b/tests/unit/async_db/test_connection.py index fbdf2dc3c73..e45ca0abe47 100644 --- a/tests/unit/async_db/test_connection.py +++ b/tests/unit/async_db/test_connection.py @@ -32,17 +32,17 @@ async def test_closed_connection(connection: Connection) -> None: @mark.asyncio async def test_cursors_closed_on_close(connection: Connection) -> None: - """Connection closes all it's cursors on close.""" + """Connection closes all its cursors on close.""" c1, c2 = connection.cursor(), connection.cursor() assert ( len(connection._cursors) == 2 - ), "Invalid number of cursors stored in connection" + ), "Invalid number of cursors stored in connection." await connection.aclose() - assert connection.closed, "Connection was not closed on close" - assert c1.closed, "Cursor was not closed on connection close" - assert c2.closed, "Cursor was not closed on connection close" - assert len(connection._cursors) == 0, "Cursors left in connection after close" + assert connection.closed, "Connection was not closed on close." + assert c1.closed, "Cursor was not closed on connection close." + assert c2.closed, "Cursor was not closed on connection close." + assert len(connection._cursors) == 0, "Cursors left in connection after close." await connection.aclose() @@ -57,7 +57,7 @@ async def test_cursor_initialized( query_url: str, python_query_data: List[List[ColType]], ) -> None: - """Connection initialised it's cursors propperly""" + """Connection initialised its cursors properly.""" httpx_mock.add_callback(auth_callback, url=auth_url) httpx_mock.add_callback(query_callback, url=query_url) @@ -75,7 +75,7 @@ async def test_cursor_initialized( cursor = connection.cursor() assert ( cursor.connection == connection - ), "Invalid cursor connection attribute" + ), "Invalid cursor connection attribute." assert ( cursor._client == connection._client ), "Invalid cursor _client attribute" @@ -85,7 +85,7 @@ async def test_cursor_initialized( cursor.close() assert ( cursor not in connection._cursors - ), "Cursor wasn't removed from connection after close" + ), "Cursor wasn't removed from connection after close." @mark.asyncio @@ -136,7 +136,7 @@ async def test_connect_engine_name( ): pass assert str(exc_info.value).startswith( - "Both engine_name and engine_url are provided" + "Both engine_name and engine_url are provided." ) with raises(InterfaceError) as exc_info: @@ -148,7 +148,7 @@ async def test_connect_engine_name( ): pass assert str(exc_info.value).startswith( - "Neither engine_name nor engine_url are provided" + "Neither engine_name nor engine_url is provided." ) httpx_mock.add_callback(auth_callback, url=auth_url) diff --git a/tests/unit/client/test_auth.py b/tests/unit/client/test_auth.py index 9b775975857..34c8c087568 100644 --- a/tests/unit/client/test_auth.py +++ b/tests/unit/client/test_auth.py @@ -52,7 +52,7 @@ def test_auth_refresh_on_expiration( execute_generator_requests(auth.auth_flow(Request("GET", "https://host"))) assert auth.token == test_token, "invalid access token" execute_generator_requests(auth.auth_flow(Request("GET", "https://host"))) - assert auth.token == test_token2, "expired access token was not updated" + assert auth.token == test_token2, "Expired access token was not updated." def test_auth_uses_same_token_if_valid( @@ -88,7 +88,7 @@ def test_auth_uses_same_token_if_valid( execute_generator_requests(auth.auth_flow(Request("GET", "https://host"))) assert auth.token == test_token, "invalid access token" execute_generator_requests(auth.auth_flow(Request("GET", "https://host"))) - assert auth.token == test_token, "shoud not update token until it expires" + assert auth.token == test_token, "Should not update token until it expires." httpx_mock.reset(False) @@ -129,7 +129,7 @@ def http_error(**kwargs): execute_generator_requests(auth.get_new_token_generator()) assert ( - str(excinfo.value) == "Failed to authenticate at https://host: firebolt" + str(excinfo.value) == "Failed to authenticate at https://host: firebolt." ), "Invalid authentication error message" httpx_mock.reset(True) diff --git a/tests/unit/client/test_client.py b/tests/unit/client/test_client.py index cb72c32bca2..2d914e10a99 100644 --- a/tests/unit/client/test_client.py +++ b/tests/unit/client/test_client.py @@ -57,11 +57,11 @@ def test_client_different_auths( test_password: str, ): """ - Client propperly handles such auth types: + Client properly handles such auth types: - tuple(username, password) - Auth - None - All other types should raise TypeError + All other types should raise TypeError. """ httpx_mock.add_callback( diff --git a/tests/unit/client/test_client_async.py b/tests/unit/client/test_client_async.py index 9c563d3c511..913a598126c 100644 --- a/tests/unit/client/test_client_async.py +++ b/tests/unit/client/test_client_async.py @@ -59,11 +59,11 @@ async def test_client_different_auths( test_password: str, ): """ - Client propperly handles such auth types: + Client properly handles such auth types: - tuple(username, password) - Auth - None - All other types should raise TypeError + All other types should raise TypeError. """ httpx_mock.add_callback( diff --git a/tests/unit/db/test_connection.py b/tests/unit/db/test_connection.py index 47f0dc7dc5e..3a042fe52f6 100644 --- a/tests/unit/db/test_connection.py +++ b/tests/unit/db/test_connection.py @@ -26,7 +26,7 @@ def test_closed_connection(connection: Connection) -> None: def test_cursors_closed_on_close(connection: Connection) -> None: - """Connection closes all it's cursors on close.""" + """Connection closes all its cursors on close.""" c1, c2 = connection.cursor(), connection.cursor() assert ( len(connection._cursors) == 2 @@ -49,7 +49,7 @@ def test_cursor_initialized( query_url: str, python_query_data: List[List[ColType]], ) -> None: - """Connection initialised it's cursors propperly""" + """Connection initialised its cursors properly.""" httpx_mock.add_callback(auth_callback, url=auth_url) httpx_mock.add_callback(query_callback, url=query_url) @@ -121,7 +121,7 @@ def test_connect_engine_name( password="password", ) assert str(exc_info.value).startswith( - "Both engine_name and engine_url are provided" + "Both engine_name and engine_url are provided." ) with raises(InterfaceError) as exc_info: @@ -131,7 +131,7 @@ def test_connect_engine_name( password="password", ) assert str(exc_info.value).startswith( - "Neither engine_name nor engine_url are provided" + "Neither engine_name nor engine_url is provided." ) httpx_mock.add_callback(auth_callback, url=auth_url)