示例#1
0
文件: tests.py 项目: keredson/dsprpc
 def test_function_with_arg_and_kwarg(self):
   class O(object):
     def x(self, y, default=12):
       return y+default
   s = dsprpc.DSPRPCServer(O())
   client = dsprpc.DSPRPCClient()
   self.assertEqual(client.x(1), 13)
   self.assertEqual(client.x(2, default=40), 42)
   s.shutdown()
示例#2
0
文件: tests.py 项目: keredson/dsprpc
 def test_function_with_kwarg(self):
   class O(object):
     def x(self, default=12):
       return default
   s = dsprpc.DSPRPCServer(O())
   client = dsprpc.DSPRPCClient()
   self.assertEqual(client.x(), 12)
   self.assertEqual(client.x(default=42), 42)
   s.shutdown()
示例#3
0
文件: tests.py 项目: keredson/dsprpc
 def test_speed(self):
   s = dsprpc.DSPRPCServer("Derek Anderson")
   client = dsprpc.DSPRPCClient()
   n = 100
   start = time.clock()
   for i in range(100):
     client.lower()
   end = time.clock()
   took = end-start
   print('%i requests took %fs' % (n, took)) # 0.4s on my machine
   self.assertLess(took, 2)
   s.shutdown()
示例#4
0
文件: tests.py 项目: keredson/dsprpc
 def test_threading(self):
   class O(object):
     def y(self):
       time.sleep(1)
       return 'woot'
   s = dsprpc.DSPRPCServer(O())
   client = dsprpc.DSPRPCClient()
   def f():
     client.y()
   threads = [threading.Thread(target=f) for i in range(5)]
   start = time.clock()
   [t.start() for t in threads]
   [t.join() for t in threads]
   end = time.clock()
   took = end-start
   self.assertLess(took, 3)
   s.shutdown()
示例#5
0
文件: tests.py 项目: keredson/dsprpc
 def test_no_server(self):
   client = dsprpc.DSPRPCClient()
   with self.assertRaises(requests.exceptions.ConnectionError):
     client.lower()
示例#6
0
文件: tests.py 项目: keredson/dsprpc
 def test_error(self):
   s = dsprpc.DSPRPCServer("Derek Anderson")
   client = dsprpc.DSPRPCClient()
   with self.assertRaises(AttributeError):
     client.not_a_function()
   s.shutdown()
示例#7
0
文件: tests.py 项目: keredson/dsprpc
 def test_function(self):
   s = dsprpc.DSPRPCServer("Derek Anderson")
   client = dsprpc.DSPRPCClient()
   self.assertEqual(client.lower(), 'derek anderson')
   s.shutdown()
示例#8
0
文件: tests.py 项目: keredson/dsprpc
 def test_attribute(self):
   cls = collections.namedtuple('Woot',['derek'])
   s = dsprpc.DSPRPCServer(cls('anderson'))
   client = dsprpc.DSPRPCClient()
   self.assertEqual(client.derek, 'anderson')
   s.shutdown()
示例#9
0
文件: tests.py 项目: keredson/dsprpc
 def test_function_with_missing_arg(self):
   s = dsprpc.DSPRPCServer("derek")
   client = dsprpc.DSPRPCClient()
   with self.assertRaises(TypeError):
     client.center()
   s.shutdown()
示例#10
0
文件: tests.py 项目: keredson/dsprpc
 def test_function_with_arg(self):
   s = dsprpc.DSPRPCServer("derek")
   client = dsprpc.DSPRPCClient()
   self.assertEqual(client.center(9), '  derek  ')
   s.shutdown()