-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconftest.py
More file actions
123 lines (84 loc) · 3.2 KB
/
Copy pathconftest.py
File metadata and controls
123 lines (84 loc) · 3.2 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import os
import sqlite3
from copy import deepcopy
import pytest
from dotenv import load_dotenv
import sqlitecloud
from sqlitecloud.client import SQLiteCloudClient
from sqlitecloud.datatypes import SQLiteCloudAccount, SQLiteCloudConnect
@pytest.fixture(autouse=True)
def load_env_vars():
load_dotenv(".env")
@pytest.fixture(autouse=True)
def reset_module_state():
original_sqlc_adapters = deepcopy(sqlitecloud.adapters)
original_sqlc_converters = deepcopy(sqlitecloud.converters)
original_sql_adapters = deepcopy(sqlite3.adapters)
original_sql_converters = deepcopy(sqlite3.converters)
yield
sqlitecloud.adapters.clear()
sqlitecloud.converters.clear()
sqlite3.adapters.clear()
sqlite3.converters.clear()
sqlitecloud.adapters.update(original_sqlc_adapters)
sqlitecloud.converters.update(original_sqlc_converters)
sqlite3.adapters.update(original_sql_adapters)
sqlite3.converters.update(original_sql_converters)
@pytest.fixture()
def sqlitecloud_connection():
account = SQLiteCloudAccount()
account.username = os.getenv("SQLITE_USER")
account.password = os.getenv("SQLITE_PASSWORD")
account.dbname = os.getenv("SQLITE_DB")
account.hostname = os.getenv("SQLITE_HOST")
account.port = int(os.getenv("SQLITE_PORT"))
client = SQLiteCloudClient(cloud_account=account)
connection = client.open_connection()
assert isinstance(connection, SQLiteCloudConnect)
assert client.is_connected(connection)
yield (connection, client)
client.disconnect(connection)
@pytest.fixture()
def sqlitecloud_dbapi2_connection():
# fixture and declaration are split to be able
# to create multiple instances of the connection
# when calling the getter function directly from
# the test.
# Fixtures are both cached and cannot be called
# directly whithin the test.
connection_generator = get_sqlitecloud_dbapi2_connection()
connection = next(connection_generator)
yield connection
close_generator(connection_generator)
def get_sqlitecloud_dbapi2_connection(detect_types: int = 0):
account = SQLiteCloudAccount()
account.username = os.getenv("SQLITE_USER")
account.password = os.getenv("SQLITE_PASSWORD")
account.dbname = os.getenv("SQLITE_DB")
account.hostname = os.getenv("SQLITE_HOST")
account.port = int(os.getenv("SQLITE_PORT"))
connection = sqlitecloud.connect(account, detect_types=detect_types)
assert isinstance(connection, sqlitecloud.Connection)
yield connection
connection.close()
@pytest.fixture()
def sqlite3_connection():
connection_generator = get_sqlite3_connection()
connection = next(connection_generator)
yield connection
close_generator(connection_generator)
def get_sqlite3_connection(detect_types: int = 0):
# set isolation_level=None to enable autocommit
# and to be aligned with the behavior of SQLite Cloud
connection = sqlite3.connect(
os.path.join(os.path.dirname(__file__), "./assets/chinook.sqlite"),
isolation_level=None,
detect_types=detect_types,
)
yield connection
connection.close()
def close_generator(generator):
try:
next(generator)
except StopIteration:
pass