@@ -15,6 +15,12 @@ def hello(self):
1515 def sum (self , x , y ):
1616 return x + y
1717
18+ def nil (self ):
19+ return None
20+
21+ def raise_error (self ):
22+ raise Exception ('error' )
23+
1824
1925 def setUp (self ):
2026 self ._address = msgpackrpc .Address ('localhost' , helper .unused_port ())
@@ -39,33 +45,46 @@ def tearDown(self):
3945
4046 def test_call (self ):
4147 client = self .setup_env ();
42- result = client .call ('hello' )
43- self .assertEqual (result , "world" , "'hello' result is incorrect" )
4448
45- result = client .call ('sum' , 1 , 2 )
46- self .assertEqual (result , 3 , "'sum' result is incorrect" )
49+ result1 = client .call ('hello' )
50+ result2 = client .call ('sum' , 1 , 2 )
51+ result3 = client .call ('nil' )
52+
53+ self .assertEqual (result1 , "world" , "'hello' result is incorrect" )
54+ self .assertEqual (result2 , 3 , "'sum' result is incorrect" )
55+ self .assertIsNone (result3 , "'nil' result is incorrect" )
4756
4857 def test_call_async (self ):
4958 client = self .setup_env ();
5059
51- feture1 = client .call_async ('hello' )
52- feture2 = client .call_async ('sum' , 1 , 2 )
53- feture1 .join ()
54- feture2 .join ()
60+ future1 = client .call_async ('hello' )
61+ future2 = client .call_async ('sum' , 1 , 2 )
62+ future3 = client .call_async ('nil' )
63+ future1 .join ()
64+ future2 .join ()
65+ future3 .join ()
5566
56- self .assertEqual (feture1 .result , "world" , "'hello' result is incorrect in call_async" )
57- self .assertEqual (feture2 .result , 3 , "'sum' result is incorrect in call_async" )
67+ self .assertEqual (future1 .result , "world" , "'hello' result is incorrect in call_async" )
68+ self .assertEqual (future2 .result , 3 , "'sum' result is incorrect in call_async" )
69+ self .assertIsNone (future3 .result , "'nil' result is incorrect in call_async" )
5870
5971 def test_notify (self ):
6072 client = self .setup_env ();
73+
6174 result = True
6275 try :
6376 client .notify ('hello' )
6477 client .notify ('sum' , 1 , 2 )
78+ client .notify ('nil' )
6579 except :
6680 result = False
81+
6782 self .assertTrue (result )
6883
84+ def test_raise_error (self ):
85+ client = self .setup_env ();
86+ self .assertRaises (error .RPCError , lambda : client .call ('raise_error' ))
87+
6988 def test_unknown_method (self ):
7089 client = self .setup_env ();
7190 self .assertRaises (error .RPCError , lambda : client .call ('unknown' , True ))
@@ -76,6 +95,5 @@ def test_unknown_method(self):
7695 message = e .args [0 ]
7796 self .assertEqual (message , "'unknown' method not found" , "Error message mismatched" )
7897
79-
8098if __name__ == '__main__' :
8199 unittest .main ()
0 commit comments