def test_misc(protocol): '''Misc tests to get full coverage.''' connection = JSONRPCConnection(protocol) with pytest.raises(ProtocolError): connection.receive_message(b'[]') with pytest.raises(AssertionError): connection.send_request(Response(2)) request = Request('a', []) assert request.send_result(2) is None
def test_Batch(): b = Batch([Request("m", []), Request("n", [])]) assert repr(b) == "Batch(2 items)" with pytest.raises(ProtocolError) as e: Batch([Request('m', []), Response(2)]) assert e.value.code == JSONRPC.INVALID_REQUEST assert 'homogeneous' in e.value.message with pytest.raises(ProtocolError) as e: Batch([b]) assert e.value.code == JSONRPC.INVALID_REQUEST with pytest.raises(ProtocolError) as e: Batch(2) assert e.value.code == JSONRPC.INVALID_REQUEST assert 'must be a list' in e.value.message with pytest.raises(ProtocolError) as e: Batch((x for x in (1, ))) assert e.value.code == JSONRPC.INVALID_REQUEST assert 'must be a list' in e.value.message assert b[:2] == b.items[:2]