def testIsNot(self): def func(x): pass p,q,r = object(),object(),object() when(func,"x is not p")(value('~p')) when(func,"x is not p and x is not q and x is not r")(value('nada')) self.assertEqual(func(23),'nada') self.assertEqual(func(q),'~p')
def testTypeVsIsTypePrecedence(self): def func(x): pass when(func, (int, ))(value(1)) when(func, (istype(int), ))(value(2)) self.assertEqual(func(42), 2)
def testIsNot(self): def func(x): pass p, q, r = object(), object(), object() when(func, "x is not p")(value('~p')) when(func, "x is not p and x is not q and x is not r")(value('nada')) self.assertEqual(func(23), 'nada') self.assertEqual(func(q), '~p')
def testFlatPriorities(self): from peak.rules import value, AmbiguousMethods from peak.rules.predicates import priority f = lambda n, m: 0 f1, f2, f3 = value(1), value(2), value(3) when(f, "n==5 and priority(1)")(f1) when(f, "m==5 and priority(1)")(f2) when(f, "n==5 and m==5 and priority(1)")(f3) self.assertEqual(f(5, 5), 3)
def testFlatPriorities(self): from peak.rules import value, AmbiguousMethods from peak.rules.predicates import priority f = lambda n, m: 0 f1, f2, f3 = value(1), value(2), value(3) when(f, "n==5 and priority(1)")(f1) when(f, "m==5 and priority(1)")(f2) when(f, "n==5 and m==5 and priority(1)")(f3) self.assertEqual(f(5,5), 3)
def testNamedGFExtension(self): p, q, r = object(), object(), object() when("%s:%s.named_func" % (__name__, self.__class__.__name__), "x is not p")(value('~p')) self.assertEqual(self.named_func(q), '~p')
def testNamedGFExtension(self): p,q,r = object(),object(),object() when("%s:%s.named_func" % (__name__, self.__class__.__name__), "x is not p")(value('~p')) self.assertEqual(self.named_func(q),'~p')
def testTypeVsIsTypePrecedence(self): def func(x): pass when(func, (int, ))(value(1)) when(func, (istype(int),))(value(2)) self.assertEqual(func(42), 2)