author | Katia Saurfelt <katia.saurfelt@logilab.fr> |
Wed, 02 Sep 2009 10:40:16 +0200 | |
branch | stable |
changeset 3095 | 804313942724 |
parent 2446 | 440cb4ea7e5c |
child 2835 | 04034421b072 |
child 4212 | ab6573088b4a |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1640
diff
changeset
|
1 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1640
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1640
diff
changeset
|
3 |
:organization: Logilab |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1640
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1640
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1640
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1640
diff
changeset
|
7 |
""" |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
8 |
import sys |
0 | 9 |
import os |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
10 |
from os.path import dirname, join, abspath |
0 | 11 |
|
12 |
from logilab.common.testlib import TestCase, unittest_main |
|
13 |
from logilab.common.changelog import Version |
|
14 |
||
15 |
from cubicweb.devtools import ApptestConfiguration |
|
16 |
||
17 |
def unabsolutize(path): |
|
18 |
parts = path.split(os.sep) |
|
515
92d95b86263e
search in reverted order else in case of installed cubes (eg in cubicweb/cubes) we do not remove all expected parts
sylvain.thenault@logilab.fr
parents:
13
diff
changeset
|
19 |
for i, part in reversed(tuple(enumerate(parts))): |
1341 | 20 |
if part.startswith('cubicweb') or part == 'cubes': |
0 | 21 |
return '/'.join(parts[i+1:]) |
22 |
raise Exception('duh? %s' % path) |
|
1640 | 23 |
|
0 | 24 |
class CubicWebConfigurationTC(TestCase): |
25 |
def setUp(self): |
|
26 |
self.config = ApptestConfiguration('data') |
|
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
27 |
self.config._cubes = ('email', 'file') |
0 | 28 |
|
1341 | 29 |
def tearDown(self): |
30 |
os.environ.pop('CW_CUBES_PATH', None) |
|
31 |
||
0 | 32 |
def test_reorder_cubes(self): |
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
33 |
# jpl depends on email and file and comment |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
34 |
# email depends on file |
2036
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
35 |
self.assertEquals(self.config.reorder_cubes(['file', 'email', 'forge']), |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
36 |
('forge', 'email', 'file')) |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
37 |
self.assertEquals(self.config.reorder_cubes(['email', 'file', 'forge']), |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
38 |
('forge', 'email', 'file')) |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
39 |
self.assertEquals(self.config.reorder_cubes(['email', 'forge', 'file']), |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
40 |
('forge', 'email', 'file')) |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
41 |
self.assertEquals(self.config.reorder_cubes(['file', 'forge', 'email']), |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
42 |
('forge', 'email', 'file')) |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
43 |
self.assertEquals(self.config.reorder_cubes(['forge', 'file', 'email']), |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
44 |
('forge', 'email', 'file')) |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
45 |
self.assertEquals(self.config.reorder_cubes(('forge', 'email', 'file')), |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
46 |
('forge', 'email', 'file')) |
1640 | 47 |
|
0 | 48 |
def test_reorder_cubes_recommends(self): |
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
49 |
from cubes.comment import __pkginfo__ as comment_pkginfo |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
50 |
comment_pkginfo.__recommend__ = ('file',) |
0 | 51 |
try: |
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
52 |
# email recommends comment |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
53 |
# comment recommends file |
2036
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
54 |
self.assertEquals(self.config.reorder_cubes(('forge', 'email', 'file', 'comment')), |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
55 |
('forge', 'email', 'comment', 'file')) |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
56 |
self.assertEquals(self.config.reorder_cubes(('forge', 'email', 'comment', 'file')), |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
57 |
('forge', 'email', 'comment', 'file')) |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
58 |
self.assertEquals(self.config.reorder_cubes(('forge', 'comment', 'email', 'file')), |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
59 |
('forge', 'email', 'comment', 'file')) |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
60 |
self.assertEquals(self.config.reorder_cubes(('comment', 'forge', 'email', 'file')), |
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
61 |
('forge', 'email', 'comment', 'file')) |
0 | 62 |
finally: |
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
63 |
comment_pkginfo.__use__ = () |
1640 | 64 |
|
65 |
||
0 | 66 |
# def test_vc_config(self): |
67 |
# vcconf = self.config.vc_config() |
|
68 |
# self.assertIsInstance(vcconf['EEMAIL'], Version) |
|
69 |
# self.assertEquals(vcconf['EEMAIL'], (0, 3, 1)) |
|
70 |
# self.assertEquals(vcconf['CW'], (2, 31, 2)) |
|
71 |
# self.assertRaises(KeyError, vcconf.__getitem__, 'CW_VERSION') |
|
72 |
# self.assertRaises(KeyError, vcconf.__getitem__, 'CRM') |
|
1640 | 73 |
|
0 | 74 |
def test_expand_cubes(self): |
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
75 |
self.assertEquals(self.config.expand_cubes(('email', 'eblog')), |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
76 |
['email', 'eblog', 'file']) |
0 | 77 |
|
78 |
def test_vregistry_path(self): |
|
79 |
self.assertEquals([unabsolutize(p) for p in self.config.vregistry_path()], |
|
80 |
['entities', 'web/views', 'sobjects', |
|
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
81 |
'file/entities.py', 'file/views', 'file/hooks.py', |
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
82 |
'email/entities.py', 'email/views', 'email/hooks.py', |
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
83 |
'test/data/entities.py']) |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
84 |
|
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
85 |
def test_cubes_path(self): |
1023
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
86 |
# make sure we don't import the email cube, but the stdlib email package |
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
87 |
import email |
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
88 |
self.assertNotEquals(dirname(email.__file__), self.config.CUBES_DIR) |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
89 |
os.environ['CW_CUBES_PATH'] = join(dirname(__file__), 'data', 'cubes') |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
90 |
self.assertEquals(self.config.cubes_search_path(), |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
91 |
[abspath(join(dirname(__file__), 'data', 'cubes')), |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
92 |
self.config.CUBES_DIR]) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
93 |
os.environ['CW_CUBES_PATH'] = '%s%s%s%s%s' % (join(dirname(__file__), 'data', 'cubes'), |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
94 |
os.pathsep, self.config.CUBES_DIR, |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
95 |
os.pathsep, 'unexistant') |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
96 |
# filter out unexistant and duplicates |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
97 |
self.assertEquals(self.config.cubes_search_path(), |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
98 |
[abspath(join(dirname(__file__), 'data', 'cubes')), |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
99 |
self.config.CUBES_DIR]) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
100 |
self.failUnless('mycube' in self.config.available_cubes()) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
101 |
# test cubes python path |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
102 |
self.config.adjust_sys_path() |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
103 |
import cubes |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
104 |
self.assertEquals(cubes.__path__, self.config.cubes_search_path()) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
105 |
# this import should succeed once path is adjusted |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
106 |
from cubes import mycube |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
107 |
self.assertEquals(mycube.__path__, [abspath(join(dirname(__file__), 'data', 'cubes', 'mycube'))]) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
108 |
# file cube should be overriden by the one found in data/cubes |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
109 |
sys.modules.pop('cubes.file', None) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
110 |
del cubes.file |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
111 |
from cubes import file |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
112 |
self.assertEquals(file.__path__, [abspath(join(dirname(__file__), 'data', 'cubes', 'file'))]) |
1640 | 113 |
|
114 |
||
0 | 115 |
if __name__ == '__main__': |
116 |
unittest_main() |