author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 25 Mar 2015 07:57:38 +0100 | |
changeset 10285 | d14db30b90d6 |
parent 9674 | 96549de9dd70 |
child 10239 | 495efb844048 |
permissions | -rw-r--r-- |
8537
e30d0a7f0087
[config] turn internal configuration methods building appobjects search path into normal method rather than class method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
1 |
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
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:
4691
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
6314
b233cc448bdd
[test] add some fake cubes necessary for test so we don't depend on the actual forge cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
18 |
"""cubicweb.cwconfig unit tests""" |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1640
diff
changeset
|
19 |
|
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
20 |
import sys |
0 | 21 |
import os |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
22 |
import tempfile |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
23 |
from os.path import dirname, join, abspath |
0 | 24 |
|
4691
ae468fae9965
[test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4681
diff
changeset
|
25 |
from logilab.common.modutils import cleanup_sys_modules |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
26 |
from logilab.common.testlib import (TestCase, unittest_main, |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
27 |
with_tempdir) |
0 | 28 |
from logilab.common.changelog import Version |
29 |
||
30 |
from cubicweb.devtools import ApptestConfiguration |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
31 |
from cubicweb.cwconfig import _find_prefix |
0 | 32 |
|
33 |
def unabsolutize(path): |
|
34 |
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
|
35 |
for i, part in reversed(tuple(enumerate(parts))): |
1341 | 36 |
if part.startswith('cubicweb') or part == 'cubes': |
0 | 37 |
return '/'.join(parts[i+1:]) |
38 |
raise Exception('duh? %s' % path) |
|
1640 | 39 |
|
4681
5f72584ab1d7
[test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4490
diff
changeset
|
40 |
CUSTOM_CUBES_DIR = abspath(join(dirname(__file__), 'data', 'cubes')) |
5f72584ab1d7
[test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4490
diff
changeset
|
41 |
|
5f72584ab1d7
[test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4490
diff
changeset
|
42 |
|
0 | 43 |
class CubicWebConfigurationTC(TestCase): |
44 |
def setUp(self): |
|
4691
ae468fae9965
[test] fix test inter-dependancies pb. Pytest ok in each individual test dir, though not yet for whole cubicweb, but for different reasons
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4681
diff
changeset
|
45 |
cleanup_sys_modules([CUSTOM_CUBES_DIR, ApptestConfiguration.CUBES_DIR]) |
6631
26c303c3f1aa
[test] make test independant from the working directory
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6412
diff
changeset
|
46 |
self.config = ApptestConfiguration('data', apphome=self.datadir) |
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
47 |
self.config._cubes = ('email', 'file') |
0 | 48 |
|
1341 | 49 |
def tearDown(self): |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
50 |
ApptestConfiguration.CUBES_PATH = [] |
1341 | 51 |
|
0 | 52 |
def test_reorder_cubes(self): |
6314
b233cc448bdd
[test] add some fake cubes necessary for test so we don't depend on the actual forge cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
53 |
self.config.__class__.CUBES_PATH = [CUSTOM_CUBES_DIR] |
b233cc448bdd
[test] add some fake cubes necessary for test so we don't depend on the actual forge cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
54 |
self.config.adjust_sys_path() |
b233cc448bdd
[test] add some fake cubes necessary for test so we don't depend on the actual forge cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
55 |
# forge depends on email and file and comment |
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
56 |
# email depends on file |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
57 |
self.assertEqual(self.config.reorder_cubes(['file', 'email', 'forge']), |
2036
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
58 |
('forge', 'email', 'file')) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
59 |
self.assertEqual(self.config.reorder_cubes(['email', 'file', 'forge']), |
2036
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
60 |
('forge', 'email', 'file')) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
61 |
self.assertEqual(self.config.reorder_cubes(['email', 'forge', 'file']), |
2036
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
62 |
('forge', 'email', 'file')) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
63 |
self.assertEqual(self.config.reorder_cubes(['file', 'forge', 'email']), |
2036
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
64 |
('forge', 'email', 'file')) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
65 |
self.assertEqual(self.config.reorder_cubes(['forge', 'file', 'email']), |
2036
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
66 |
('forge', 'email', 'file')) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
67 |
self.assertEqual(self.config.reorder_cubes(('forge', 'email', 'file')), |
2036
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
68 |
('forge', 'email', 'file')) |
1640 | 69 |
|
0 | 70 |
def test_reorder_cubes_recommends(self): |
6314
b233cc448bdd
[test] add some fake cubes necessary for test so we don't depend on the actual forge cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
71 |
self.config.__class__.CUBES_PATH = [CUSTOM_CUBES_DIR] |
b233cc448bdd
[test] add some fake cubes necessary for test so we don't depend on the actual forge cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
72 |
self.config.adjust_sys_path() |
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
73 |
from cubes.comment import __pkginfo__ as comment_pkginfo |
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
74 |
comment_pkginfo.__recommends_cubes__ = {'file': None} |
0 | 75 |
try: |
13
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
76 |
# email recommends comment |
bae30087db21
fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
0
diff
changeset
|
77 |
# comment recommends file |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
78 |
self.assertEqual(self.config.reorder_cubes(('forge', 'email', 'file', 'comment')), |
2036
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
79 |
('forge', 'email', 'comment', 'file')) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
80 |
self.assertEqual(self.config.reorder_cubes(('forge', 'email', 'comment', 'file')), |
2036
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
81 |
('forge', 'email', 'comment', 'file')) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
82 |
self.assertEqual(self.config.reorder_cubes(('forge', 'comment', 'email', 'file')), |
2036
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
83 |
('forge', 'email', 'comment', 'file')) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
84 |
self.assertEqual(self.config.reorder_cubes(('comment', 'forge', 'email', 'file')), |
2036
68ee0ffb66a7
replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
1977
diff
changeset
|
85 |
('forge', 'email', 'comment', 'file')) |
0 | 86 |
finally: |
5025
2826f5406201
deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5021
diff
changeset
|
87 |
comment_pkginfo.__recommends_cubes__ = {} |
1640 | 88 |
|
89 |
||
0 | 90 |
# def test_vc_config(self): |
91 |
# vcconf = self.config.vc_config() |
|
92 |
# self.assertIsInstance(vcconf['EEMAIL'], Version) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
93 |
# self.assertEqual(vcconf['EEMAIL'], (0, 3, 1)) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
94 |
# self.assertEqual(vcconf['CW'], (2, 31, 2)) |
0 | 95 |
# self.assertRaises(KeyError, vcconf.__getitem__, 'CW_VERSION') |
96 |
# self.assertRaises(KeyError, vcconf.__getitem__, 'CRM') |
|
1640 | 97 |
|
0 | 98 |
def test_expand_cubes(self): |
6349
14ec625b3f55
fix test so that we don't actually depends on file and email cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
99 |
self.config.__class__.CUBES_PATH = [CUSTOM_CUBES_DIR] |
14ec625b3f55
fix test so that we don't actually depends on file and email cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
100 |
self.config.adjust_sys_path() |
6411
308f6d0e11ae
[test] don't add unnecessary dependency to blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6349
diff
changeset
|
101 |
self.assertEqual(self.config.expand_cubes(('email', 'comment')), |
308f6d0e11ae
[test] don't add unnecessary dependency to blog
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6349
diff
changeset
|
102 |
['email', 'comment', 'file']) |
0 | 103 |
|
8537
e30d0a7f0087
[config] turn internal configuration methods building appobjects search path into normal method rather than class method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
104 |
def test_appobjects_path(self): |
6349
14ec625b3f55
fix test so that we don't actually depends on file and email cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
105 |
self.config.__class__.CUBES_PATH = [CUSTOM_CUBES_DIR] |
14ec625b3f55
fix test so that we don't actually depends on file and email cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
106 |
self.config.adjust_sys_path() |
8537
e30d0a7f0087
[config] turn internal configuration methods building appobjects search path into normal method rather than class method
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
107 |
self.assertEqual([unabsolutize(p) for p in self.config.appobjects_path()], |
2835
04034421b072
[hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2446
diff
changeset
|
108 |
['entities', 'web/views', 'sobjects', 'hooks', |
6349
14ec625b3f55
fix test so that we don't actually depends on file and email cubes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6340
diff
changeset
|
109 |
'file/entities', 'file/views.py', 'file/hooks', |
750
89e997bc2bf1
update test for new test schema
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
110 |
'email/entities.py', 'email/views', 'email/hooks.py', |
4490
d45cde54d464
backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
111 |
'test/data/entities.py', 'test/data/views.py']) |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
112 |
|
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
113 |
def test_cubes_path(self): |
1023
278f997aa257
fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1015
diff
changeset
|
114 |
# 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
|
115 |
import email |
6412
370357e68837
[test] cleanup / unittest2 api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6411
diff
changeset
|
116 |
self.assertNotEqual(dirname(email.__file__), self.config.CUBES_DIR) |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
117 |
self.config.__class__.CUBES_PATH = [CUSTOM_CUBES_DIR] |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
118 |
self.assertEqual(self.config.cubes_search_path(), |
4681
5f72584ab1d7
[test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4490
diff
changeset
|
119 |
[CUSTOM_CUBES_DIR, self.config.CUBES_DIR]) |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
120 |
self.config.__class__.CUBES_PATH = [CUSTOM_CUBES_DIR, |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
121 |
self.config.CUBES_DIR, 'unexistant'] |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
122 |
# filter out unexistant and duplicates |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
123 |
self.assertEqual(self.config.cubes_search_path(), |
4681
5f72584ab1d7
[test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4490
diff
changeset
|
124 |
[CUSTOM_CUBES_DIR, |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
125 |
self.config.CUBES_DIR]) |
9674
96549de9dd70
[test] use assertIn where appropriate
Julien Cristau <julien.cristau@logilab.fr>
parents:
8537
diff
changeset
|
126 |
self.assertIn('mycube', self.config.available_cubes()) |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
127 |
# test cubes python path |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
128 |
self.config.adjust_sys_path() |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
129 |
import cubes |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
130 |
self.assertEqual(cubes.__path__, self.config.cubes_search_path()) |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
131 |
# 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
|
132 |
from cubes import mycube |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
133 |
self.assertEqual(mycube.__path__, [join(CUSTOM_CUBES_DIR, 'mycube')]) |
1015
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
134 |
# 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
|
135 |
sys.modules.pop('cubes.file', None) |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
136 |
del cubes.file |
b5fdad9208f8
search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents:
515
diff
changeset
|
137 |
from cubes import file |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
138 |
self.assertEqual(file.__path__, [join(CUSTOM_CUBES_DIR, 'file')]) |
1640 | 139 |
|
6314
b233cc448bdd
[test] add some fake cubes necessary for test so we don't depend on the actual forge cube
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
140 |
|
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
141 |
class FindPrefixTC(TestCase): |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
142 |
def make_dirs(self, *args): |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
143 |
path = join(tempfile.tempdir, *args) |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
144 |
if not os.path.exists(path): |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
145 |
os.makedirs(path) |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
146 |
return path |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
147 |
|
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
148 |
def make_file(self, *args): |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
149 |
self.make_dirs(*args[: -1]) |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
150 |
file_path = join(tempfile.tempdir, *args) |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
151 |
file_obj = open(file_path, 'w') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
152 |
file_obj.write('""" None """') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
153 |
file_obj.close() |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
154 |
return file_path |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
155 |
|
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
156 |
@with_tempdir |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
157 |
def test_samedir(self): |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
158 |
prefix = tempfile.tempdir |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
159 |
self.make_dirs('share', 'cubicweb') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
160 |
self.assertEqual(_find_prefix(prefix), prefix) |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
161 |
|
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
162 |
@with_tempdir |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
163 |
def test_samedir_filepath(self): |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
164 |
prefix = tempfile.tempdir |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
165 |
self.make_dirs('share', 'cubicweb') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
166 |
file_path = self.make_file('bob.py') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
167 |
self.assertEqual(_find_prefix(file_path), prefix) |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
168 |
|
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
169 |
@with_tempdir |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
170 |
def test_dir_inside_prefix(self): |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
171 |
prefix = tempfile.tempdir |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
172 |
self.make_dirs('share', 'cubicweb') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
173 |
dir_path = self.make_dirs('bob') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
174 |
self.assertEqual(_find_prefix(dir_path), prefix) |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
175 |
|
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
176 |
@with_tempdir |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
177 |
def test_file_in_dir_inside_prefix(self): |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
178 |
prefix = tempfile.tempdir |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
179 |
self.make_dirs('share', 'cubicweb') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
180 |
file_path = self.make_file('bob', 'toto.py') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
181 |
self.assertEqual(_find_prefix(file_path), prefix) |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
182 |
|
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
183 |
@with_tempdir |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
184 |
def test_file_in_deeper_dir_inside_prefix(self): |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
185 |
prefix = tempfile.tempdir |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
186 |
self.make_dirs('share', 'cubicweb') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
187 |
file_path = self.make_file('bob', 'pyves', 'alain', 'adim', 'syt', 'toto.py') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
188 |
self.assertEqual(_find_prefix(file_path), prefix) |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
189 |
|
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
190 |
@with_tempdir |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
191 |
def test_multiple_candidate_prefix(self): |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
192 |
self.make_dirs('share', 'cubicweb') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
193 |
prefix = self.make_dirs('bob') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
194 |
self.make_dirs('bob', 'share', 'cubicweb') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
195 |
file_path = self.make_file('bob', 'pyves', 'alain', 'adim', 'syt', 'toto.py') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
196 |
self.assertEqual(_find_prefix(file_path), prefix) |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
197 |
|
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
198 |
@with_tempdir |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
199 |
def test_sister_candidate_prefix(self): |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
200 |
prefix = tempfile.tempdir |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
201 |
self.make_dirs('share', 'cubicweb') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
202 |
self.make_dirs('bob', 'share', 'cubicweb') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
203 |
file_path = self.make_file('bell', 'toto.py') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
204 |
self.assertEqual(_find_prefix(file_path), prefix) |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
205 |
|
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
206 |
@with_tempdir |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
207 |
def test_multiple_parent_candidate_prefix(self): |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
208 |
self.make_dirs('share', 'cubicweb') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
209 |
prefix = self.make_dirs('share', 'cubicweb', 'bob') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
210 |
self.make_dirs('share', 'cubicweb', 'bob', 'share', 'cubicweb') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
211 |
file_path = self.make_file('share', 'cubicweb', 'bob', 'pyves', 'alain', 'adim', 'syt', 'toto.py') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
212 |
self.assertEqual(_find_prefix(file_path), prefix) |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
213 |
|
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
214 |
@with_tempdir |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
215 |
def test_upper_candidate_prefix(self): |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
216 |
prefix = tempfile.tempdir |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
217 |
self.make_dirs('share', 'cubicweb') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
218 |
self.make_dirs('bell','bob', 'share', 'cubicweb') |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
219 |
file_path = self.make_file('bell', 'toto.py') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
220 |
self.assertEqual(_find_prefix(file_path), prefix) |
5021
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
221 |
|
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
222 |
@with_tempdir |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
223 |
def test_no_prefix(self): |
58e89f3dfbae
handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4691
diff
changeset
|
224 |
prefix = tempfile.tempdir |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6314
diff
changeset
|
225 |
self.assertEqual(_find_prefix(prefix), sys.prefix) |
1640 | 226 |
|
0 | 227 |
if __name__ == '__main__': |
228 |
unittest_main() |