def test__forward_close_returns_true_if_response(): driver = CIPDriver(CONNECT_PATH) driver._session = 1 response = ( b"o\x00\x1e\x00\x02\x16\x02\x0b\x00\x00\x00\x00_pycomm_" b"\x00\x00\x00\x00\x00\x00\x00\x00\n\x00\x02\x00\x00\x00" b"\x00\x00\xb2\x00\x0e\x00\xce\x00\x00\x00'\x04\t\x10\xd6\x9c\x06=\x00\x00" ) driver._sock = Mocket(response) assert driver._forward_close()
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()
def test__forward_open_returns_false_if_falsy_response(): driver = CIPDriver(CONNECT_PATH) driver._sock = Mocket() driver._session = 1 assert not driver._forward_open()
def test_close_raises_no_error_on_close_with_registered_session(): driver = CIPDriver(CONNECT_PATH) driver._session = 1 driver._sock = Mocket() driver.close()