author | Rémi Cardona <remi.cardona@logilab.fr> |
Wed, 28 Jan 2015 11:51:16 +0100 | |
changeset 10164 | 2094262d6553 |
parent 9850 | 5ef9dd383ae2 |
child 10365 | 21461f80f348 |
permissions | -rw-r--r-- |
9833
1485aab7ece6
[tests/querier] use the new connection api (part 3/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9831
diff
changeset
|
1 |
# copyright 2003-2014 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
"""some utilities to ease repository testing |
19 |
||
20 |
This module contains functions to initialize a new repository. |
|
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
21 |
""" |
0 | 22 |
|
23 |
__docformat__ = "restructuredtext en" |
|
24 |
||
25 |
from pprint import pprint |
|
26 |
||
6818
5fa425574548
[server test] can't use skipTest method as a class method, raise appropriate exception instead
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6804
diff
changeset
|
27 |
from logilab.common.testlib import SkipTest |
2074
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
28 |
|
9835
5ad968dd9d51
[devtools/repotest] simplify a very small helper
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9834
diff
changeset
|
29 |
def tuplify(mylist): |
5ad968dd9d51
[devtools/repotest] simplify a very small helper
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9834
diff
changeset
|
30 |
return [tuple(item) for item in mylist] |
0 | 31 |
|
32 |
def snippet_cmp(a, b): |
|
33 |
a = (a[0], [e.expression for e in a[1]]) |
|
34 |
b = (b[0], [e.expression for e in b[1]]) |
|
35 |
return cmp(a, b) |
|
36 |
||
37 |
def test_plan(self, rql, expected, kwargs=None): |
|
9834
807f7a6f33f4
[tests/repotest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9833
diff
changeset
|
38 |
with self.session.new_cnx() as cnx: |
807f7a6f33f4
[tests/repotest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9833
diff
changeset
|
39 |
plan = self._prepare_plan(cnx, rql, kwargs) |
807f7a6f33f4
[tests/repotest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9833
diff
changeset
|
40 |
self.planner.build_plan(plan) |
807f7a6f33f4
[tests/repotest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9833
diff
changeset
|
41 |
try: |
807f7a6f33f4
[tests/repotest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9833
diff
changeset
|
42 |
self.assertEqual(len(plan.steps), len(expected), |
807f7a6f33f4
[tests/repotest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9833
diff
changeset
|
43 |
'expected %s steps, got %s' % (len(expected), len(plan.steps))) |
807f7a6f33f4
[tests/repotest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9833
diff
changeset
|
44 |
# step order is important |
807f7a6f33f4
[tests/repotest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9833
diff
changeset
|
45 |
for i, step in enumerate(plan.steps): |
807f7a6f33f4
[tests/repotest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9833
diff
changeset
|
46 |
compare_steps(self, step.test_repr(), expected[i]) |
807f7a6f33f4
[tests/repotest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9833
diff
changeset
|
47 |
except AssertionError: |
807f7a6f33f4
[tests/repotest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9833
diff
changeset
|
48 |
pprint([step.test_repr() for step in plan.steps]) |
807f7a6f33f4
[tests/repotest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9833
diff
changeset
|
49 |
raise |
0 | 50 |
|
51 |
def compare_steps(self, step, expected): |
|
52 |
try: |
|
6369
a151453dc564
[test] more update to unittest2 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
53 |
self.assertEqual(step[0], expected[0], 'expected step type %s, got %s' % (expected[0], step[0])) |
0 | 54 |
if len(step) > 2 and isinstance(step[1], list) and isinstance(expected[1], list): |
55 |
queries, equeries = step[1], expected[1] |
|
6369
a151453dc564
[test] more update to unittest2 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
56 |
self.assertEqual(len(queries), len(equeries), |
0 | 57 |
'expected %s queries, got %s' % (len(equeries), len(queries))) |
58 |
for i, (rql, sol) in enumerate(queries): |
|
6369
a151453dc564
[test] more update to unittest2 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
59 |
self.assertEqual(rql, equeries[i][0]) |
a151453dc564
[test] more update to unittest2 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
60 |
self.assertEqual(sorted(sol), sorted(equeries[i][1])) |
0 | 61 |
idx = 2 |
62 |
else: |
|
63 |
idx = 1 |
|
6369
a151453dc564
[test] more update to unittest2 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
64 |
self.assertEqual(step[idx:-1], expected[idx:-1], |
0 | 65 |
'expected step characteristic \n%s\n, got\n%s' % (expected[1:-1], step[1:-1])) |
6369
a151453dc564
[test] more update to unittest2 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
66 |
self.assertEqual(len(step[-1]), len(expected[-1]), |
0 | 67 |
'got %s child steps, expected %s' % (len(step[-1]), len(expected[-1]))) |
68 |
except AssertionError: |
|
69 |
print 'error on step ', |
|
70 |
pprint(step[:-1]) |
|
71 |
raise |
|
72 |
children = step[-1] |
|
73 |
if step[0] in ('UnionFetchStep', 'UnionStep'): |
|
74 |
# sort children |
|
75 |
children = sorted(children) |
|
76 |
expectedchildren = sorted(expected[-1]) |
|
77 |
else: |
|
78 |
expectedchildren = expected[-1] |
|
79 |
for i, substep in enumerate(children): |
|
80 |
compare_steps(self, substep, expectedchildren[i]) |
|
81 |
||
82 |
||
83 |
class DumbOrderedDict(list): |
|
84 |
def __iter__(self): |
|
85 |
return self.iterkeys() |
|
86 |
def __contains__(self, key): |
|
87 |
return key in self.iterkeys() |
|
88 |
def __getitem__(self, key): |
|
1236
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
89 |
for key_, value in list.__iter__(self): |
0 | 90 |
if key == key_: |
91 |
return value |
|
92 |
raise KeyError(key) |
|
93 |
def iterkeys(self): |
|
94 |
return (x for x, y in list.__iter__(self)) |
|
95 |
def iteritems(self): |
|
96 |
return (x for x in list.__iter__(self)) |
|
1236
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
97 |
def items(self): |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
98 |
return [x for x in list.__iter__(self)] |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
99 |
|
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
100 |
class DumbOrderedDict2(object): |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
101 |
def __init__(self, origdict, sortkey): |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
102 |
self.origdict = origdict |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
103 |
self.sortkey = sortkey |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
104 |
def __getattr__(self, attr): |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
105 |
return getattr(self.origdict, attr) |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
106 |
def __iter__(self): |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
107 |
return iter(sorted(self.origdict, key=self.sortkey)) |
0 | 108 |
|
4766
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
109 |
def schema_eids_idx(schema): |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
110 |
"""return a dictionary mapping schema types to their eids so we can reread |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
111 |
it from the fs instead of the db (too costly) between tests |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
112 |
""" |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
113 |
schema_eids = {} |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
114 |
for x in schema.entities(): |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
115 |
schema_eids[x] = x.eid |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
116 |
for x in schema.relations(): |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
117 |
schema_eids[x] = x.eid |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
118 |
for rdef in x.rdefs.itervalues(): |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
119 |
schema_eids[(rdef.subject, rdef.rtype, rdef.object)] = rdef.eid |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
120 |
return schema_eids |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
121 |
|
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
122 |
def restore_schema_eids_idx(schema, schema_eids): |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
123 |
"""rebuild schema eid index""" |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
124 |
for x in schema.entities(): |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
125 |
x.eid = schema_eids[x] |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
126 |
schema._eid_index[x.eid] = x |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
127 |
for x in schema.relations(): |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
128 |
x.eid = schema_eids[x] |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
129 |
schema._eid_index[x.eid] = x |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
130 |
for rdef in x.rdefs.itervalues(): |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
131 |
rdef.eid = schema_eids[(rdef.subject, rdef.rtype, rdef.object)] |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
132 |
schema._eid_index[rdef.eid] = rdef |
162b2b127b15
[test] get a chance to get proper garbage collection when running pytest on whole cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4674
diff
changeset
|
133 |
|
0 | 134 |
|
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
135 |
from logilab.common.testlib import TestCase, mock_object |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
136 |
from logilab.database import get_db_helper |
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
137 |
|
0 | 138 |
from rql import RQLHelper |
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
139 |
|
9460
a2a0bc984863
[config] cleanup/refactor server sources file values handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9456
diff
changeset
|
140 |
from cubicweb.devtools.fake import FakeRepo, FakeConfig, FakeSession |
6758
28b11ecf319b
[ms] #1382452: incorrect results with multi-sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6671
diff
changeset
|
141 |
from cubicweb.server import set_debug, debugged |
0 | 142 |
from cubicweb.server.querier import QuerierHelper |
143 |
from cubicweb.server.session import Session |
|
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
144 |
from cubicweb.server.sources.rql2sql import SQLGenerator, remove_unused_solutions |
0 | 145 |
|
146 |
class RQLGeneratorTC(TestCase): |
|
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7850
diff
changeset
|
147 |
schema = backend = None # set this in concrete class |
6804
4262d0d6abcb
unittest2 fix: can't skip test in setUp, but it's fine in setUpClass
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6794
diff
changeset
|
148 |
|
4262d0d6abcb
unittest2 fix: can't skip test in setUp, but it's fine in setUpClass
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6794
diff
changeset
|
149 |
@classmethod |
4262d0d6abcb
unittest2 fix: can't skip test in setUp, but it's fine in setUpClass
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6794
diff
changeset
|
150 |
def setUpClass(cls): |
4262d0d6abcb
unittest2 fix: can't skip test in setUp, but it's fine in setUpClass
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6794
diff
changeset
|
151 |
if cls.backend is not None: |
4262d0d6abcb
unittest2 fix: can't skip test in setUp, but it's fine in setUpClass
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6794
diff
changeset
|
152 |
try: |
4262d0d6abcb
unittest2 fix: can't skip test in setUp, but it's fine in setUpClass
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6794
diff
changeset
|
153 |
cls.dbhelper = get_db_helper(cls.backend) |
8695
358d8bed9626
[toward-py3k] rewrite to "except AnException as exc:" (part of #2711624)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8544
diff
changeset
|
154 |
except ImportError as ex: |
6818
5fa425574548
[server test] can't use skipTest method as a class method, raise appropriate exception instead
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6804
diff
changeset
|
155 |
raise SkipTest(str(ex)) |
6804
4262d0d6abcb
unittest2 fix: can't skip test in setUp, but it's fine in setUpClass
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6794
diff
changeset
|
156 |
|
0 | 157 |
def setUp(self): |
9460
a2a0bc984863
[config] cleanup/refactor server sources file values handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9456
diff
changeset
|
158 |
self.repo = FakeRepo(self.schema, config=FakeConfig(apphome=self.datadir)) |
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
159 |
self.repo.system_source = mock_object(dbdriver=self.backend) |
9850
5ef9dd383ae2
[tests/rqlannotation,querier] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9835
diff
changeset
|
160 |
self.rqlhelper = RQLHelper(self.schema, |
5ef9dd383ae2
[tests/rqlannotation,querier] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9835
diff
changeset
|
161 |
special_relations={'eid': 'uid', |
5ef9dd383ae2
[tests/rqlannotation,querier] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9835
diff
changeset
|
162 |
'has_text': 'fti'}, |
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
163 |
backend=self.backend) |
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2200
diff
changeset
|
164 |
self.qhelper = QuerierHelper(self.repo, self.schema) |
0 | 165 |
ExecutionPlan._check_permissions = _dummy_check_permissions |
166 |
rqlannotation._select_principal = _select_principal |
|
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
167 |
if self.backend is not None: |
6804
4262d0d6abcb
unittest2 fix: can't skip test in setUp, but it's fine in setUpClass
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6794
diff
changeset
|
168 |
self.o = SQLGenerator(self.schema, self.dbhelper) |
0 | 169 |
|
170 |
def tearDown(self): |
|
171 |
ExecutionPlan._check_permissions = _orig_check_permissions |
|
172 |
rqlannotation._select_principal = _orig_select_principal |
|
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2074
diff
changeset
|
173 |
|
2069
7c0a1b90b1c6
set_debug method on rql2sql test as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
174 |
def set_debug(self, debug): |
7c0a1b90b1c6
set_debug method on rql2sql test as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
175 |
set_debug(debug) |
6758
28b11ecf319b
[ms] #1382452: incorrect results with multi-sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6671
diff
changeset
|
176 |
def debugged(self, debug): |
28b11ecf319b
[ms] #1382452: incorrect results with multi-sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6671
diff
changeset
|
177 |
return debugged(debug) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1789
diff
changeset
|
178 |
|
0 | 179 |
def _prepare(self, rql): |
180 |
#print '******************** prepare', rql |
|
181 |
union = self.rqlhelper.parse(rql) |
|
182 |
#print '********* parsed', union.as_string() |
|
183 |
self.rqlhelper.compute_solutions(union) |
|
184 |
#print '********* solutions', solutions |
|
185 |
self.rqlhelper.simplify(union) |
|
186 |
#print '********* simplified', union.as_string() |
|
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2200
diff
changeset
|
187 |
plan = self.qhelper.plan_factory(union, {}, FakeSession(self.repo)) |
0 | 188 |
plan.preprocess(union) |
189 |
for select in union.children: |
|
190 |
select.solutions.sort() |
|
191 |
#print '********* ppsolutions', solutions |
|
192 |
return union |
|
193 |
||
194 |
||
195 |
class BaseQuerierTC(TestCase): |
|
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7850
diff
changeset
|
196 |
repo = None # set this in concrete class |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1789
diff
changeset
|
197 |
|
0 | 198 |
def setUp(self): |
199 |
self.o = self.repo.querier |
|
200 |
self.session = self.repo._sessions.values()[0] |
|
201 |
self.ueid = self.session.user.eid |
|
202 |
assert self.ueid != -1 |
|
203 |
self.repo._type_source_cache = {} # clear cache |
|
204 |
self.maxeid = self.get_max_eid() |
|
205 |
do_monkey_patch() |
|
4773
6ab9ca63531f
[testlib] properly close dumb sessions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
206 |
self._dumb_sessions = [] |
0 | 207 |
|
208 |
def get_max_eid(self): |
|
9833
1485aab7ece6
[tests/querier] use the new connection api (part 3/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9831
diff
changeset
|
209 |
with self.session.new_cnx() as cnx: |
1485aab7ece6
[tests/querier] use the new connection api (part 3/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9831
diff
changeset
|
210 |
return cnx.execute('Any MAX(X)')[0][0] |
1485aab7ece6
[tests/querier] use the new connection api (part 3/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9831
diff
changeset
|
211 |
|
0 | 212 |
def cleanup(self): |
9833
1485aab7ece6
[tests/querier] use the new connection api (part 3/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9831
diff
changeset
|
213 |
with self.session.new_cnx() as cnx: |
1485aab7ece6
[tests/querier] use the new connection api (part 3/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9831
diff
changeset
|
214 |
cnx.execute('DELETE Any X WHERE X eid > %s' % self.maxeid) |
1485aab7ece6
[tests/querier] use the new connection api (part 3/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9831
diff
changeset
|
215 |
cnx.commit() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1789
diff
changeset
|
216 |
|
0 | 217 |
def tearDown(self): |
218 |
undo_monkey_patch() |
|
219 |
self.cleanup() |
|
220 |
assert self.session.user.eid != -1 |
|
221 |
||
222 |
def set_debug(self, debug): |
|
223 |
set_debug(debug) |
|
6758
28b11ecf319b
[ms] #1382452: incorrect results with multi-sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6671
diff
changeset
|
224 |
def debugged(self, debug): |
28b11ecf319b
[ms] #1382452: incorrect results with multi-sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6671
diff
changeset
|
225 |
return debugged(debug) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1789
diff
changeset
|
226 |
|
0 | 227 |
def _rqlhelper(self): |
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2200
diff
changeset
|
228 |
rqlhelper = self.repo.vreg.rqlhelper |
0 | 229 |
# reset uid_func so it don't try to get type from eids |
230 |
rqlhelper._analyser.uid_func = None |
|
231 |
rqlhelper._analyser.uid_func_mapping = {} |
|
232 |
return rqlhelper |
|
233 |
||
9850
5ef9dd383ae2
[tests/rqlannotation,querier] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9835
diff
changeset
|
234 |
def _prepare_plan(self, cnx, rql, kwargs=None, simplify=True): |
0 | 235 |
rqlhelper = self._rqlhelper() |
236 |
rqlst = rqlhelper.parse(rql) |
|
237 |
rqlhelper.compute_solutions(rqlst, kwargs=kwargs) |
|
4184
7002e91d304a
should not simplify previous to preprocess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
238 |
if simplify: |
7002e91d304a
should not simplify previous to preprocess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
239 |
rqlhelper.simplify(rqlst) |
0 | 240 |
for select in rqlst.children: |
241 |
select.solutions.sort() |
|
9850
5ef9dd383ae2
[tests/rqlannotation,querier] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9835
diff
changeset
|
242 |
return self.o.plan_factory(rqlst, kwargs, cnx) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1789
diff
changeset
|
243 |
|
9850
5ef9dd383ae2
[tests/rqlannotation,querier] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9835
diff
changeset
|
244 |
def _prepare(self, cnx, rql, kwargs=None): |
5ef9dd383ae2
[tests/rqlannotation,querier] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9835
diff
changeset
|
245 |
plan = self._prepare_plan(cnx, rql, kwargs, simplify=False) |
0 | 246 |
plan.preprocess(plan.rqlst) |
247 |
rqlst = plan.rqlst.children[0] |
|
248 |
rqlst.solutions = remove_unused_solutions(rqlst, rqlst.solutions, {}, self.repo.schema)[0] |
|
249 |
return rqlst |
|
250 |
||
4674
3d509dbb473a
[test api] rename _user_session to user_groups_session, fix its arguments and return only the session, not (user, session) to make things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
251 |
def user_groups_session(self, *groups): |
3d509dbb473a
[test api] rename _user_session to user_groups_session, fix its arguments and return only the session, not (user, session) to make things clearer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
252 |
"""lightweight session using the current user with hi-jacked groups""" |
0 | 253 |
# use self.session.user.eid to get correct owned_by relation, unless explicit eid |
9833
1485aab7ece6
[tests/querier] use the new connection api (part 3/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9831
diff
changeset
|
254 |
with self.session.new_cnx() as cnx: |
1485aab7ece6
[tests/querier] use the new connection api (part 3/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9831
diff
changeset
|
255 |
u = self.repo._build_user(cnx, self.session.user.eid) |
1485aab7ece6
[tests/querier] use the new connection api (part 3/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9831
diff
changeset
|
256 |
u._groups = set(groups) |
1485aab7ece6
[tests/querier] use the new connection api (part 3/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9831
diff
changeset
|
257 |
s = Session(u, self.repo) |
1485aab7ece6
[tests/querier] use the new connection api (part 3/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9831
diff
changeset
|
258 |
return s |
0 | 259 |
|
9831
db4aeba5d336
[test/querier] use the new connection api (part 1/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9468
diff
changeset
|
260 |
def qexecute(self, rql, args=None, build_descr=True): |
db4aeba5d336
[test/querier] use the new connection api (part 1/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9468
diff
changeset
|
261 |
with self.session.new_cnx() as cnx: |
db4aeba5d336
[test/querier] use the new connection api (part 1/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9468
diff
changeset
|
262 |
with cnx.ensure_cnx_set: |
db4aeba5d336
[test/querier] use the new connection api (part 1/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9468
diff
changeset
|
263 |
try: |
db4aeba5d336
[test/querier] use the new connection api (part 1/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9468
diff
changeset
|
264 |
return self.o.execute(cnx, rql, args, build_descr) |
db4aeba5d336
[test/querier] use the new connection api (part 1/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9468
diff
changeset
|
265 |
finally: |
db4aeba5d336
[test/querier] use the new connection api (part 1/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9468
diff
changeset
|
266 |
if rql.startswith(('INSERT', 'DELETE', 'SET')): |
db4aeba5d336
[test/querier] use the new connection api (part 1/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9468
diff
changeset
|
267 |
cnx.commit() |
db4aeba5d336
[test/querier] use the new connection api (part 1/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9468
diff
changeset
|
268 |
|
0 | 269 |
|
270 |
class BasePlannerTC(BaseQuerierTC): |
|
6957
ffda12be2e9f
[repository] #1460066: backport datafeed cube as cubicweb source
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6818
diff
changeset
|
271 |
|
2074
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
272 |
def setup(self): |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
273 |
# XXX source_defs |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
274 |
self.o = self.repo.querier |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
275 |
self.session = self.repo._sessions.values()[0] |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
276 |
self.schema = self.o.schema |
9456
a79e88aad555
[multi-sources-removal]Â Kill repo.sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9452
diff
changeset
|
277 |
self.system = self.repo.system_source |
2074
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
278 |
do_monkey_patch() |
5768
1e73a466aa69
[fti] support for fti ranking: has_text query results sorted by relevance, and provides a way to control weight per entity / entity's attribute
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
279 |
self.repo.vreg.rqlhelper.backend = 'postgres' # so FTIRANK is considered |
2074
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
280 |
|
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
281 |
def tearDown(self): |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
282 |
undo_monkey_patch() |
0 | 283 |
|
9834
807f7a6f33f4
[tests/repotest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9833
diff
changeset
|
284 |
def _prepare_plan(self, cnx, rql, kwargs=None): |
0 | 285 |
rqlst = self.o.parse(rql, annotate=True) |
9834
807f7a6f33f4
[tests/repotest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9833
diff
changeset
|
286 |
self.o.solutions(cnx, rqlst, kwargs) |
0 | 287 |
if rqlst.TYPE == 'select': |
3240
8604a15995d1
refactor so that rql rewriter may be used outside the server. Enhance it to be usable for RRQLExpression as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2200
diff
changeset
|
288 |
self.repo.vreg.rqlhelper.annotate(rqlst) |
0 | 289 |
for select in rqlst.children: |
290 |
select.solutions.sort() |
|
291 |
else: |
|
292 |
rqlst.solutions.sort() |
|
9834
807f7a6f33f4
[tests/repotest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9833
diff
changeset
|
293 |
return self.o.plan_factory(rqlst, kwargs, cnx) |
0 | 294 |
|
295 |
||
296 |
# monkey patch some methods to get predicatable results ####################### |
|
297 |
||
7850
d14b77c42b06
[test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
298 |
from cubicweb import rqlrewrite |
d14b77c42b06
[test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
299 |
_orig_iter_relations = rqlrewrite.iter_relations |
d14b77c42b06
[test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
300 |
_orig_insert_snippets = rqlrewrite.RQLRewriter.insert_snippets |
d14b77c42b06
[test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
301 |
_orig_build_variantes = rqlrewrite.RQLRewriter.build_variantes |
0 | 302 |
|
303 |
def _insert_snippets(self, snippets, varexistsmap=None): |
|
304 |
_orig_insert_snippets(self, sorted(snippets, snippet_cmp), varexistsmap) |
|
305 |
||
306 |
def _build_variantes(self, newsolutions): |
|
307 |
variantes = _orig_build_variantes(self, newsolutions) |
|
308 |
sortedvariantes = [] |
|
309 |
for variante in variantes: |
|
1132 | 310 |
orderedkeys = sorted((k[1], k[2], v) for k, v in variante.iteritems()) |
0 | 311 |
variante = DumbOrderedDict(sorted(variante.iteritems(), |
1132 | 312 |
lambda a, b: cmp((a[0][1],a[0][2],a[1]), |
313 |
(b[0][1],b[0][2],b[1])))) |
|
0 | 314 |
sortedvariantes.append( (orderedkeys, variante) ) |
315 |
return [v for ok, v in sorted(sortedvariantes)] |
|
316 |
||
317 |
from cubicweb.server.querier import ExecutionPlan |
|
318 |
_orig_check_permissions = ExecutionPlan._check_permissions |
|
319 |
||
320 |
def _check_permissions(*args, **kwargs): |
|
321 |
res, restricted = _orig_check_permissions(*args, **kwargs) |
|
1132 | 322 |
res = DumbOrderedDict(sorted(res.iteritems(), lambda a, b: cmp(a[1], b[1]))) |
0 | 323 |
return res, restricted |
324 |
||
325 |
def _dummy_check_permissions(self, rqlst): |
|
326 |
return {(): rqlst.solutions}, set() |
|
327 |
||
328 |
from cubicweb.server import rqlannotation |
|
329 |
_orig_select_principal = rqlannotation._select_principal |
|
330 |
||
331 |
def _select_principal(scope, relations): |
|
7357
5ad3154a8810
[rql2sql] fix bug avoiding outer join relation to be used as a variable principal. Closes #1659395
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6957
diff
changeset
|
332 |
def sort_key(something): |
5ad3154a8810
[rql2sql] fix bug avoiding outer join relation to be used as a variable principal. Closes #1659395
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6957
diff
changeset
|
333 |
try: |
5ad3154a8810
[rql2sql] fix bug avoiding outer join relation to be used as a variable principal. Closes #1659395
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6957
diff
changeset
|
334 |
return something.r_type |
5ad3154a8810
[rql2sql] fix bug avoiding outer join relation to be used as a variable principal. Closes #1659395
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6957
diff
changeset
|
335 |
except AttributeError: |
5ad3154a8810
[rql2sql] fix bug avoiding outer join relation to be used as a variable principal. Closes #1659395
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6957
diff
changeset
|
336 |
return (something[0].r_type, something[1]) |
599
9ef680acd92a
fix select principal so results are predictable during tests
Sylvain <syt@logilab.fr>
parents:
0
diff
changeset
|
337 |
return _orig_select_principal(scope, relations, |
7357
5ad3154a8810
[rql2sql] fix bug avoiding outer join relation to be used as a variable principal. Closes #1659395
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6957
diff
changeset
|
338 |
_sort=lambda rels: sorted(rels, key=sort_key)) |
0 | 339 |
|
340 |
||
7850
d14b77c42b06
[test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
341 |
def _ordered_iter_relations(stinfo): |
d14b77c42b06
[test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
342 |
return sorted(_orig_iter_relations(stinfo), key=lambda x:x.r_type) |
d14b77c42b06
[test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
343 |
|
0 | 344 |
def do_monkey_patch(): |
7850
d14b77c42b06
[test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
345 |
rqlrewrite.iter_relations = _ordered_iter_relations |
d14b77c42b06
[test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
346 |
rqlrewrite.RQLRewriter.insert_snippets = _insert_snippets |
d14b77c42b06
[test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
347 |
rqlrewrite.RQLRewriter.build_variantes = _build_variantes |
0 | 348 |
ExecutionPlan._check_permissions = _check_permissions |
349 |
ExecutionPlan.tablesinorder = None |
|
350 |
||
351 |
def undo_monkey_patch(): |
|
7850
d14b77c42b06
[test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
352 |
rqlrewrite.iter_relations = _orig_iter_relations |
d14b77c42b06
[test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
353 |
rqlrewrite.RQLRewriter.insert_snippets = _orig_insert_snippets |
d14b77c42b06
[test] sort to avoid random failure due to dict order
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7398
diff
changeset
|
354 |
rqlrewrite.RQLRewriter.build_variantes = _orig_build_variantes |
0 | 355 |
ExecutionPlan._check_permissions = _orig_check_permissions |