def test_get_connection(): """ Test getting connection from the local thread. """ repl = Repl() assert repl.get_connection() is None assert repl.is_repl_active is False
def test_clear_not_existing_connection(): """ Test clearing connection from the local thread which was never set. """ repl = Repl() repl.clear_connection() assert repl.get_connection() is None assert repl.is_repl_active is False
def test_set_connection(): """ Test setting connection on the local thread. """ repl = Repl() connection = TestConnection() repl.set_connection(connection) assert repl.get_connection() == connection assert repl.is_repl_active is True
def test_get_existing_connection(): """ Test getting existing connection from the local thread. """ repl = Repl() connection = TestConnection() repl.set_connection(connection) assert repl.get_connection() == connection assert repl.is_repl_active is True
def test_get_thread_data(mock_threading): """ Test getting thread data from the Repl object. """ local_thread_data = Mock() delattr(local_thread_data, REPL_CONNECTION_ATTRIBUTE) mock_threading.local.return_value = local_thread_data repl = Repl() connection = repl.get_connection() assert connection is None assert repl.is_repl_active is False
def test_get_existing_thread_data(mock_threading): """ Test getting existing thread data from the Repl object. """ expected_connection = Mock() local_thread_data = Mock() setattr(local_thread_data, REPL_CONNECTION_ATTRIBUTE, expected_connection) mock_threading.local.return_value = local_thread_data repl = Repl() connection = repl.get_connection() assert connection == expected_connection
def test_clear_not_existing_thread_data(mock_threading): """ Test clearing the thread data. """ local_thread_data = Mock() delattr(local_thread_data, REPL_CONNECTION_ATTRIBUTE) mock_threading.local.return_value = local_thread_data repl = Repl() repl.clear_connection() connection = repl.get_connection() assert connection is None assert repl.is_repl_active is False
def test_set_connection_on_thread(mock_threading): """ Test setting connection on thread when no previous connection was set. """ expected_connection = Mock() local_thread_data = Mock() delattr(local_thread_data, REPL_CONNECTION_ATTRIBUTE) mock_threading.local.return_value = local_thread_data repl = Repl() repl.set_connection(expected_connection) assert repl.get_connection() == expected_connection assert repl.is_repl_active is True
def test_override_connection_on_thread(mock_threading): """ Test setting connection on thread when a previous connection was already set. """ original_connection = Mock() expected_connection = Mock() local_thread_data = Mock() setattr(local_thread_data, REPL_CONNECTION_ATTRIBUTE, original_connection) mock_threading.local.return_value = local_thread_data repl = Repl() repl.set_connection(expected_connection) assert repl.get_connection() == expected_connection assert repl.is_repl_active is True
def test_init(mock_threading): """ Test initialization of REPL object. """ repl = Repl() assert repl.is_repl_active is False assert repl.thread_data == mock_threading.local.return_value
def test_clear_connection(): """ Test clearing connection from the local thread. """ repl = Repl() connection = TestConnection() repl.set_connection(connection) repl.clear_connection() assert repl.get_connection() is None assert repl.is_repl_active is False
def test_override_connection(): """ Test overriding connection on the local thread. """ repl = Repl() original_connection = TestConnection() new_connection = TestConnection() repl.set_connection(original_connection) assert repl.get_connection() == original_connection assert repl.is_repl_active is True repl.set_connection(new_connection) assert repl.get_connection() == new_connection assert repl.is_repl_active is True