forked from piccolo-orm/piccolo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_lazy_loader.py
More file actions
27 lines (20 loc) · 975 Bytes
/
test_lazy_loader.py
File metadata and controls
27 lines (20 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from unittest import TestCase, mock
from piccolo.utils.lazy_loader import LazyLoader
from tests.base import postgres_only, sqlite_only
class TestLazyLoader(TestCase):
def test_lazy_loading_database_driver(self):
_ = LazyLoader("asyncpg", globals(), "asyncpg")
@postgres_only
def test_lazy_loader_asyncpg_exception(self):
lazy_loader = LazyLoader("asyncpg", globals(), "asyncpg.connect")
with mock.patch("asyncpg.connect") as module:
module.side_effect = ModuleNotFoundError()
with self.assertRaises(ModuleNotFoundError):
lazy_loader._load()
@sqlite_only
def test_lazy_loader_aiosqlite_exception(self):
lazy_loader = LazyLoader("aiosqlite", globals(), "aiosqlite.connect")
with mock.patch("aiosqlite.connect") as module:
module.side_effect = ModuleNotFoundError()
with self.assertRaises(ModuleNotFoundError):
lazy_loader._load()