def test_arguments(self): def foo(a=int, b=bool, c=int): return str r = RemoteMethodSchema(method=foo) getpos = r.getPositionalArgConstraint getkw = r.getKeywordArgConstraint self.failUnless(isinstance(getpos(0)[1], schema.IntegerConstraint)) self.failUnless(isinstance(getpos(1)[1], schema.BooleanConstraint)) self.failUnless(isinstance(getpos(2)[1], schema.IntegerConstraint)) self.failUnless(isinstance(getkw("a")[1], schema.IntegerConstraint)) self.failUnless(isinstance(getkw("b")[1], schema.BooleanConstraint)) self.failUnless(isinstance(getkw("c")[1], schema.IntegerConstraint)) self.failUnless(isinstance(r.getResponseConstraint(), schema.ByteStringConstraint)) self.failUnless(isinstance(getkw("c", 1, [])[1], schema.IntegerConstraint)) self.failUnlessRaises(schema.Violation, getkw, "a", 1, []) self.failUnlessRaises(schema.Violation, getkw, "b", 1, ["b"]) self.failUnlessRaises(schema.Violation, getkw, "a", 2, []) self.failUnless(isinstance(getkw("c", 2, [])[1], schema.IntegerConstraint)) self.failUnless(isinstance(getkw("c", 0, ["a", "b"])[1], schema.IntegerConstraint)) try: r.checkAllArgs((1,True,2), {}, False) r.checkAllArgs((), {"a":1, "b":False, "c":2}, False) r.checkAllArgs((1,), {"b":False, "c":2}, False) r.checkAllArgs((1,True), {"c":3}, False) r.checkResults("good", False) except schema.Violation: self.fail("that shouldn't have raised a Violation") self.failUnlessRaises(schema.Violation, # 2 is not bool r.checkAllArgs, (1,2,3), {}, False) self.failUnlessRaises(schema.Violation, # too many r.checkAllArgs, (1,True,3,4), {}, False) self.failUnlessRaises(schema.Violation, # double "a" r.checkAllArgs, (1,), {"a":1, "b":True, "c": 3}, False) self.failUnlessRaises(schema.Violation, # missing required "b" r.checkAllArgs, (1,), {"c": 3}, False) self.failUnlessRaises(schema.Violation, # missing required "a" r.checkAllArgs, (), {"b":True, "c": 3}, False) self.failUnlessRaises(schema.Violation, r.checkResults, 12, False)
def test_arguments(self): def foo(a=int, b=bool, c=int): return bytes r = RemoteMethodSchema(method=foo) getpos = r.getPositionalArgConstraint getkw = r.getKeywordArgConstraint self.assertTrue(isinstance(getpos(0)[1], schema.IntegerConstraint)) self.assertTrue(isinstance(getpos(1)[1], schema.BooleanConstraint)) self.assertTrue(isinstance(getpos(2)[1], schema.IntegerConstraint)) self.assertTrue(isinstance(getkw("a")[1], schema.IntegerConstraint)) self.assertTrue(isinstance(getkw("b")[1], schema.BooleanConstraint)) self.assertTrue(isinstance(getkw("c")[1], schema.IntegerConstraint)) self.assertTrue( isinstance(r.getResponseConstraint(), schema.ByteStringConstraint)) self.assertTrue( isinstance(getkw("c", 1, [])[1], schema.IntegerConstraint)) self.assertRaises(schema.Violation, getkw, "a", 1, []) self.assertRaises(schema.Violation, getkw, "b", 1, ["b"]) self.assertRaises(schema.Violation, getkw, "a", 2, []) self.assertTrue( isinstance(getkw("c", 2, [])[1], schema.IntegerConstraint)) self.assertTrue( isinstance(getkw("c", 0, ["a", "b"])[1], schema.IntegerConstraint)) try: r.checkAllArgs((1, True, 2), {}, False) r.checkAllArgs((), {"a": 1, "b": False, "c": 2}, False) r.checkAllArgs((1, ), {"b": False, "c": 2}, False) r.checkAllArgs((1, True), {"c": 3}, False) r.checkResults(b"good", False) except schema.Violation: self.fail("that shouldn't have raised a Violation") self.assertRaises( schema.Violation, # 2 is not bool r.checkAllArgs, (1, 2, 3), {}, False) self.assertRaises( schema.Violation, # too many r.checkAllArgs, (1, True, 3, 4), {}, False) self.assertRaises( schema.Violation, # double "a" r.checkAllArgs, (1, ), { "a": 1, "b": True, "c": 3 }, False) self.assertRaises( schema.Violation, # missing required "b" r.checkAllArgs, (1, ), {"c": 3}, False) self.assertRaises( schema.Violation, # missing required "a" r.checkAllArgs, (), { "b": True, "c": 3 }, False) self.assertRaises(schema.Violation, r.checkResults, 12, False)