-
Notifications
You must be signed in to change notification settings - Fork 7
/
conftest.py
76 lines (55 loc) · 1.95 KB
/
conftest.py
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
import numpy
import pytest
from shutil import rmtree
import monetdbe
@pytest.fixture(scope="function")
def monetdbe_empty_cursor(request, tmp_path):
test_dbfarm = tmp_path.resolve().as_posix()
connection = monetdbe.connect(test_dbfarm)
def finalizer():
if tmp_path.is_dir():
connection.close()
rmtree(test_dbfarm, ignore_errors=True)
request.addfinalizer(finalizer)
cursor = connection.cursor()
return cursor
@pytest.fixture(scope="function")
def monetdbe_cursor(request, tmp_path):
test_dbfarm = tmp_path.resolve().as_posix()
connection = monetdbe.connect(test_dbfarm)
def finalizer():
if tmp_path.is_dir():
connection.close()
rmtree(test_dbfarm, ignore_errors=True)
request.addfinalizer(finalizer)
cursor = connection.cursor()
cursor.create('integers', {'i': numpy.arange(10)})
cursor.execute('INSERT INTO integers VALUES(NULL)')
return cursor
@pytest.fixture(scope="function")
def monetdbe_cursor_autocommit(tmp_path):
test_dbfarm = tmp_path.resolve().as_posix()
connection = monetdbe.connect(test_dbfarm)
connection.set_autocommit(True)
cursor = connection.cursor()
class Context:
def __init__(self, cursor, connection, dbfarm):
self.cursor = cursor
self.connection = connection
self.dbfarm = dbfarm
context = Context(cursor, connection, test_dbfarm)
yield context
if tmp_path.is_dir():
context.connection.close()
rmtree(context.dbfarm, ignore_errors=True)
@pytest.fixture(scope="function")
def initialize_monetdbe(request, tmp_path):
test_dbfarm = tmp_path.resolve().as_posix()
connection = monetdbe.connect(test_dbfarm)
def finalizer():
if tmp_path.is_dir():
connection.close()
rmtree(test_dbfarm, ignore_errors=True)
request.addfinalizer(finalizer)
monetdbe.connect(test_dbfarm)
return test_dbfarm