<s> import lymph <EOL> from lymph . core import trace <EOL> from lymph . core . interfaces import Interface <EOL> from lymph . core . messages import Message <EOL> from lymph . testing import RPCServiceTestCase <EOL> from lymph . exceptions import RemoteError , Nack <EOL> class Upper ( Interface ) : <EOL> service_type = '<STR_LIT>' <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( Upper , self ) . __init__ ( * args , ** kwargs ) <EOL> self . eventlog = [ ] <EOL> @ lymph . rpc ( ) <EOL> def upper ( self , text = None ) : <EOL> return text . upper ( ) <EOL> @ lymph . rpc ( ) <EOL> def indirect_upper ( self , text = None ) : <EOL> return self . upper ( text ) <EOL> @ lymph . rpc ( raises = ( ValueError , ) ) <EOL> def fail ( self ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> @ lymph . raw_rpc ( ) <EOL> def just_ack ( self , channel ) : <EOL> channel . ack ( ) <EOL> @ lymph . rpc ( ) <EOL> def auto_nack ( self ) : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> @ lymph . event ( '<STR_LIT:foo>' ) <EOL> def on_foo_event ( self , event ) : <EOL> self . eventlog . append ( ( event . evt_type , event . body ) ) <EOL> @ lymph . rpc ( ) <EOL> def get_trace_id ( self ) : <EOL> return trace . get_id ( ) <EOL> class BasicMockTest ( RPCServiceTestCase ) : <EOL> service_class = Upper <EOL> service_name = '<STR_LIT>' <EOL> def test_upper ( self ) : <EOL> reply = self . client . upper ( text = '<STR_LIT:foo>' ) <EOL> self . assertEqual ( reply , '<STR_LIT>' ) <EOL> def test_indirect_upper ( self ) : <EOL> reply = self . client . indirect_upper ( text = '<STR_LIT:foo>' ) <EOL> self . assertEqual ( reply , '<STR_LIT>' ) <EOL> def test_ping ( self ) : <EOL> reply = self . request ( '<STR_LIT>' , { '<STR_LIT>' : <NUM_LIT> } ) <EOL> self . assertEqual ( reply . body , <NUM_LIT> ) <EOL> def test_status ( self ) : <EOL> reply = self . request ( '<STR_LIT>' , { } ) <EOL> self . assertEqual ( reply . body , { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> def test_error ( self ) : <EOL> with self . assertRaisesRegexp ( RemoteError , '<STR_LIT>' ) : <EOL> self . client . fail ( ) <EOL> def test_exception_handling ( self ) : <EOL> with self . assertRaises ( RemoteError . ValueError ) : <EOL> self . client . fail ( ) <EOL> def test_ack ( self ) : <EOL> reply = self . request ( '<STR_LIT>' , { } ) <EOL> self . assertIsNone ( reply . body ) <EOL> self . assertEqual ( reply . type , Message . ACK ) <EOL> def test_auto_nack ( self ) : <EOL> with self . assertRaises ( Nack ) : <EOL> self . client . auto_nack ( ) <EOL> def test_events ( self ) : <EOL> log = self . service . eventlog <EOL> self . assertEqual ( log , [ ] ) <EOL> self . emit ( '<STR_LIT:foo>' , { '<STR_LIT>' : <NUM_LIT> } ) <EOL> self . assertEqual ( log , [ ( '<STR_LIT:foo>' , { '<STR_LIT>' : <NUM_LIT> } ) ] ) <EOL> self . emit ( '<STR_LIT:foo>' , { '<STR_LIT>' : <NUM_LIT> } ) <EOL> self . assertEqual ( log , [ ( '<STR_LIT:foo>' , { '<STR_LIT>' : <NUM_LIT> } ) , ( '<STR_LIT:foo>' , { '<STR_LIT>' : <NUM_LIT> } ) ] ) <EOL> def test_inspect ( self ) : <EOL> proxy = self . get_proxy ( namespace = '<STR_LIT>' ) <EOL> methods = proxy . inspect ( ) [ '<STR_LIT>' ] <EOL> self . assertEqual ( set ( m [ '<STR_LIT:name>' ] for m in methods ) , set ( [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> ] ) ) <EOL> def test_trace_id_propagates_via_rpc ( self ) : <EOL> trace_id = trace . get_id ( ) <EOL> self . assertEqual ( trace_id , self . client . get_trace_id ( ) ) <EOL> def test_trace_id_propagates_via_deferred_rpc ( self ) : <EOL> trace_id = trace . get_id ( ) <EOL> self . assertEqual ( trace_id , self . client . get_trace_id . defer ( ) . get ( ) ) </s>
