def test_check_params(self): s = Signature(lambda slf, x, y: x, x=Int(), y=Unicode()) s.check_params([None, 1, u"a"], {}) self.assertRaises(RpcCheckError, s.check_params, [None, u"a", u"a"], {}) self.assertRaises(RpcCheckError, s.check_params, [None, 1, 2], {}) self.assertRaises(RpcCheckError, s.check_params, [None, 1, u"a", 3], {})
def test_param_doc(self): s = Signature(lambda slf, x: x, x=Int("foo"), returns=Int("bar")) self.assertEqual(s.param_doc(), [ ':param Int x:', ' foo', ':rtype Int:', ' bar'])
def test_jsonrpc_signature(self): s = Signature(lambda slf, x: unicode(x), x=Int("foo"), returns=Unicode("bar")) self.assertEqual(s.jsonrpc_signature(), [['string', 'int']])
def test_check_result(self): s = Signature(lambda slf, x: x, x=Int("foo"), returns=Int("bar")) self.assertEqual(s.check_result(5), 5) self.assertRaises(RpcCheckError, s.check_result, 'a')
def test_check_params_with_defaults(self): s = Signature(lambda slf, x, y=u"default": x, x=Int(), y=Unicode()) s.check_params([None, 1, u"a"], {}) s.check_params([None, 1], {})
def test_param_doc(self): s = Signature(lambda slf, x: x, x=Int("foo"), returns=Int("bar")) self.assertEqual( s.param_doc(), [':param Int x:', ' foo', ':rtype Int:', ' bar'])