forked from long2ice/asynch
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconftest.py
More file actions
77 lines (64 loc) · 1.98 KB
/
conftest.py
File metadata and controls
77 lines (64 loc) · 1.98 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
import asyncio
from asyncio.streams import StreamReader
import pytest
import asynch
from asynch import connect
from asynch.cursors import DictCursor
from asynch.proto import constants
from asynch.proto.context import Context
from asynch.proto.streams.buffered import BufferedReader, BufferedWriter
@pytest.fixture
def column_options():
reader = BufferedReader(StreamReader(), constants.BUFFER_SIZE)
writer = BufferedWriter()
context = Context()
context.client_settings = {
"strings_as_bytes": False,
"strings_encoding": constants.STRINGS_ENCODING,
}
column_options = {"reader": reader, "writer": writer, "context": context}
return column_options
@pytest.fixture(scope="session")
def event_loop():
policy = asyncio.get_event_loop_policy()
res = policy.new_event_loop()
asyncio.set_event_loop(res)
res._close = res.close
res.close = lambda: None
yield res
res._close()
@pytest.fixture(scope="session", autouse=True)
async def initialize_tests():
conn = await connect()
async with conn.cursor(cursor=DictCursor) as cursor:
await cursor.execute('create database if not exists test')
await cursor.execute("""CREATE TABLE if not exists test.asynch
(
`id` Int32,
`decimal` Decimal(10, 2),
`date` Date,
`datetime` DateTime,
`float` Float32,
`uuid` UUID,
`string` String,
`ipv4` IPv4,
`ipv6` IPv6,
`bool` Bool
)
ENGINE = MergeTree
ORDER BY id""")
yield
await conn.close()
@pytest.fixture(scope="function", autouse=True)
async def truncate_table():
conn = await connect()
async with conn.cursor(cursor=DictCursor) as cursor:
await cursor.execute("truncate table test.asynch")
yield
await conn.close()
@pytest.fixture(scope="function")
async def pool():
pool = await asynch.create_pool()
yield pool
pool.close()
await pool.wait_closed()