def testUnionMixed(self): t = Union([List([R('a'), R('b')]), T(M(), M(), M())]) t = simplify(t) self.assertIsInstance(t, Union) self.assertEqual(t.list[0], T(M(), M(), M())) self.assertIsInstance(t.list[1], List) self.assertEqual(set(t.list[1].list), {R('a'), R('b')})
def testIntersectionMixed(self): t = Intersection([List([R('a'), R('b')]), List([R('c'), R('a')]), T(M(), M(), M())]) t = simplify(t) self.assertIsInstance(t, Intersection) self.assertEqual(t.list[0], T(M(), M(), M())) self.assertEqual(t.list[1], R('a'))
def predicate(node): if node == T(M(), M(), M()): return R('foo') elif node == R('foo'): return R('bar') elif node == M(): return node elif node == L([]): return node else: assert False, node
def testWorking(self): t = T(M(), M(), M()) q = { 'id': '1', 'language': 'en', 'tree': t.as_dict(), 'measures': {}, 'trace': [] } self.assertResponse( q, [Response('en', R('bar'), {}, [TraceItem('test', R('bar'), {})])])
def testIntersectionResourceLists(self): t = Intersection([List([R('a'), R('b')]), List([R('c'), R('a')])]) t = simplify(t) self.assertEqual(t, R('a')) t = Intersection([List([R('a'), R('b'), R('c')]), List([R('c'), R('a')])]) t = simplify(t) self.assertIn(t, (List([R('a'), R('c')]), List([R('c'), R('a')])))
def testIntersectionTrivial(self): self.assertEqual(simplify(Intersection([])), Intersection([])) self.assertEqual(simplify(Intersection([R('a')])), R('a'))
def testUnionResourceLists(self): t = Union([List([R('a'), R('b')]), List([R('c')])]) t = simplify(t) self.assertIsInstance(t, List) self.assertEqual(set(t.list), {R('a'), R('b'), R('c')})
def testUnionTrivial(self): self.assertEqual(simplify(Union([])), List([])) self.assertEqual(simplify(Union([List([R('a')])])), R('a'))
def testList(self): self.assertEqual(simplify(List([R('a')])), R('a'))