author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 21 Oct 2010 09:33:12 +0200 | |
branch | stable |
changeset 6571 | 71b446d1cf93 |
parent 6348 | f5bd501628b0 |
child 6869 | 900cb9b1b687 |
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
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:
4491
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5561
58b05c314443
[selectors] ensure adaptable('IDownloadable') takes precedence over implements('Any')
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
18 |
"""unit tests for selectors mechanism""" |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
19 |
|
6348
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
20 |
from operator import eq, lt, le, gt |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
21 |
from logilab.common.testlib import TestCase, unittest_main |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
22 |
|
5561
58b05c314443
[selectors] ensure adaptable('IDownloadable') takes precedence over implements('Any')
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
23 |
from cubicweb import Binary |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
24 |
from cubicweb.devtools.testlib import CubicWebTC |
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
25 |
from cubicweb.appobject import Selector, AndSelector, OrSelector |
6348
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
26 |
from cubicweb.selectors import (is_instance, adaptable, match_user_groups, |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
27 |
multi_lines_rset) |
779
8510e14335e1
implements some str, fix implements selector, test and fixes
sylvain.thenault@logilab.fr
parents:
630
diff
changeset
|
28 |
from cubicweb.interfaces import IDownloadable |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
29 |
from cubicweb.web import action |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
30 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
31 |
class _1_(Selector): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
32 |
def __call__(self, *args, **kwargs): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
33 |
return 1 |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
34 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
35 |
class _0_(Selector): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
36 |
def __call__(self, *args, **kwargs): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
37 |
return 0 |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
38 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
39 |
def _2_(*args, **kwargs): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
40 |
return 2 |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
41 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
42 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
43 |
class SelectorsTC(TestCase): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
44 |
def test_basic_and(self): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
45 |
selector = _1_() & _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
46 |
self.assertEqual(selector(None), 2) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
47 |
selector = _1_() & _0_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
48 |
self.assertEqual(selector(None), 0) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
49 |
selector = _0_() & _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
50 |
self.assertEqual(selector(None), 0) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
51 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
52 |
def test_basic_or(self): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
53 |
selector = _1_() | _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
54 |
self.assertEqual(selector(None), 1) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
55 |
selector = _1_() | _0_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
56 |
self.assertEqual(selector(None), 1) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
57 |
selector = _0_() | _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
58 |
self.assertEqual(selector(None), 1) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
59 |
selector = _0_() | _0_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
60 |
self.assertEqual(selector(None), 0) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
61 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
62 |
def test_selector_and_function(self): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
63 |
selector = _1_() & _2_ |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
64 |
self.assertEqual(selector(None), 3) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
65 |
selector = _2_ & _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
66 |
self.assertEqual(selector(None), 3) |
1473 | 67 |
|
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
68 |
def test_three_and(self): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
69 |
selector = _1_() & _1_() & _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
70 |
self.assertEqual(selector(None), 3) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
71 |
selector = _1_() & _0_() & _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
72 |
self.assertEqual(selector(None), 0) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
73 |
selector = _0_() & _1_() & _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
74 |
self.assertEqual(selector(None), 0) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
75 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
76 |
def test_three_or(self): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
77 |
selector = _1_() | _1_() | _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
78 |
self.assertEqual(selector(None), 1) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
79 |
selector = _1_() | _0_() | _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
80 |
self.assertEqual(selector(None), 1) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
81 |
selector = _0_() | _1_() | _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
82 |
self.assertEqual(selector(None), 1) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
83 |
selector = _0_() | _0_() | _0_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
84 |
self.assertEqual(selector(None), 0) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
85 |
|
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
86 |
def test_composition(self): |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
87 |
selector = (_1_() & _1_()) & (_1_() & _1_()) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
88 |
self.failUnless(isinstance(selector, AndSelector)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
89 |
self.assertEqual(len(selector.selectors), 4) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
90 |
self.assertEqual(selector(None), 4) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
91 |
selector = (_1_() & _0_()) | (_1_() & _1_()) |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
92 |
self.failUnless(isinstance(selector, OrSelector)) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
93 |
self.assertEqual(len(selector.selectors), 2) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
94 |
self.assertEqual(selector(None), 2) |
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
95 |
|
779
8510e14335e1
implements some str, fix implements selector, test and fixes
sylvain.thenault@logilab.fr
parents:
630
diff
changeset
|
96 |
def test_search_selectors(self): |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5561
diff
changeset
|
97 |
sel = is_instance('something') |
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5561
diff
changeset
|
98 |
self.assertIs(sel.search_selector(is_instance), sel) |
779
8510e14335e1
implements some str, fix implements selector, test and fixes
sylvain.thenault@logilab.fr
parents:
630
diff
changeset
|
99 |
csel = AndSelector(sel, Selector()) |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5561
diff
changeset
|
100 |
self.assertIs(csel.search_selector(is_instance), sel) |
779
8510e14335e1
implements some str, fix implements selector, test and fixes
sylvain.thenault@logilab.fr
parents:
630
diff
changeset
|
101 |
csel = AndSelector(Selector(), sel) |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5561
diff
changeset
|
102 |
self.assertIs(csel.search_selector(is_instance), sel) |
1473 | 103 |
|
5373
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
104 |
def test_inplace_and(self): |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
105 |
selector = _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
106 |
selector &= _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
107 |
selector &= _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
108 |
self.assertEqual(selector(None), 3) |
5373
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
109 |
selector = _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
110 |
selector &= _0_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
111 |
selector &= _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
112 |
self.assertEqual(selector(None), 0) |
5373
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
113 |
selector = _0_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
114 |
selector &= _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
115 |
selector &= _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
116 |
self.assertEqual(selector(None), 0) |
5373
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
117 |
selector = _0_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
118 |
selector &= _0_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
119 |
selector &= _0_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
120 |
self.assertEqual(selector(None), 0) |
5373
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
121 |
|
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
122 |
def test_inplace_or(self): |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
123 |
selector = _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
124 |
selector |= _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
125 |
selector |= _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
126 |
self.assertEqual(selector(None), 1) |
5373
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
127 |
selector = _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
128 |
selector |= _0_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
129 |
selector |= _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
130 |
self.assertEqual(selector(None), 1) |
5373
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
131 |
selector = _0_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
132 |
selector |= _1_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
133 |
selector |= _1_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
134 |
self.assertEqual(selector(None), 1) |
5373
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
135 |
selector = _0_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
136 |
selector |= _0_() |
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
137 |
selector |= _0_() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
138 |
self.assertEqual(selector(None), 0) |
5373
24a873060692
[selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
4491
diff
changeset
|
139 |
|
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
140 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
141 |
class ImplementsSelectorTC(CubicWebTC): |
779
8510e14335e1
implements some str, fix implements selector, test and fixes
sylvain.thenault@logilab.fr
parents:
630
diff
changeset
|
142 |
def test_etype_priority(self): |
8510e14335e1
implements some str, fix implements selector, test and fixes
sylvain.thenault@logilab.fr
parents:
630
diff
changeset
|
143 |
req = self.request() |
5561
58b05c314443
[selectors] ensure adaptable('IDownloadable') takes precedence over implements('Any')
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
144 |
f = req.create_entity('File', data_name=u'hop.txt', data=Binary('hop')) |
58b05c314443
[selectors] ensure adaptable('IDownloadable') takes precedence over implements('Any')
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
145 |
rset = f.as_rset() |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5561
diff
changeset
|
146 |
anyscore = is_instance('Any')(f.__class__, req, rset=rset) |
5561
58b05c314443
[selectors] ensure adaptable('IDownloadable') takes precedence over implements('Any')
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
147 |
idownscore = adaptable('IDownloadable')(f.__class__, req, rset=rset) |
779
8510e14335e1
implements some str, fix implements selector, test and fixes
sylvain.thenault@logilab.fr
parents:
630
diff
changeset
|
148 |
self.failUnless(idownscore > anyscore, (idownscore, anyscore)) |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5561
diff
changeset
|
149 |
filescore = is_instance('File')(f.__class__, req, rset=rset) |
779
8510e14335e1
implements some str, fix implements selector, test and fixes
sylvain.thenault@logilab.fr
parents:
630
diff
changeset
|
150 |
self.failUnless(filescore > idownscore, (filescore, idownscore)) |
1473 | 151 |
|
152 |
def test_etype_inheritance_no_yams_inheritance(self): |
|
2657
de974465d381
[appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
153 |
cls = self.vreg['etypes'].etype_class('Personne') |
5877
0c7b7b76a84f
[selectors] provide a new, optimized, is_instance selector that should at some point replace implements (along with the adaptable selector)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5561
diff
changeset
|
154 |
self.failIf(is_instance('Societe').score_class(cls, self.request())) |
1473 | 155 |
|
6046
3fd4a34c4a09
[selectors] fix is_instance bug w/ parent classes. Also slight performance enhancements by changing what's returned by vreg['etypes'].parent_classes method (dedicated for this usage...) and removing no more necessary methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
156 |
def test_yams_inheritance(self): |
3fd4a34c4a09
[selectors] fix is_instance bug w/ parent classes. Also slight performance enhancements by changing what's returned by vreg['etypes'].parent_classes method (dedicated for this usage...) and removing no more necessary methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
157 |
cls = self.vreg['etypes'].etype_class('Transition') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6046
diff
changeset
|
158 |
self.assertEqual(is_instance('BaseTransition').score_class(cls, self.request()), |
6046
3fd4a34c4a09
[selectors] fix is_instance bug w/ parent classes. Also slight performance enhancements by changing what's returned by vreg['etypes'].parent_classes method (dedicated for this usage...) and removing no more necessary methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
159 |
3) |
3fd4a34c4a09
[selectors] fix is_instance bug w/ parent classes. Also slight performance enhancements by changing what's returned by vreg['etypes'].parent_classes method (dedicated for this usage...) and removing no more necessary methods
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5877
diff
changeset
|
160 |
|
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
161 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2657
diff
changeset
|
162 |
class MatchUserGroupsTC(CubicWebTC): |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
163 |
def test_owners_group(self): |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
164 |
"""tests usage of 'owners' group with match_user_group""" |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
165 |
class SomeAction(action.Action): |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2773
diff
changeset
|
166 |
__regid__ = 'yo' |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
167 |
category = 'foo' |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
168 |
__select__ = match_user_groups('owners') |
1640 | 169 |
self.vreg._loadedmods[__name__] = {} |
4491
a0f48c31b58a
kill register_appobject_class method, simplifying autoregistration. Update test accordingly (test which manually registers object should also properly call there __register__ method). Drop the disable-appobjects config file entry: no one used it since its introduction years ago.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4490
diff
changeset
|
170 |
self.vreg.register(SomeAction) |
4490
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
171 |
SomeAction.__registered__(self.vreg['actions']) |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
172 |
self.failUnless(SomeAction in self.vreg['actions']['yo'], self.vreg['actions']) |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
173 |
try: |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
174 |
# login as a simple user |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
175 |
self.create_user('john') |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
176 |
self.login('john') |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
177 |
# it should not be possible to use SomeAction not owned objects |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2773
diff
changeset
|
178 |
req = self.request() |
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2773
diff
changeset
|
179 |
rset = req.execute('Any G WHERE G is CWGroup, G name "managers"') |
1640 | 180 |
self.failIf('yo' in dict(self.pactions(req, rset))) |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
181 |
# insert a new card, and check that we can use SomeAction on our object |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
182 |
self.execute('INSERT Card C: C title "zoubidou"') |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
183 |
self.commit() |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2773
diff
changeset
|
184 |
req = self.request() |
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2773
diff
changeset
|
185 |
rset = req.execute('Card C WHERE C title "zoubidou"') |
1640 | 186 |
self.failUnless('yo' in dict(self.pactions(req, rset)), self.pactions(req, rset)) |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
187 |
# make sure even managers can't use the action |
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
188 |
self.restore_connection() |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2773
diff
changeset
|
189 |
req = self.request() |
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2773
diff
changeset
|
190 |
rset = req.execute('Card C WHERE C title "zoubidou"') |
1640 | 191 |
self.failIf('yo' in dict(self.pactions(req, rset))) |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
192 |
finally: |
3418
7b49fa7e942d
[api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2773
diff
changeset
|
193 |
del self.vreg[SomeAction.__registry__][SomeAction.__regid__] |
1571
e9ad2724659d
tests depends on the bootstrap cube
sylvain.thenault@logilab.fr
parents:
1473
diff
changeset
|
194 |
|
6348
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
195 |
|
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
196 |
class MultiLinesRsetSelectorTC(CubicWebTC): |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
197 |
def setUp(self): |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
198 |
super(MultiLinesRsetSelectorTC, self).setUp() |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
199 |
self.req = self.request() |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
200 |
self.req.execute('INSERT CWGroup G: G name "group1"') |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
201 |
self.req.execute('INSERT CWGroup G: G name "group2"') |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
202 |
self.commit() |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
203 |
self.rset = self.req.execute('Any G WHERE G is CWGroup') |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
204 |
|
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
205 |
def test_default_op_in_selector(self): |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
206 |
expected = len(self.rset) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
207 |
selector = multi_lines_rset(expected) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
208 |
self.assertEqual(selector(None, self.req, self.rset), 1) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
209 |
self.assertEqual(selector(None, self.req, None), 0) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
210 |
selector = multi_lines_rset(expected + 1) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
211 |
self.assertEqual(selector(None, self.req, self.rset), 0) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
212 |
self.assertEqual(selector(None, self.req, None), 0) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
213 |
selector = multi_lines_rset(expected - 1) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
214 |
self.assertEqual(selector(None, self.req, self.rset), 0) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
215 |
self.assertEqual(selector(None, self.req, None), 0) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
216 |
|
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
217 |
def test_without_rset(self): |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
218 |
expected = len(self.rset) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
219 |
selector = multi_lines_rset(expected) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
220 |
self.assertEqual(selector(None, self.req, None), 0) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
221 |
selector = multi_lines_rset(expected + 1) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
222 |
self.assertEqual(selector(None, self.req, None), 0) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
223 |
selector = multi_lines_rset(expected - 1) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
224 |
self.assertEqual(selector(None, self.req, None), 0) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
225 |
|
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
226 |
def test_with_operators(self): |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
227 |
expected = len(self.rset) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
228 |
|
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
229 |
# Format 'expected', 'operator', 'assert' |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
230 |
testdata = (( expected, eq, 1), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
231 |
( expected+1, eq, 0), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
232 |
( expected-1, eq, 0), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
233 |
( expected, le, 1), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
234 |
( expected+1, le, 1), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
235 |
( expected-1, le, 0), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
236 |
( expected-1, gt, 1), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
237 |
( expected, gt, 0), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
238 |
( expected+1, gt, 0), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
239 |
( expected+1, lt, 1), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
240 |
( expected, lt, 0), |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
241 |
( expected-1, lt, 0)) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
242 |
|
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
243 |
for (expected, operator, assertion) in testdata: |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
244 |
selector = multi_lines_rset(expected, operator) |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
245 |
yield self.assertEqual, selector(None, self.req, self.rset), assertion |
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
246 |
|
f5bd501628b0
[selectors] multi_lines_rset selector supports now optional operator for richer comparaisons
Julien Jehannet <julien.jehannet@logilab.fr>
parents:
6340
diff
changeset
|
247 |
|
630
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
248 |
if __name__ == '__main__': |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
249 |
unittest_main() |
66ff0b2f7d03
simple test implementation for binary operators on selectors
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff
changeset
|
250 |