author | Rémi Cardona <remi.cardona@logilab.fr> |
Tue, 15 Sep 2015 15:08:04 +0200 | |
changeset 10673 | 9924fd69bcba |
parent 10663 | 54b8a1f249fb |
child 10711 | d7f009a3b960 |
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 |
""" |
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10365
diff
changeset
|
22 |
from __future__ import print_function |
0 | 23 |
|
24 |
__docformat__ = "restructuredtext en" |
|
25 |
||
26 |
from pprint import pprint |
|
27 |
||
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
|
28 |
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
|
29 |
|
9835
5ad968dd9d51
[devtools/repotest] simplify a very small helper
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9834
diff
changeset
|
30 |
def tuplify(mylist): |
5ad968dd9d51
[devtools/repotest] simplify a very small helper
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9834
diff
changeset
|
31 |
return [tuple(item) for item in mylist] |
0 | 32 |
|
33 |
def snippet_cmp(a, b): |
|
34 |
a = (a[0], [e.expression for e in a[1]]) |
|
35 |
b = (b[0], [e.expression for e in b[1]]) |
|
36 |
return cmp(a, b) |
|
37 |
||
38 |
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
|
39 |
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
|
40 |
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
|
41 |
self.planner.build_plan(plan) |
807f7a6f33f4
[tests/repotest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9833
diff
changeset
|
42 |
try: |
807f7a6f33f4
[tests/repotest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9833
diff
changeset
|
43 |
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
|
44 |
'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
|
45 |
# step order is important |
807f7a6f33f4
[tests/repotest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9833
diff
changeset
|
46 |
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
|
47 |
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
|
48 |
except AssertionError: |
807f7a6f33f4
[tests/repotest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9833
diff
changeset
|
49 |
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
|
50 |
raise |
0 | 51 |
|
52 |
def compare_steps(self, step, expected): |
|
53 |
try: |
|
6369
a151453dc564
[test] more update to unittest2 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
54 |
self.assertEqual(step[0], expected[0], 'expected step type %s, got %s' % (expected[0], step[0])) |
0 | 55 |
if len(step) > 2 and isinstance(step[1], list) and isinstance(expected[1], list): |
56 |
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
|
57 |
self.assertEqual(len(queries), len(equeries), |
0 | 58 |
'expected %s queries, got %s' % (len(equeries), len(queries))) |
59 |
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
|
60 |
self.assertEqual(rql, equeries[i][0]) |
a151453dc564
[test] more update to unittest2 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
61 |
self.assertEqual(sorted(sol), sorted(equeries[i][1])) |
0 | 62 |
idx = 2 |
63 |
else: |
|
64 |
idx = 1 |
|
6369
a151453dc564
[test] more update to unittest2 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
65 |
self.assertEqual(step[idx:-1], expected[idx:-1], |
0 | 66 |
'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
|
67 |
self.assertEqual(len(step[-1]), len(expected[-1]), |
0 | 68 |
'got %s child steps, expected %s' % (len(step[-1]), len(expected[-1]))) |
69 |
except AssertionError: |
|
10589
7c23b7de2b8d
[py3k] print function
Samuel Trégouët <samuel.tregouet@logilab.fr>
parents:
10365
diff
changeset
|
70 |
print('error on step ', end=' ') |
0 | 71 |
pprint(step[:-1]) |
72 |
raise |
|
73 |
children = step[-1] |
|
74 |
if step[0] in ('UnionFetchStep', 'UnionStep'): |
|
75 |
# sort children |
|
76 |
children = sorted(children) |
|
77 |
expectedchildren = sorted(expected[-1]) |
|
78 |
else: |
|
79 |
expectedchildren = expected[-1] |
|
80 |
for i, substep in enumerate(children): |
|
81 |
compare_steps(self, substep, expectedchildren[i]) |
|
82 |
||
83 |
||
84 |
class DumbOrderedDict(list): |
|
85 |
def __iter__(self): |
|
86 |
return self.iterkeys() |
|
87 |
def __contains__(self, key): |
|
88 |
return key in self.iterkeys() |
|
89 |
def __getitem__(self, key): |
|
1236
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
90 |
for key_, value in list.__iter__(self): |
0 | 91 |
if key == key_: |
92 |
return value |
|
93 |
raise KeyError(key) |
|
94 |
def iterkeys(self): |
|
95 |
return (x for x, y in list.__iter__(self)) |
|
96 |
def iteritems(self): |
|
97 |
return (x for x in list.__iter__(self)) |
|
1236
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
98 |
def items(self): |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
99 |
return [x for x in list.__iter__(self)] |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
100 |
|
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
101 |
class DumbOrderedDict2(object): |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
102 |
def __init__(self, origdict, sortkey): |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
103 |
self.origdict = origdict |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
104 |
self.sortkey = sortkey |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
105 |
def __getattr__(self, attr): |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
106 |
return getattr(self.origdict, attr) |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
107 |
def __iter__(self): |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
108 |
return iter(sorted(self.origdict, key=self.sortkey)) |
0 | 109 |
|
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
|
110 |
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
|
111 |
"""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
|
112 |
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
|
113 |
""" |
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 |
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
|
115 |
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
|
116 |
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
|
117 |
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
|
118 |
schema_eids[x] = x.eid |
10663
54b8a1f249fb
[py3k] dict.itervalues → dict.values
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10662
diff
changeset
|
119 |
for rdef in x.rdefs.values(): |
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
|
120 |
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
|
121 |
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
|
122 |
|
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 |
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
|
124 |
"""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
|
125 |
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
|
126 |
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
|
127 |
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
|
128 |
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
|
129 |
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
|
130 |
schema._eid_index[x.eid] = x |
10663
54b8a1f249fb
[py3k] dict.itervalues → dict.values
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10662
diff
changeset
|
131 |
for rdef in x.rdefs.values(): |
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
|
132 |
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
|
133 |
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
|
134 |
|
0 | 135 |
|
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
|
136 |
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
|
137 |
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
|
138 |
|
0 | 139 |
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
|
140 |
|
9460
a2a0bc984863
[config] cleanup/refactor server sources file values handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9456
diff
changeset
|
141 |
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
|
142 |
from cubicweb.server import set_debug, debugged |
0 | 143 |
from cubicweb.server.querier import QuerierHelper |
144 |
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
|
145 |
from cubicweb.server.sources.rql2sql import SQLGenerator, remove_unused_solutions |
0 | 146 |
|
147 |
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
|
148 |
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
|
149 |
|
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 |
@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
|
151 |
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
|
152 |
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
|
153 |
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
|
154 |
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
|
155 |
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
|
156 |
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
|
157 |
|
0 | 158 |
def setUp(self): |
9460
a2a0bc984863
[config] cleanup/refactor server sources file values handling
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9456
diff
changeset
|
159 |
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
|
160 |
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
|
161 |
self.rqlhelper = RQLHelper(self.schema, |
5ef9dd383ae2
[tests/rqlannotation,querier] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9835
diff
changeset
|
162 |
special_relations={'eid': 'uid', |
5ef9dd383ae2
[tests/rqlannotation,querier] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9835
diff
changeset
|
163 |
'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
|
164 |
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
|
165 |
self.qhelper = QuerierHelper(self.repo, self.schema) |
0 | 166 |
ExecutionPlan._check_permissions = _dummy_check_permissions |
167 |
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
|
168 |
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
|
169 |
self.o = SQLGenerator(self.schema, self.dbhelper) |
0 | 170 |
|
171 |
def tearDown(self): |
|
172 |
ExecutionPlan._check_permissions = _orig_check_permissions |
|
173 |
rqlannotation._select_principal = _orig_select_principal |
|
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2074
diff
changeset
|
174 |
|
2069
7c0a1b90b1c6
set_debug method on rql2sql test as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
175 |
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
|
176 |
set_debug(debug) |
6758
28b11ecf319b
[ms] #1382452: incorrect results with multi-sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6671
diff
changeset
|
177 |
def debugged(self, debug): |
28b11ecf319b
[ms] #1382452: incorrect results with multi-sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6671
diff
changeset
|
178 |
return debugged(debug) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1789
diff
changeset
|
179 |
|
0 | 180 |
def _prepare(self, rql): |
181 |
#print '******************** prepare', rql |
|
182 |
union = self.rqlhelper.parse(rql) |
|
183 |
#print '********* parsed', union.as_string() |
|
184 |
self.rqlhelper.compute_solutions(union) |
|
185 |
#print '********* solutions', solutions |
|
186 |
self.rqlhelper.simplify(union) |
|
187 |
#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
|
188 |
plan = self.qhelper.plan_factory(union, {}, FakeSession(self.repo)) |
0 | 189 |
plan.preprocess(union) |
190 |
for select in union.children: |
|
191 |
select.solutions.sort() |
|
192 |
#print '********* ppsolutions', solutions |
|
193 |
return union |
|
194 |
||
195 |
||
196 |
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
|
197 |
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
|
198 |
|
0 | 199 |
def setUp(self): |
200 |
self.o = self.repo.querier |
|
201 |
self.session = self.repo._sessions.values()[0] |
|
202 |
self.ueid = self.session.user.eid |
|
203 |
assert self.ueid != -1 |
|
204 |
self.repo._type_source_cache = {} # clear cache |
|
205 |
self.maxeid = self.get_max_eid() |
|
206 |
do_monkey_patch() |
|
4773
6ab9ca63531f
[testlib] properly close dumb sessions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
207 |
self._dumb_sessions = [] |
0 | 208 |
|
209 |
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
|
210 |
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
|
211 |
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
|
212 |
|
0 | 213 |
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
|
214 |
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
|
215 |
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
|
216 |
cnx.commit() |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1789
diff
changeset
|
217 |
|
0 | 218 |
def tearDown(self): |
219 |
undo_monkey_patch() |
|
220 |
self.cleanup() |
|
221 |
assert self.session.user.eid != -1 |
|
222 |
||
223 |
def set_debug(self, debug): |
|
224 |
set_debug(debug) |
|
6758
28b11ecf319b
[ms] #1382452: incorrect results with multi-sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6671
diff
changeset
|
225 |
def debugged(self, debug): |
28b11ecf319b
[ms] #1382452: incorrect results with multi-sources
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6671
diff
changeset
|
226 |
return debugged(debug) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1789
diff
changeset
|
227 |
|
0 | 228 |
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
|
229 |
rqlhelper = self.repo.vreg.rqlhelper |
0 | 230 |
# reset uid_func so it don't try to get type from eids |
231 |
rqlhelper._analyser.uid_func = None |
|
232 |
rqlhelper._analyser.uid_func_mapping = {} |
|
233 |
return rqlhelper |
|
234 |
||
9850
5ef9dd383ae2
[tests/rqlannotation,querier] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9835
diff
changeset
|
235 |
def _prepare_plan(self, cnx, rql, kwargs=None, simplify=True): |
0 | 236 |
rqlhelper = self._rqlhelper() |
237 |
rqlst = rqlhelper.parse(rql) |
|
238 |
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
|
239 |
if simplify: |
7002e91d304a
should not simplify previous to preprocess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
240 |
rqlhelper.simplify(rqlst) |
0 | 241 |
for select in rqlst.children: |
242 |
select.solutions.sort() |
|
9850
5ef9dd383ae2
[tests/rqlannotation,querier] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9835
diff
changeset
|
243 |
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
|
244 |
|
9850
5ef9dd383ae2
[tests/rqlannotation,querier] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9835
diff
changeset
|
245 |
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
|
246 |
plan = self._prepare_plan(cnx, rql, kwargs, simplify=False) |
0 | 247 |
plan.preprocess(plan.rqlst) |
248 |
rqlst = plan.rqlst.children[0] |
|
249 |
rqlst.solutions = remove_unused_solutions(rqlst, rqlst.solutions, {}, self.repo.schema)[0] |
|
250 |
return rqlst |
|
251 |
||
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
|
252 |
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
|
253 |
"""lightweight session using the current user with hi-jacked groups""" |
0 | 254 |
# 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
|
255 |
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
|
256 |
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
|
257 |
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
|
258 |
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
|
259 |
return s |
0 | 260 |
|
9831
db4aeba5d336
[test/querier] use the new connection api (part 1/3)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9468
diff
changeset
|
261 |
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
|
262 |
with self.session.new_cnx() as cnx: |
10365
21461f80f348
[connection] remove ensure_cnx_set context manager uses
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9850
diff
changeset
|
263 |
try: |
21461f80f348
[connection] remove ensure_cnx_set context manager uses
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9850
diff
changeset
|
264 |
return self.o.execute(cnx, rql, args, build_descr) |
21461f80f348
[connection] remove ensure_cnx_set context manager uses
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9850
diff
changeset
|
265 |
finally: |
21461f80f348
[connection] remove ensure_cnx_set context manager uses
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9850
diff
changeset
|
266 |
if rql.startswith(('INSERT', 'DELETE', 'SET')): |
21461f80f348
[connection] remove ensure_cnx_set context manager uses
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9850
diff
changeset
|
267 |
cnx.commit() |
9831
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: |
|
10662
10942ed172de
[py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10589
diff
changeset
|
310 |
orderedkeys = sorted((k[1], k[2], v) for k, v in variante.items()) |
10942ed172de
[py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10589
diff
changeset
|
311 |
variante = DumbOrderedDict(sorted(variante.items(), |
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) |
|
10662
10942ed172de
[py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10589
diff
changeset
|
322 |
res = DumbOrderedDict(sorted(res.items(), 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 |