<s> import pytest <EOL> import _compat <EOL> from six . moves . mock import Mock <EOL> from tinyrpc . exc import RPCError <EOL> from tinyrpc . client import RPCClient , RPCProxy <EOL> from tinyrpc . protocols import RPCProtocol , RPCResponse , RPCErrorResponse <EOL> from tinyrpc . transports import ClientTransport <EOL> @ pytest . fixture ( params = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def method_name ( request ) : <EOL> return request . param <EOL> @ pytest . fixture ( params = [ ( ) , ( '<STR_LIT:foo>' , None , <NUM_LIT> ) , ( <NUM_LIT:1> , ) ] ) <EOL> def method_args ( request ) : <EOL> return request . param <EOL> @ pytest . fixture ( params = [ ( ) , ( ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) , ( '<STR_LIT:x>' , None ) , ( '<STR_LIT:y>' , <NUM_LIT> ) ) , <EOL> ( ( '<STR_LIT:q>' , <NUM_LIT:1> ) , ) ] ) <EOL> def method_kwargs ( request ) : <EOL> return dict ( request . param or { } ) <EOL> @ pytest . fixture ( params = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def prefix ( request ) : <EOL> return request . param <EOL> @ pytest . fixture ( params = [ True , False ] ) <EOL> def one_way_setting ( request ) : <EOL> return request . param <EOL> @ pytest . fixture <EOL> def mock_client ( ) : <EOL> return Mock ( RPCClient ) <EOL> @ pytest . fixture <EOL> def mock_protocol ( ) : <EOL> mproto = Mock ( RPCProtocol ) <EOL> foo = Mock ( RPCResponse ) <EOL> foo . result = None <EOL> mproto . parse_reply = Mock ( return_value = foo ) <EOL> return mproto <EOL> @ pytest . fixture <EOL> def mock_transport ( ) : <EOL> return Mock ( ClientTransport ) <EOL> @ pytest . fixture ( ) <EOL> def client ( mock_protocol , mock_transport ) : <EOL> return RPCClient ( mock_protocol , mock_transport ) <EOL> @ pytest . fixture <EOL> def m_proxy ( mock_client , prefix , one_way_setting ) : <EOL> return RPCProxy ( mock_client , prefix , one_way_setting ) <EOL> def test_proxy_calls_correct_method ( m_proxy , mock_client , <EOL> prefix , method_kwargs , method_args , <EOL> method_name , one_way_setting ) : <EOL> getattr ( m_proxy , method_name ) ( * method_args , ** method_kwargs ) <EOL> mock_client . call . assert_called_with ( <EOL> prefix + method_name , method_args , method_kwargs , <EOL> one_way = one_way_setting <EOL> ) <EOL> def test_client_uses_correct_protocol ( client , mock_protocol , method_name , <EOL> method_args , method_kwargs , <EOL> one_way_setting ) : <EOL> client . call ( method_name , method_args , method_kwargs , one_way_setting ) <EOL> assert mock_protocol . create_request . called <EOL> def test_client_uses_correct_transport ( client , mock_protocol , method_name , <EOL> method_args , method_kwargs , <EOL> one_way_setting , mock_transport ) : <EOL> client . call ( method_name , method_args , method_kwargs , one_way_setting ) <EOL> assert mock_transport . send_message . called <EOL> def test_client_passes_correct_reply ( client , mock_protocol , method_name , <EOL> method_args , method_kwargs , <EOL> one_way_setting , mock_transport ) : <EOL> transport_return = '<STR_LIT>' <EOL> mock_transport . send_message = Mock ( return_value = transport_return ) <EOL> client . call ( method_name , method_args , method_kwargs , one_way_setting ) <EOL> mock_protocol . parse_reply . assert_called_with ( transport_return ) <EOL> def test_client_raises_error_replies ( client , mock_protocol , method_name , <EOL> method_args , method_kwargs , <EOL> one_way_setting ) : <EOL> error_response = RPCErrorResponse ( ) <EOL> error_response . error = '<STR_LIT:foo>' <EOL> mock_protocol . parse_reply = Mock ( return_value = error_response ) <EOL> with pytest . raises ( RPCError ) : <EOL> client . call ( method_name , method_args , method_kwargs , one_way_setting ) </s>
