Skip to content

Commit 096bb06

Browse files
authored
refactor: Exposing exceptions on module level (#75)
1 parent 0907012 commit 096bb06

File tree

5 files changed

+67
-0
lines changed

5 files changed

+67
-0
lines changed

src/firebolt/async_db/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,18 @@
1515
)
1616
from firebolt.async_db.connection import Connection, connect
1717
from firebolt.async_db.cursor import Cursor
18+
from firebolt.common.exception import (
19+
DatabaseError,
20+
DataError,
21+
Error,
22+
IntegrityError,
23+
InterfaceError,
24+
InternalError,
25+
NotSupportedError,
26+
OperationalError,
27+
ProgrammingError,
28+
Warning,
29+
)
1830

1931
apilevel = "2.0"
2032
# threads may only share the module and connections, cursors should not be shared

src/firebolt/db/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
Timestamp,
1414
TimestampFromTicks,
1515
)
16+
from firebolt.common.exception import (
17+
DatabaseError,
18+
DataError,
19+
Error,
20+
IntegrityError,
21+
InterfaceError,
22+
InternalError,
23+
NotSupportedError,
24+
OperationalError,
25+
ProgrammingError,
26+
Warning,
27+
)
1628
from firebolt.db.connection import Connection, connect
1729
from firebolt.db.cursor import Cursor
1830

tests/unit/async_db/test_module.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import firebolt.async_db
2+
3+
4+
def test_has_exceptions(db_api_exceptions):
5+
"""Verify async module has top-level dbapi exceptions exposed"""
6+
for ex_name, ex_class in db_api_exceptions.items():
7+
assert issubclass(getattr(firebolt.async_db, ex_name), ex_class)

tests/unit/conftest.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66
from pytest_httpx import to_response
77
from pytest_httpx._httpx_internals import Response
88

9+
from firebolt.common.exception import (
10+
DatabaseError,
11+
DataError,
12+
Error,
13+
IntegrityError,
14+
InterfaceError,
15+
InternalError,
16+
NotSupportedError,
17+
OperationalError,
18+
ProgrammingError,
19+
Warning,
20+
)
921
from firebolt.common.settings import Settings
1022
from firebolt.common.urls import (
1123
ACCOUNT_ENGINE_URL,
@@ -202,3 +214,20 @@ def get_engines_url(settings: Settings) -> str:
202214
@pytest.fixture
203215
def get_databases_url(settings: Settings) -> str:
204216
return f"https://{settings.server}{DATABASES_URL}"
217+
218+
219+
@pytest.fixture
220+
def db_api_exceptions():
221+
exceptions = {
222+
"DatabaseError": DatabaseError,
223+
"DataError": DataError,
224+
"Error": Error,
225+
"IntegrityError": IntegrityError,
226+
"InterfaceError": InterfaceError,
227+
"InternalError": InternalError,
228+
"NotSupportedError": NotSupportedError,
229+
"OperationalError": OperationalError,
230+
"ProgrammingError": ProgrammingError,
231+
"Warning": Warning,
232+
}
233+
return exceptions

tests/unit/db/test_module.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import firebolt.db
2+
3+
4+
def test_has_exceptions(db_api_exceptions):
5+
"""Verify sync module has top-level dbapi exceptions exposed"""
6+
for ex_name, ex_class in db_api_exceptions.items():
7+
assert issubclass(getattr(firebolt.db, ex_name), ex_class)

0 commit comments

Comments
 (0)