From 9621733aa1febffee86cd6677e735b314853f225 Mon Sep 17 00:00:00 2001 From: Ethan Ho Date: Wed, 13 Dec 2023 11:06:27 -0700 Subject: [PATCH 1/3] cp to tests --- tests/test_reconnection.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/test_reconnection.py diff --git a/tests/test_reconnection.py b/tests/test_reconnection.py new file mode 100644 index 000000000..b275766ae --- /dev/null +++ b/tests/test_reconnection.py @@ -0,0 +1,35 @@ +""" +Collection of test cases to test connection module. +""" + +from nose.tools import assert_true, assert_false, raises +import datajoint as dj +from datajoint import DataJointError +from . import CONN_INFO + + +class TestReconnect: + """ + test reconnection + """ + + def setup(self): + self.conn = dj.conn(reset=True, **CONN_INFO) + + def test_close(self): + assert_true(self.conn.is_connected, "Connection should be alive") + self.conn.close() + assert_false(self.conn.is_connected, "Connection should now be closed") + + def test_reconnect(self): + assert_true(self.conn.is_connected, "Connection should be alive") + self.conn.close() + self.conn.query("SHOW DATABASES;", reconnect=True).fetchall() + assert_true(self.conn.is_connected, "Connection should be alive") + + @raises(DataJointError) + def test_reconnect_throws_error_in_transaction(self): + assert_true(self.conn.is_connected, "Connection should be alive") + with self.conn.transaction: + self.conn.close() + self.conn.query("SHOW DATABASES;", reconnect=True).fetchall() From f3a5dd1f36d761a0bef720c402c03c2ff27e3c85 Mon Sep 17 00:00:00 2001 From: Ethan Ho Date: Wed, 13 Dec 2023 11:06:49 -0700 Subject: [PATCH 2/3] nose2pytest test_reconnection --- tests/test_reconnection.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/test_reconnection.py b/tests/test_reconnection.py index b275766ae..6eb0343b5 100644 --- a/tests/test_reconnection.py +++ b/tests/test_reconnection.py @@ -17,19 +17,19 @@ def setup(self): self.conn = dj.conn(reset=True, **CONN_INFO) def test_close(self): - assert_true(self.conn.is_connected, "Connection should be alive") + assert self.conn.is_connected, "Connection should be alive" self.conn.close() - assert_false(self.conn.is_connected, "Connection should now be closed") + assert not self.conn.is_connected, "Connection should now be closed" def test_reconnect(self): - assert_true(self.conn.is_connected, "Connection should be alive") + assert self.conn.is_connected, "Connection should be alive" self.conn.close() self.conn.query("SHOW DATABASES;", reconnect=True).fetchall() - assert_true(self.conn.is_connected, "Connection should be alive") + assert self.conn.is_connected, "Connection should be alive" @raises(DataJointError) def test_reconnect_throws_error_in_transaction(self): - assert_true(self.conn.is_connected, "Connection should be alive") + assert self.conn.is_connected, "Connection should be alive" with self.conn.transaction: self.conn.close() self.conn.query("SHOW DATABASES;", reconnect=True).fetchall() From e3672f60e68913a3bde1267350abc8bfdf39a1c6 Mon Sep 17 00:00:00 2001 From: Ethan Ho Date: Wed, 13 Dec 2023 11:11:17 -0700 Subject: [PATCH 3/3] Migrate test_reconnection --- tests/test_reconnection.py | 45 +++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/tests/test_reconnection.py b/tests/test_reconnection.py index 6eb0343b5..262531243 100644 --- a/tests/test_reconnection.py +++ b/tests/test_reconnection.py @@ -2,34 +2,35 @@ Collection of test cases to test connection module. """ -from nose.tools import assert_true, assert_false, raises +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 + Test reconnection """ - def setup(self): - self.conn = dj.conn(reset=True, **CONN_INFO) - - def test_close(self): - assert self.conn.is_connected, "Connection should be alive" - self.conn.close() - assert not self.conn.is_connected, "Connection should now be closed" - - def test_reconnect(self): - assert self.conn.is_connected, "Connection should be alive" - self.conn.close() - self.conn.query("SHOW DATABASES;", reconnect=True).fetchall() - assert self.conn.is_connected, "Connection should be alive" - - @raises(DataJointError) - def test_reconnect_throws_error_in_transaction(self): - assert self.conn.is_connected, "Connection should be alive" - with self.conn.transaction: - self.conn.close() - self.conn.query("SHOW DATABASES;", reconnect=True).fetchall() + 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()