예제 #1
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()
예제 #2
0
def test__forward_open_returns_true_if_already_connected():
    driver = CIPDriver(CONNECT_PATH)
    driver._target_is_connected = True
    assert driver._forward_open()