Skip to content

Commit 9621733

Browse files
committed
cp to tests
1 parent 5cf703f commit 9621733

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

tests/test_reconnection.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""
2+
Collection of test cases to test connection module.
3+
"""
4+
5+
from nose.tools import assert_true, assert_false, raises
6+
import datajoint as dj
7+
from datajoint import DataJointError
8+
from . import CONN_INFO
9+
10+
11+
class TestReconnect:
12+
"""
13+
test reconnection
14+
"""
15+
16+
def setup(self):
17+
self.conn = dj.conn(reset=True, **CONN_INFO)
18+
19+
def test_close(self):
20+
assert_true(self.conn.is_connected, "Connection should be alive")
21+
self.conn.close()
22+
assert_false(self.conn.is_connected, "Connection should now be closed")
23+
24+
def test_reconnect(self):
25+
assert_true(self.conn.is_connected, "Connection should be alive")
26+
self.conn.close()
27+
self.conn.query("SHOW DATABASES;", reconnect=True).fetchall()
28+
assert_true(self.conn.is_connected, "Connection should be alive")
29+
30+
@raises(DataJointError)
31+
def test_reconnect_throws_error_in_transaction(self):
32+
assert_true(self.conn.is_connected, "Connection should be alive")
33+
with self.conn.transaction:
34+
self.conn.close()
35+
self.conn.query("SHOW DATABASES;", reconnect=True).fetchall()

0 commit comments

Comments
 (0)