-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1133 from ethho/dev-tests-plat-161-reconn
PLAT-161: Migrate test_reconnection
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
""" | ||
Collection of test cases to test connection module. | ||
""" | ||
|
||
import pytest | ||
import datajoint as dj | ||
from datajoint import DataJointError | ||
from . import CONN_INFO | ||
|
||
|
||
@pytest.fixture | ||
def conn(connection_root): | ||
return dj.conn(reset=True, **CONN_INFO) | ||
|
||
|
||
class TestReconnect: | ||
""" | ||
Test reconnection | ||
""" | ||
|
||
def test_close(self, conn): | ||
assert conn.is_connected, "Connection should be alive" | ||
conn.close() | ||
assert not conn.is_connected, "Connection should now be closed" | ||
|
||
def test_reconnect(self, conn): | ||
assert conn.is_connected, "Connection should be alive" | ||
conn.close() | ||
conn.query("SHOW DATABASES;", reconnect=True).fetchall() | ||
assert conn.is_connected, "Connection should be alive" | ||
|
||
def test_reconnect_throws_error_in_transaction(self, conn): | ||
assert conn.is_connected, "Connection should be alive" | ||
with conn.transaction, pytest.raises(DataJointError): | ||
conn.close() | ||
conn.query("SHOW DATABASES;", reconnect=True).fetchall() |