Exemplo n.º 1
0
 def test_method_parser(self):
   working_sigs = [
     ('jsonrpc', 'jsonrpc', OrderedDict(), Any),
     ('jsonrpc.methodName', 'jsonrpc.methodName', OrderedDict(), Any),
     ('jsonrpc.methodName() -> list', 'jsonrpc.methodName', OrderedDict(), list),
     ('jsonrpc.methodName(str, str, str ) ', 'jsonrpc.methodName', OrderedDict([('a', str), ('b', str), ('c', str)]), Any),
     ('jsonrpc.methodName(str, b=str, c=str)', 'jsonrpc.methodName', OrderedDict([('a', str), ('b', str), ('c', str)]), Any),
     ('jsonrpc.methodName(str, b=str) -> dict', 'jsonrpc.methodName', OrderedDict([('a', str), ('b', str)]), dict),
     ('jsonrpc.methodName(str, str, c=Any) -> Any', 'jsonrpc.methodName', OrderedDict([('a', str), ('b', str), ('c', Any)]), Any),
     ('jsonrpc(Any ) ->  Any', 'jsonrpc', OrderedDict([('a', Any)]), Any),
   ]
   error_sigs = [
     ('jsonrpc(str) -> nowai', ValueError),
     ('jsonrpc(nowai) -> Any', ValueError),
     ('jsonrpc(nowai=str, str)', ValueError),
     ('jsonrpc.methodName(nowai*str) -> Any', ValueError)
   ]
   for sig in working_sigs:
     ret = _parse_sig(sig[0], list(iter(sig[2])))
     self.assertEquals(ret[0], sig[1])
     self.assertEquals(ret[1], sig[2])
     self.assertEquals(ret[2], sig[3])
   for sig in error_sigs:
     e = None
     try:
       _parse_sig(sig[0], ['a'])
     except Exception as exc:
       e = exc
     self.assert_(type(e) is sig[1])
Exemplo n.º 2
0
 def test_method_parser(self):
   working_sigs = [
     ('jsonrpc', 'jsonrpc', SortedDict(), Any),
     ('jsonrpc.methodName', 'jsonrpc.methodName', SortedDict(), Any),
     ('jsonrpc.methodName() -> list', 'jsonrpc.methodName', SortedDict(), list),
     ('jsonrpc.methodName(str, str, str ) ', 'jsonrpc.methodName', SortedDict([('a', str), ('b', str), ('c', str)]), Any),
     ('jsonrpc.methodName(str, b=str, c=str)', 'jsonrpc.methodName', SortedDict([('a', str), ('b', str), ('c', str)]), Any),
     ('jsonrpc.methodName(str, b=str) -> dict', 'jsonrpc.methodName', SortedDict([('a', str), ('b', str)]), dict),
     ('jsonrpc.methodName(str, str, c=Any) -> Any', 'jsonrpc.methodName', SortedDict([('a', str), ('b', str), ('c', Any)]), Any),
     ('jsonrpc(Any ) ->  Any', 'jsonrpc', SortedDict([('a', Any)]), Any),
   ]
   error_sigs = [
     ('jsonrpc(str) -> nowai', ValueError),
     ('jsonrpc(nowai) -> Any', ValueError),
     ('jsonrpc(nowai=str, str)', ValueError),
     ('jsonrpc.methodName(nowai*str) -> Any', ValueError)
   ]
   for sig in working_sigs:
     ret = _parse_sig(sig[0], list(iter(sig[2])))
     self.assertEquals(ret[0], sig[1])
     self.assertEquals(ret[1], sig[2])
     self.assertEquals(ret[2], sig[3])
   for sig in error_sigs:
     e = None
     try:
       _parse_sig(sig[0], ['a'])
     except Exception, exc:
       e = exc
     self.assert_(type(e) is sig[1])