39 |
39 |
40 def test_plan(self, rql, expected, kwargs=None): |
40 def test_plan(self, rql, expected, kwargs=None): |
41 plan = self._prepare_plan(rql, kwargs) |
41 plan = self._prepare_plan(rql, kwargs) |
42 self.planner.build_plan(plan) |
42 self.planner.build_plan(plan) |
43 try: |
43 try: |
44 self.assertEquals(len(plan.steps), len(expected), |
44 self.assertEqual(len(plan.steps), len(expected), |
45 'expected %s steps, got %s' % (len(expected), len(plan.steps))) |
45 'expected %s steps, got %s' % (len(expected), len(plan.steps))) |
46 # step order is important |
46 # step order is important |
47 for i, step in enumerate(plan.steps): |
47 for i, step in enumerate(plan.steps): |
48 compare_steps(self, step.test_repr(), expected[i]) |
48 compare_steps(self, step.test_repr(), expected[i]) |
49 except AssertionError: |
49 except AssertionError: |
50 pprint([step.test_repr() for step in plan.steps]) |
50 pprint([step.test_repr() for step in plan.steps]) |
51 raise |
51 raise |
52 |
52 |
53 def compare_steps(self, step, expected): |
53 def compare_steps(self, step, expected): |
54 try: |
54 try: |
55 self.assertEquals(step[0], expected[0], 'expected step type %s, got %s' % (expected[0], step[0])) |
55 self.assertEqual(step[0], expected[0], 'expected step type %s, got %s' % (expected[0], step[0])) |
56 if len(step) > 2 and isinstance(step[1], list) and isinstance(expected[1], list): |
56 if len(step) > 2 and isinstance(step[1], list) and isinstance(expected[1], list): |
57 queries, equeries = step[1], expected[1] |
57 queries, equeries = step[1], expected[1] |
58 self.assertEquals(len(queries), len(equeries), |
58 self.assertEqual(len(queries), len(equeries), |
59 'expected %s queries, got %s' % (len(equeries), len(queries))) |
59 'expected %s queries, got %s' % (len(equeries), len(queries))) |
60 for i, (rql, sol) in enumerate(queries): |
60 for i, (rql, sol) in enumerate(queries): |
61 self.assertEquals(rql, equeries[i][0]) |
61 self.assertEqual(rql, equeries[i][0]) |
62 self.assertEquals(sorted(sol), sorted(equeries[i][1])) |
62 self.assertEqual(sorted(sol), sorted(equeries[i][1])) |
63 idx = 2 |
63 idx = 2 |
64 else: |
64 else: |
65 idx = 1 |
65 idx = 1 |
66 self.assertEquals(step[idx:-1], expected[idx:-1], |
66 self.assertEqual(step[idx:-1], expected[idx:-1], |
67 'expected step characteristic \n%s\n, got\n%s' % (expected[1:-1], step[1:-1])) |
67 'expected step characteristic \n%s\n, got\n%s' % (expected[1:-1], step[1:-1])) |
68 self.assertEquals(len(step[-1]), len(expected[-1]), |
68 self.assertEqual(len(step[-1]), len(expected[-1]), |
69 'got %s child steps, expected %s' % (len(step[-1]), len(expected[-1]))) |
69 'got %s child steps, expected %s' % (len(step[-1]), len(expected[-1]))) |
70 except AssertionError: |
70 except AssertionError: |
71 print 'error on step ', |
71 print 'error on step ', |
72 pprint(step[:-1]) |
72 pprint(step[:-1]) |
73 raise |
73 raise |