-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_query_result_close.py
More file actions
130 lines (115 loc) · 3.58 KB
/
test_query_result_close.py
File metadata and controls
130 lines (115 loc) · 3.58 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
124
125
126
127
128
129
130
import subprocess
import sys
from pathlib import Path
from textwrap import dedent
import pytest
from conftest import get_db_file_path
from lbug_test_paths import LBUG_ROOT
def test_query_result_close(tmp_path: Path, build_dir: Path) -> None:
db_path = get_db_file_path(tmp_path)
code = dedent(f"""
import sys
sys.path.append(r"{build_dir!s}")
import ladybug as lb
db = lb.Database(r"{db_path!s}")
conn = lb.Connection(db)
conn.execute('''
CREATE NODE TABLE person (
ID INT64,
fName STRING,
gender INT64,
isStudent BOOLEAN,
isWorker BOOLEAN,
age INT64,
eyeSight DOUBLE,
birthdate DATE,
registerTime TIMESTAMP,
lastJobDuration INTERVAL,
workedHours INT64[],
usedNames STRING[],
courseScoresPerTerm INT64[][],
grades INT64[4],
height float,
u UUID,
PRIMARY KEY (ID))
''')
conn.execute('COPY person FROM "{LBUG_ROOT}/dataset/tinysnb/vPerson.csv" (HEADER=true)')
result = conn.execute("MATCH (a:person) WHERE a.ID = 0 RETURN a.isStudent;")
# result.close()
""")
result = subprocess.run([sys.executable, "-c", code])
assert result.returncode == 0
def test_pybind_native_close_is_idempotent(tmp_path: Path, build_dir: Path) -> None:
db_path = get_db_file_path(tmp_path)
code = dedent(f"""
import gc
import sys
sys.path.append(r"{build_dir!s}")
from ladybug._backend import get_pybind_module
pybind = get_pybind_module()
if pybind is None:
raise SystemExit(77)
db = pybind.Database(r"{db_path!s}")
conn = pybind.Connection(db)
result = conn.query("RETURN 1")
result.close()
result.close()
try:
result.hasNext()
except RuntimeError as exc:
assert "closed" in str(exc)
else:
raise AssertionError("closed query result remained usable")
del result
gc.collect()
conn.close()
conn.close()
try:
conn.query("RETURN 1")
except RuntimeError as exc:
assert "closed" in str(exc)
else:
raise AssertionError("closed connection remained usable")
del conn
gc.collect()
db.close()
db.close()
del db
gc.collect()
db = pybind.Database(r"{db_path!s}.db_first")
conn = pybind.Connection(db)
result = conn.query("RETURN 1")
statement = conn.prepare("RETURN 1")
db.close()
db.close()
try:
pybind.Connection(db)
except RuntimeError as exc:
assert "closed" in str(exc)
else:
raise AssertionError("connection opened on a closed database")
del db
gc.collect()
del statement
del result
del conn
gc.collect()
db = pybind.Database(r"{db_path!s}.child_result")
conn = pybind.Connection(db)
result = conn.query("RETURN 1; RETURN 2;")
child = result.getNextQueryResult()
result.close()
assert child.hasNext()
assert child.getNext() == [2]
conn.close()
db.close()
del child
del result
del conn
del db
gc.collect()
""")
result = subprocess.run([sys.executable, "-c", code])
if result.returncode == 77:
pytest.skip("pybind extension is not available")
assert result.returncode == 0