author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 05 Nov 2010 09:12:57 +0100 | |
branch | stable |
changeset 6671 | c34fa947df07 |
parent 6654 | 18d159a2d1ba |
child 6758 | 28b11ecf319b |
permissions | -rw-r--r-- |
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
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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 |
||
6671
c34fa947df07
[ms test] fix nasty cache effect break unittest_multisources.test_not_relation since introduction of local_eid method andfor full dereferencement of external eids
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6654
diff
changeset
|
25 |
from copy import deepcopy |
0 | 26 |
from pprint import pprint |
27 |
||
2074
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
28 |
from logilab.common.decorators import clear_cache |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
29 |
|
0 | 30 |
def tuplify(list): |
31 |
for i in range(len(list)): |
|
32 |
if type(list[i]) is not type(()): |
|
33 |
list[i] = tuple(list[i]) |
|
34 |
return list |
|
35 |
||
36 |
def snippet_cmp(a, b): |
|
37 |
a = (a[0], [e.expression for e in a[1]]) |
|
38 |
b = (b[0], [e.expression for e in b[1]]) |
|
39 |
return cmp(a, b) |
|
40 |
||
41 |
def test_plan(self, rql, expected, kwargs=None): |
|
42 |
plan = self._prepare_plan(rql, kwargs) |
|
43 |
self.planner.build_plan(plan) |
|
44 |
try: |
|
6369
a151453dc564
[test] more update to unittest2 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
45 |
self.assertEqual(len(plan.steps), len(expected), |
0 | 46 |
'expected %s steps, got %s' % (len(expected), len(plan.steps))) |
47 |
# step order is important |
|
48 |
for i, step in enumerate(plan.steps): |
|
49 |
compare_steps(self, step.test_repr(), expected[i]) |
|
50 |
except AssertionError: |
|
51 |
pprint([step.test_repr() for step in plan.steps]) |
|
52 |
raise |
|
53 |
||
54 |
def compare_steps(self, step, expected): |
|
55 |
try: |
|
6369
a151453dc564
[test] more update to unittest2 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
56 |
self.assertEqual(step[0], expected[0], 'expected step type %s, got %s' % (expected[0], step[0])) |
0 | 57 |
if len(step) > 2 and isinstance(step[1], list) and isinstance(expected[1], list): |
58 |
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
|
59 |
self.assertEqual(len(queries), len(equeries), |
0 | 60 |
'expected %s queries, got %s' % (len(equeries), len(queries))) |
61 |
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
|
62 |
self.assertEqual(rql, equeries[i][0]) |
a151453dc564
[test] more update to unittest2 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
63 |
self.assertEqual(sorted(sol), sorted(equeries[i][1])) |
0 | 64 |
idx = 2 |
65 |
else: |
|
66 |
idx = 1 |
|
6369
a151453dc564
[test] more update to unittest2 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5768
diff
changeset
|
67 |
self.assertEqual(step[idx:-1], expected[idx:-1], |
0 | 68 |
'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
|
69 |
self.assertEqual(len(step[-1]), len(expected[-1]), |
0 | 70 |
'got %s child steps, expected %s' % (len(step[-1]), len(expected[-1]))) |
71 |
except AssertionError: |
|
72 |
print 'error on step ', |
|
73 |
pprint(step[:-1]) |
|
74 |
raise |
|
75 |
children = step[-1] |
|
76 |
if step[0] in ('UnionFetchStep', 'UnionStep'): |
|
77 |
# sort children |
|
78 |
children = sorted(children) |
|
79 |
expectedchildren = sorted(expected[-1]) |
|
80 |
else: |
|
81 |
expectedchildren = expected[-1] |
|
82 |
for i, substep in enumerate(children): |
|
83 |
compare_steps(self, substep, expectedchildren[i]) |
|
84 |
||
85 |
||
86 |
class DumbOrderedDict(list): |
|
87 |
def __iter__(self): |
|
88 |
return self.iterkeys() |
|
89 |
def __contains__(self, key): |
|
90 |
return key in self.iterkeys() |
|
91 |
def __getitem__(self, key): |
|
1236
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
92 |
for key_, value in list.__iter__(self): |
0 | 93 |
if key == key_: |
94 |
return value |
|
95 |
raise KeyError(key) |
|
96 |
def iterkeys(self): |
|
97 |
return (x for x, y in list.__iter__(self)) |
|
98 |
def iteritems(self): |
|
99 |
return (x for x in list.__iter__(self)) |
|
1236
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
100 |
def items(self): |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
101 |
return [x for x in list.__iter__(self)] |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
102 |
|
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
103 |
class DumbOrderedDict2(object): |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
104 |
def __init__(self, origdict, sortkey): |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
105 |
self.origdict = origdict |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
106 |
self.sortkey = sortkey |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
107 |
def __getattr__(self, attr): |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
108 |
return getattr(self.origdict, attr) |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
109 |
def __iter__(self): |
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
110 |
return iter(sorted(self.origdict, key=self.sortkey)) |
0 | 111 |
|
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
|
112 |
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
|
113 |
"""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
|
114 |
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
|
115 |
""" |
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 = {} |
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.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
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
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
|
123 |
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
|
124 |
|
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 |
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
|
126 |
"""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
|
127 |
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
|
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 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
|
131 |
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
|
132 |
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
|
133 |
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
|
134 |
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
|
135 |
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
|
136 |
|
0 | 137 |
|
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
|
138 |
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
|
139 |
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
|
140 |
|
0 | 141 |
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
|
142 |
|
0 | 143 |
from cubicweb.devtools.fake import FakeRepo, FakeSession |
144 |
from cubicweb.server import set_debug |
|
145 |
from cubicweb.server.querier import QuerierHelper |
|
146 |
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
|
147 |
from cubicweb.server.sources.rql2sql import SQLGenerator, remove_unused_solutions |
0 | 148 |
|
149 |
class RQLGeneratorTC(TestCase): |
|
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
|
150 |
schema = backend = None # set this in concret test |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1789
diff
changeset
|
151 |
|
0 | 152 |
def setUp(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
|
153 |
self.repo = FakeRepo(self.schema) |
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
|
154 |
self.repo.system_source = mock_object(dbdriver=self.backend) |
0 | 155 |
self.rqlhelper = RQLHelper(self.schema, special_relations={'eid': 'uid', |
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
|
156 |
'has_text': 'fti'}, |
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
|
157 |
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
|
158 |
self.qhelper = QuerierHelper(self.repo, self.schema) |
0 | 159 |
ExecutionPlan._check_permissions = _dummy_check_permissions |
160 |
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
|
161 |
if self.backend is not None: |
6414
6003dc203567
[test] skip test when dbhelper has no underlying dbapi module available
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6369
diff
changeset
|
162 |
try: |
6003dc203567
[test] skip test when dbhelper has no underlying dbapi module available
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6369
diff
changeset
|
163 |
dbhelper = get_db_helper(self.backend) |
6003dc203567
[test] skip test when dbhelper has no underlying dbapi module available
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6369
diff
changeset
|
164 |
except ImportError, ex: |
6003dc203567
[test] skip test when dbhelper has no underlying dbapi module available
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6369
diff
changeset
|
165 |
self.skipTest(str(ex)) |
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
|
166 |
self.o = SQLGenerator(self.schema, dbhelper) |
0 | 167 |
|
168 |
def tearDown(self): |
|
169 |
ExecutionPlan._check_permissions = _orig_check_permissions |
|
170 |
rqlannotation._select_principal = _orig_select_principal |
|
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2074
diff
changeset
|
171 |
|
2069
7c0a1b90b1c6
set_debug method on rql2sql test as well
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
172 |
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
|
173 |
set_debug(debug) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1789
diff
changeset
|
174 |
|
0 | 175 |
def _prepare(self, rql): |
176 |
#print '******************** prepare', rql |
|
177 |
union = self.rqlhelper.parse(rql) |
|
178 |
#print '********* parsed', union.as_string() |
|
179 |
self.rqlhelper.compute_solutions(union) |
|
180 |
#print '********* solutions', solutions |
|
181 |
self.rqlhelper.simplify(union) |
|
182 |
#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
|
183 |
plan = self.qhelper.plan_factory(union, {}, FakeSession(self.repo)) |
0 | 184 |
plan.preprocess(union) |
185 |
for select in union.children: |
|
186 |
select.solutions.sort() |
|
187 |
#print '********* ppsolutions', solutions |
|
188 |
return union |
|
189 |
||
190 |
||
191 |
class BaseQuerierTC(TestCase): |
|
192 |
repo = None # set this in concret test |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1789
diff
changeset
|
193 |
|
0 | 194 |
def setUp(self): |
195 |
self.o = self.repo.querier |
|
196 |
self.session = self.repo._sessions.values()[0] |
|
197 |
self.ueid = self.session.user.eid |
|
198 |
assert self.ueid != -1 |
|
199 |
self.repo._type_source_cache = {} # clear cache |
|
200 |
self.pool = self.session.set_pool() |
|
201 |
self.maxeid = self.get_max_eid() |
|
202 |
do_monkey_patch() |
|
4773
6ab9ca63531f
[testlib] properly close dumb sessions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
203 |
self._dumb_sessions = [] |
0 | 204 |
|
205 |
def get_max_eid(self): |
|
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4773
diff
changeset
|
206 |
return self.session.execute('Any MAX(X)')[0][0] |
0 | 207 |
def cleanup(self): |
4835
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4773
diff
changeset
|
208 |
self.session.set_pool() |
13b0b96d7982
[repo] enhanced security handling: deprecates unsafe_execute, in favor of explicit read/write security control using the `enabled_security` context manager. Also code executed on the repository side is now unsafe by default.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4773
diff
changeset
|
209 |
self.session.execute('DELETE Any X WHERE X eid > %s' % self.maxeid) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1789
diff
changeset
|
210 |
|
0 | 211 |
def tearDown(self): |
212 |
undo_monkey_patch() |
|
213 |
self.session.rollback() |
|
214 |
self.cleanup() |
|
215 |
self.commit() |
|
4773
6ab9ca63531f
[testlib] properly close dumb sessions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
216 |
# properly close dumb sessions |
6ab9ca63531f
[testlib] properly close dumb sessions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
217 |
for session in self._dumb_sessions: |
6ab9ca63531f
[testlib] properly close dumb sessions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
218 |
session.rollback() |
6ab9ca63531f
[testlib] properly close dumb sessions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
219 |
session.close() |
0 | 220 |
self.repo._free_pool(self.pool) |
221 |
assert self.session.user.eid != -1 |
|
222 |
||
223 |
def set_debug(self, debug): |
|
224 |
set_debug(debug) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1789
diff
changeset
|
225 |
|
0 | 226 |
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
|
227 |
rqlhelper = self.repo.vreg.rqlhelper |
0 | 228 |
# reset uid_func so it don't try to get type from eids |
229 |
rqlhelper._analyser.uid_func = None |
|
230 |
rqlhelper._analyser.uid_func_mapping = {} |
|
231 |
return rqlhelper |
|
232 |
||
4184
7002e91d304a
should not simplify previous to preprocess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
233 |
def _prepare_plan(self, rql, kwargs=None, simplify=True): |
0 | 234 |
rqlhelper = self._rqlhelper() |
235 |
rqlst = rqlhelper.parse(rql) |
|
236 |
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
|
237 |
if simplify: |
7002e91d304a
should not simplify previous to preprocess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
238 |
rqlhelper.simplify(rqlst) |
0 | 239 |
for select in rqlst.children: |
240 |
select.solutions.sort() |
|
241 |
return self.o.plan_factory(rqlst, kwargs, self.session) |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1789
diff
changeset
|
242 |
|
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1789
diff
changeset
|
243 |
def _prepare(self, rql, kwargs=None): |
4184
7002e91d304a
should not simplify previous to preprocess
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3240
diff
changeset
|
244 |
plan = self._prepare_plan(rql, kwargs, simplify=False) |
0 | 245 |
plan.preprocess(plan.rqlst) |
246 |
rqlst = plan.rqlst.children[0] |
|
247 |
rqlst.solutions = remove_unused_solutions(rqlst, rqlst.solutions, {}, self.repo.schema)[0] |
|
248 |
return rqlst |
|
249 |
||
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
|
250 |
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
|
251 |
"""lightweight session using the current user with hi-jacked groups""" |
0 | 252 |
# use self.session.user.eid to get correct owned_by relation, unless explicit eid |
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
|
253 |
u = self.repo._build_user(self.session, self.session.user.eid) |
0 | 254 |
u._groups = set(groups) |
255 |
s = Session(u, self.repo) |
|
256 |
s._threaddata.pool = self.pool |
|
4773
6ab9ca63531f
[testlib] properly close dumb sessions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
257 |
# register session to ensure it gets closed |
6ab9ca63531f
[testlib] properly close dumb sessions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
258 |
self._dumb_sessions.append(s) |
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
|
259 |
return s |
0 | 260 |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
261 |
def execute(self, rql, args=None, build_descr=True): |
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4835
diff
changeset
|
262 |
return self.o.execute(self.session, rql, args, build_descr) |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1789
diff
changeset
|
263 |
|
0 | 264 |
def commit(self): |
265 |
self.session.commit() |
|
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1789
diff
changeset
|
266 |
self.session.set_pool() |
0 | 267 |
|
268 |
||
269 |
class BasePlannerTC(BaseQuerierTC): |
|
2200
25bb65dc4559
test fixes, all server tests ok, except unittest_migractions (due to inter-tests-side-effects...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2172
diff
changeset
|
270 |
newsources = 0 |
2074
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
271 |
def setup(self): |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
272 |
clear_cache(self.repo, 'rel_type_sources') |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
273 |
clear_cache(self.repo, 'rel_type_sources') |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
274 |
clear_cache(self.repo, 'can_cross_relation') |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
275 |
clear_cache(self.repo, 'is_multi_sources_relation') |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
276 |
# XXX source_defs |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
277 |
self.o = self.repo.querier |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
278 |
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
|
279 |
self.pool = self.session.set_pool() |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
280 |
self.schema = self.o.schema |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
281 |
self.sources = self.o._repo.sources |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
282 |
self.system = self.sources[-1] |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
283 |
do_monkey_patch() |
4773
6ab9ca63531f
[testlib] properly close dumb sessions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
284 |
self._dumb_sessions = [] # by hi-jacked parent setup |
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
|
285 |
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
|
286 |
|
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
287 |
def add_source(self, sourcecls, uri): |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6414
diff
changeset
|
288 |
self.sources.append(sourcecls(self.repo, {'uri': uri})) |
2074
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
289 |
self.repo.sources_by_uri[uri] = self.sources[-1] |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
290 |
setattr(self, uri, self.sources[-1]) |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
291 |
self.newsources += 1 |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
292 |
|
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
293 |
def tearDown(self): |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
294 |
while self.newsources: |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
295 |
source = self.sources.pop(-1) |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
296 |
del self.repo.sources_by_uri[source.uri] |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
297 |
self.newsources -= 1 |
9e268cb6202e
enhance BasePlannerTC to ease subclasses definition
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2069
diff
changeset
|
298 |
undo_monkey_patch() |
4773
6ab9ca63531f
[testlib] properly close dumb sessions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
299 |
for session in self._dumb_sessions: |
6ab9ca63531f
[testlib] properly close dumb sessions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
300 |
session._threaddata.pool = None |
6ab9ca63531f
[testlib] properly close dumb sessions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4766
diff
changeset
|
301 |
session.close() |
0 | 302 |
|
303 |
def _prepare_plan(self, rql, kwargs=None): |
|
304 |
rqlst = self.o.parse(rql, annotate=True) |
|
305 |
self.o.solutions(self.session, rqlst, kwargs) |
|
306 |
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
|
307 |
self.repo.vreg.rqlhelper.annotate(rqlst) |
0 | 308 |
for select in rqlst.children: |
309 |
select.solutions.sort() |
|
310 |
else: |
|
311 |
rqlst.solutions.sort() |
|
312 |
return self.o.plan_factory(rqlst, kwargs, self.session) |
|
313 |
||
314 |
||
315 |
# monkey patch some methods to get predicatable results ####################### |
|
316 |
||
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
|
317 |
from cubicweb.rqlrewrite import RQLRewriter |
0 | 318 |
_orig_insert_snippets = RQLRewriter.insert_snippets |
319 |
_orig_build_variantes = RQLRewriter.build_variantes |
|
320 |
||
321 |
def _insert_snippets(self, snippets, varexistsmap=None): |
|
322 |
_orig_insert_snippets(self, sorted(snippets, snippet_cmp), varexistsmap) |
|
323 |
||
324 |
def _build_variantes(self, newsolutions): |
|
325 |
variantes = _orig_build_variantes(self, newsolutions) |
|
326 |
sortedvariantes = [] |
|
327 |
for variante in variantes: |
|
1132 | 328 |
orderedkeys = sorted((k[1], k[2], v) for k, v in variante.iteritems()) |
0 | 329 |
variante = DumbOrderedDict(sorted(variante.iteritems(), |
1132 | 330 |
lambda a, b: cmp((a[0][1],a[0][2],a[1]), |
331 |
(b[0][1],b[0][2],b[1])))) |
|
0 | 332 |
sortedvariantes.append( (orderedkeys, variante) ) |
333 |
return [v for ok, v in sorted(sortedvariantes)] |
|
334 |
||
335 |
from cubicweb.server.querier import ExecutionPlan |
|
336 |
_orig_check_permissions = ExecutionPlan._check_permissions |
|
337 |
_orig_init_temp_table = ExecutionPlan.init_temp_table |
|
338 |
||
339 |
def _check_permissions(*args, **kwargs): |
|
340 |
res, restricted = _orig_check_permissions(*args, **kwargs) |
|
1132 | 341 |
res = DumbOrderedDict(sorted(res.iteritems(), lambda a, b: cmp(a[1], b[1]))) |
0 | 342 |
return res, restricted |
343 |
||
344 |
def _dummy_check_permissions(self, rqlst): |
|
345 |
return {(): rqlst.solutions}, set() |
|
346 |
||
347 |
def _init_temp_table(self, table, selection, solution): |
|
348 |
if self.tablesinorder is None: |
|
349 |
tablesinorder = self.tablesinorder = {} |
|
350 |
else: |
|
351 |
tablesinorder = self.tablesinorder |
|
352 |
if not table in tablesinorder: |
|
353 |
tablesinorder[table] = 'table%s' % len(tablesinorder) |
|
354 |
return _orig_init_temp_table(self, table, selection, solution) |
|
355 |
||
356 |
from cubicweb.server import rqlannotation |
|
357 |
_orig_select_principal = rqlannotation._select_principal |
|
358 |
||
359 |
def _select_principal(scope, relations): |
|
599
9ef680acd92a
fix select principal so results are predictable during tests
Sylvain <syt@logilab.fr>
parents:
0
diff
changeset
|
360 |
return _orig_select_principal(scope, relations, |
9ef680acd92a
fix select principal so results are predictable during tests
Sylvain <syt@logilab.fr>
parents:
0
diff
changeset
|
361 |
_sort=lambda rels: sorted(rels, key=lambda x: x.r_type)) |
0 | 362 |
|
363 |
try: |
|
364 |
from cubicweb.server.msplanner import PartPlanInformation |
|
365 |
except ImportError: |
|
366 |
class PartPlanInformation(object): |
|
6654
18d159a2d1ba
[ms planner] fix changeset 6650:72f2fd93a622: we should sometime complete input map anyway
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
367 |
def merge_input_maps(self, *args, **kwargs): |
0 | 368 |
pass |
1235
9c081452efc2
actually some monkey patching is still needed for predictability
sylvain.thenault@logilab.fr
parents:
1232
diff
changeset
|
369 |
def _choose_term(self, sourceterms): |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1789
diff
changeset
|
370 |
pass |
0 | 371 |
_orig_merge_input_maps = PartPlanInformation.merge_input_maps |
1235
9c081452efc2
actually some monkey patching is still needed for predictability
sylvain.thenault@logilab.fr
parents:
1232
diff
changeset
|
372 |
_orig_choose_term = PartPlanInformation._choose_term |
0 | 373 |
|
6654
18d159a2d1ba
[ms planner] fix changeset 6650:72f2fd93a622: we should sometime complete input map anyway
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
374 |
def _merge_input_maps(*args, **kwargs): |
18d159a2d1ba
[ms planner] fix changeset 6650:72f2fd93a622: we should sometime complete input map anyway
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
375 |
return sorted(_orig_merge_input_maps(*args, **kwargs)) |
0 | 376 |
|
1235
9c081452efc2
actually some monkey patching is still needed for predictability
sylvain.thenault@logilab.fr
parents:
1232
diff
changeset
|
377 |
def _choose_term(self, sourceterms): |
9c081452efc2
actually some monkey patching is still needed for predictability
sylvain.thenault@logilab.fr
parents:
1232
diff
changeset
|
378 |
# predictable order for test purpose |
9c081452efc2
actually some monkey patching is still needed for predictability
sylvain.thenault@logilab.fr
parents:
1232
diff
changeset
|
379 |
def get_key(x): |
9c081452efc2
actually some monkey patching is still needed for predictability
sylvain.thenault@logilab.fr
parents:
1232
diff
changeset
|
380 |
try: |
9c081452efc2
actually some monkey patching is still needed for predictability
sylvain.thenault@logilab.fr
parents:
1232
diff
changeset
|
381 |
# variable |
9c081452efc2
actually some monkey patching is still needed for predictability
sylvain.thenault@logilab.fr
parents:
1232
diff
changeset
|
382 |
return x.name |
9c081452efc2
actually some monkey patching is still needed for predictability
sylvain.thenault@logilab.fr
parents:
1232
diff
changeset
|
383 |
except AttributeError: |
9c081452efc2
actually some monkey patching is still needed for predictability
sylvain.thenault@logilab.fr
parents:
1232
diff
changeset
|
384 |
try: |
9c081452efc2
actually some monkey patching is still needed for predictability
sylvain.thenault@logilab.fr
parents:
1232
diff
changeset
|
385 |
# relation |
9c081452efc2
actually some monkey patching is still needed for predictability
sylvain.thenault@logilab.fr
parents:
1232
diff
changeset
|
386 |
return x.r_type |
9c081452efc2
actually some monkey patching is still needed for predictability
sylvain.thenault@logilab.fr
parents:
1232
diff
changeset
|
387 |
except AttributeError: |
9c081452efc2
actually some monkey patching is still needed for predictability
sylvain.thenault@logilab.fr
parents:
1232
diff
changeset
|
388 |
# const |
9c081452efc2
actually some monkey patching is still needed for predictability
sylvain.thenault@logilab.fr
parents:
1232
diff
changeset
|
389 |
return x.value |
1236
aeb46e43138d
fix choose_term monkey-patching
sylvain.thenault@logilab.fr
parents:
1235
diff
changeset
|
390 |
return _orig_choose_term(self, DumbOrderedDict2(sourceterms, get_key)) |
0 | 391 |
|
6671
c34fa947df07
[ms test] fix nasty cache effect break unittest_multisources.test_not_relation since introduction of local_eid method andfor full dereferencement of external eids
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6654
diff
changeset
|
392 |
from cubicweb.server.sources.pyrorql import PyroRQLSource |
c34fa947df07
[ms test] fix nasty cache effect break unittest_multisources.test_not_relation since introduction of local_eid method andfor full dereferencement of external eids
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6654
diff
changeset
|
393 |
_orig_syntax_tree_search = PyroRQLSource.syntax_tree_search |
c34fa947df07
[ms test] fix nasty cache effect break unittest_multisources.test_not_relation since introduction of local_eid method andfor full dereferencement of external eids
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6654
diff
changeset
|
394 |
|
c34fa947df07
[ms test] fix nasty cache effect break unittest_multisources.test_not_relation since introduction of local_eid method andfor full dereferencement of external eids
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6654
diff
changeset
|
395 |
def _syntax_tree_search(*args, **kwargs): |
c34fa947df07
[ms test] fix nasty cache effect break unittest_multisources.test_not_relation since introduction of local_eid method andfor full dereferencement of external eids
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6654
diff
changeset
|
396 |
return deepcopy(_orig_syntax_tree_search(*args, **kwargs)) |
0 | 397 |
|
398 |
def do_monkey_patch(): |
|
399 |
RQLRewriter.insert_snippets = _insert_snippets |
|
400 |
RQLRewriter.build_variantes = _build_variantes |
|
401 |
ExecutionPlan._check_permissions = _check_permissions |
|
402 |
ExecutionPlan.tablesinorder = None |
|
403 |
ExecutionPlan.init_temp_table = _init_temp_table |
|
404 |
PartPlanInformation.merge_input_maps = _merge_input_maps |
|
1235
9c081452efc2
actually some monkey patching is still needed for predictability
sylvain.thenault@logilab.fr
parents:
1232
diff
changeset
|
405 |
PartPlanInformation._choose_term = _choose_term |
6671
c34fa947df07
[ms test] fix nasty cache effect break unittest_multisources.test_not_relation since introduction of local_eid method andfor full dereferencement of external eids
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6654
diff
changeset
|
406 |
PyroRQLSource.syntax_tree_search = _syntax_tree_search |
0 | 407 |
|
408 |
def undo_monkey_patch(): |
|
409 |
RQLRewriter.insert_snippets = _orig_insert_snippets |
|
410 |
RQLRewriter.build_variantes = _orig_build_variantes |
|
411 |
ExecutionPlan._check_permissions = _orig_check_permissions |
|
412 |
ExecutionPlan.init_temp_table = _orig_init_temp_table |
|
413 |
PartPlanInformation.merge_input_maps = _orig_merge_input_maps |
|
1235
9c081452efc2
actually some monkey patching is still needed for predictability
sylvain.thenault@logilab.fr
parents:
1232
diff
changeset
|
414 |
PartPlanInformation._choose_term = _orig_choose_term |
6671
c34fa947df07
[ms test] fix nasty cache effect break unittest_multisources.test_not_relation since introduction of local_eid method andfor full dereferencement of external eids
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6654
diff
changeset
|
415 |
PyroRQLSource.syntax_tree_search = _orig_syntax_tree_search |