author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Mon, 09 Mar 2009 18:52:48 +0100 | |
changeset 1021 | ce8094084165 |
parent 1015 | b5fdad9208f8 |
child 1023 | 278f997aa257 |
permissions | -rw-r--r-- |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
1 |
import sys |
0 | 2 |
import os |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
3 |
from os.path import dirname, join, abspath |
0 | 4 |
from tempfile import mktemp |
5 |
||
6 |
from logilab.common.testlib import TestCase, unittest_main |
|
7 |
from logilab.common.changelog import Version |
|
8 |
||
9 |
from cubicweb.devtools import ApptestConfiguration |
|
10 |
||
11 |
def unabsolutize(path): |
|
12 |
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
|
13 |
for i, part in reversed(tuple(enumerate(parts))): |
0 | 14 |
if part in ('cubicweb', 'cubes', 'cubes'): |
15 |
return '/'.join(parts[i+1:]) |
|
16 |
raise Exception('duh? %s' % path) |
|
17 |
||
18 |
class CubicWebConfigurationTC(TestCase): |
|
19 |
def setUp(self): |
|
20 |
self.config = ApptestConfiguration('data') |
|
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
21 |
self.config._cubes = ('email', 'file') |
0 | 22 |
|
23 |
def test_reorder_cubes(self): |
|
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
24 |
# 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
|
25 |
# email depends on file |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
26 |
self.assertEquals(self.config.reorder_cubes(['file', 'email', 'jpl']), |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
27 |
('jpl', 'email', 'file')) |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
28 |
self.assertEquals(self.config.reorder_cubes(['email', 'file', 'jpl']), |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
29 |
('jpl', 'email', 'file')) |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
30 |
self.assertEquals(self.config.reorder_cubes(['email', 'jpl', 'file']), |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
31 |
('jpl', 'email', 'file')) |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
32 |
self.assertEquals(self.config.reorder_cubes(['file', 'jpl', 'email']), |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
33 |
('jpl', 'email', 'file')) |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
34 |
self.assertEquals(self.config.reorder_cubes(['jpl', 'file', 'email']), |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
35 |
('jpl', 'email', 'file')) |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
36 |
self.assertEquals(self.config.reorder_cubes(('jpl', 'email', 'file')), |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
37 |
('jpl', 'email', 'file')) |
0 | 38 |
|
39 |
def test_reorder_cubes_recommends(self): |
|
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
40 |
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
|
41 |
comment_pkginfo.__recommend__ = ('file',) |
0 | 42 |
try: |
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
43 |
# email recommends comment |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
44 |
# comment recommends file |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
45 |
self.assertEquals(self.config.reorder_cubes(('jpl', 'email', 'file', 'comment')), |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
46 |
('jpl', 'email', 'comment', 'file')) |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
47 |
self.assertEquals(self.config.reorder_cubes(('jpl', 'email', 'comment', 'file')), |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
48 |
('jpl', 'email', 'comment', 'file')) |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
49 |
self.assertEquals(self.config.reorder_cubes(('jpl', 'comment', 'email', 'file')), |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
50 |
('jpl', 'email', 'comment', 'file')) |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
51 |
self.assertEquals(self.config.reorder_cubes(('comment', 'jpl', 'email', 'file')), |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
52 |
('jpl', 'email', 'comment', 'file')) |
0 | 53 |
finally: |
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
54 |
comment_pkginfo.__use__ = () |
0 | 55 |
|
56 |
||
57 |
# def test_vc_config(self): |
|
58 |
# vcconf = self.config.vc_config() |
|
59 |
# self.assertIsInstance(vcconf['EEMAIL'], Version) |
|
60 |
# self.assertEquals(vcconf['EEMAIL'], (0, 3, 1)) |
|
61 |
# self.assertEquals(vcconf['CW'], (2, 31, 2)) |
|
62 |
# self.assertRaises(KeyError, vcconf.__getitem__, 'CW_VERSION') |
|
63 |
# self.assertRaises(KeyError, vcconf.__getitem__, 'CRM') |
|
64 |
||
65 |
def test_expand_cubes(self): |
|
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
66 |
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
|
67 |
['email', 'eblog', 'file']) |
0 | 68 |
|
69 |
def test_vregistry_path(self): |
|
70 |
self.assertEquals([unabsolutize(p) for p in self.config.vregistry_path()], |
|
71 |
['entities', 'web/views', 'sobjects', |
|
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
72 |
'file/entities.py', 'file/views', 'file/hooks.py', |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
73 |
'email/entities.py', 'email/views', 'email/hooks.py']) |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
74 |
|
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
75 |
def test_cubes_path(self): |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
76 |
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
|
77 |
self.assertEquals(self.config.cubes_search_path(), |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
78 |
[abspath(join(dirname(__file__), 'data', 'cubes')), |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
79 |
self.config.CUBES_DIR]) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
80 |
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
|
81 |
os.pathsep, self.config.CUBES_DIR, |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
82 |
os.pathsep, 'unexistant') |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
83 |
# filter out unexistant and duplicates |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
84 |
self.assertEquals(self.config.cubes_search_path(), |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
85 |
[abspath(join(dirname(__file__), 'data', 'cubes')), |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
86 |
self.config.CUBES_DIR]) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
87 |
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
|
88 |
# test cubes python path |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
89 |
self.config.adjust_sys_path() |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
90 |
import cubes |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
91 |
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
|
92 |
# 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
|
93 |
from cubes import mycube |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
94 |
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
|
95 |
# 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
|
96 |
sys.modules.pop('cubes.file', None) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
97 |
del cubes.file |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
98 |
from cubes import file |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
99 |
self.assertEquals(file.__path__, [abspath(join(dirname(__file__), 'data', 'cubes', 'file'))]) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
100 |
|
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
101 |
|
0 | 102 |
if __name__ == '__main__': |
103 |
unittest_main() |