19 |
19 |
20 This module contains functions to initialize a new repository. |
20 This module contains functions to initialize a new repository. |
21 """ |
21 """ |
22 from __future__ import print_function |
22 from __future__ import print_function |
23 |
23 |
24 __docformat__ = "restructuredtext en" |
|
25 |
|
26 from pprint import pprint |
24 from pprint import pprint |
27 |
25 |
28 from logilab.common.decorators import cachedproperty |
26 from logilab.common.decorators import cachedproperty |
29 from logilab.common.testlib import SkipTest |
27 from logilab.common.testlib import SkipTest |
30 |
28 |
31 from cubicweb.devtools.testlib import RepoAccess |
29 from cubicweb.devtools.testlib import RepoAccess |
32 |
30 |
|
31 |
33 def tuplify(mylist): |
32 def tuplify(mylist): |
34 return [tuple(item) for item in mylist] |
33 return [tuple(item) for item in mylist] |
|
34 |
35 |
35 |
36 def snippet_key(a): |
36 def snippet_key(a): |
37 # a[0] may be a dict or a key/value tuple |
37 # a[0] may be a dict or a key/value tuple |
38 return (sorted(dict(a[0]).items()), [e.expression for e in a[1]]) |
38 return (sorted(dict(a[0]).items()), [e.expression for e in a[1]]) |
|
39 |
39 |
40 |
40 def check_plan(self, rql, expected, kwargs=None): |
41 def check_plan(self, rql, expected, kwargs=None): |
41 with self.session.new_cnx() as cnx: |
42 with self.session.new_cnx() as cnx: |
42 plan = self._prepare_plan(cnx, rql, kwargs) |
43 plan = self._prepare_plan(cnx, rql, kwargs) |
43 self.planner.build_plan(plan) |
44 self.planner.build_plan(plan) |
44 try: |
45 try: |
45 self.assertEqual(len(plan.steps), len(expected), |
46 self.assertEqual(len(plan.steps), len(expected), |
46 'expected %s steps, got %s' % (len(expected), len(plan.steps))) |
47 'expected %s steps, got %s' % (len(expected), len(plan.steps))) |
47 # step order is important |
48 # step order is important |
48 for i, step in enumerate(plan.steps): |
49 for i, step in enumerate(plan.steps): |
49 compare_steps(self, step.test_repr(), expected[i]) |
50 compare_steps(self, step.test_repr(), expected[i]) |
50 except AssertionError: |
51 except AssertionError: |
51 pprint([step.test_repr() for step in plan.steps]) |
52 pprint([step.test_repr() for step in plan.steps]) |
52 raise |
53 raise |
|
54 |
53 |
55 |
54 def compare_steps(self, step, expected): |
56 def compare_steps(self, step, expected): |
55 try: |
57 try: |
56 self.assertEqual(step[0], expected[0], 'expected step type %s, got %s' % (expected[0], step[0])) |
58 self.assertEqual(step[0], expected[0], 'expected step type %s, got %s' % (expected[0], step[0])) |
57 if len(step) > 2 and isinstance(step[1], list) and isinstance(expected[1], list): |
59 if len(step) > 2 and isinstance(step[1], list) and isinstance(expected[1], list): |