Exemplo n.º 1
0
def test_close_raises_commerror_on_socket_close_exception():
    with mock.patch.object(Socket, 'close') as mock_close:
        mock_close.side_effect = Exception
        with pytest.raises(CommError):
            driver = CIPDriver(CONNECT_PATH)
            driver._sock = Socket()
            driver.close()
Exemplo n.º 2
0
def test_close_raises_commerror_on_any_exception(mock_method, exception):
    """Raise a CommError if any CIPDriver methods raise exception.
    
    There are two CIPDriver methods called within close:
        CIPDriver._forward_close()
        CIPDriver._un_register_session()

    If those internal methods change, this test will break. I think
    that's acceptable and any changes to this method should make the
    author very aware that they have changed this method.
    """
    with mock.patch.object(CIPDriver, mock_method) as mock_method:
        mock_method.side_effect = exception
        with pytest.raises(CommError):
            driver = CIPDriver(CONNECT_PATH)
            driver._target_is_connected = True
            driver._session = 1
            driver.close()
Exemplo n.º 3
0
def test_close_calls_socket_close_if_socket():
    with mock.patch.object(Mocket, 'close') as mock_close:
        driver = CIPDriver(CONNECT_PATH)
        driver._sock = Mocket()
        driver.close()
        assert mock_close.called
Exemplo n.º 4
0
def test_close_raises_no_error_on_close_with_registered_session():
    driver = CIPDriver(CONNECT_PATH)
    driver._session = 1
    driver._sock = Mocket()
    driver.close()