test/unittest_cwconfig.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 20 Apr 2010 18:34:37 +0200
changeset 5364 e0feefb87de5
parent 5025 2826f5406201
child 5423 e15abfdcce38
permissions -rw-r--r--
[dbapi] some compat with distant < 3.8 repo
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
4212
ab6573088b4a update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2446
diff changeset
     4
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
1977
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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
     9
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
    10
import tempfile
1015
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    11
from os.path import dirname, join, abspath
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    12
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
    13
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
    14
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
    15
                                    with_tempdir)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    16
from logilab.common.changelog import Version
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    17
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    18
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
    19
from cubicweb.cwconfig import _find_prefix
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    21
def unabsolutize(path):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
    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
    23
    for i, part in reversed(tuple(enumerate(parts))):
1341
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
    24
        if part.startswith('cubicweb') or part == 'cubes':
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    25
            return '/'.join(parts[i+1:])
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    26
    raise Exception('duh? %s' % path)
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    27
4681
5f72584ab1d7 [test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4490
diff changeset
    28
CUSTOM_CUBES_DIR = abspath(join(dirname(__file__), 'data', 'cubes'))
5f72584ab1d7 [test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4490
diff changeset
    29
5f72584ab1d7 [test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4490
diff changeset
    30
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
class CubicWebConfigurationTC(TestCase):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
    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
    33
        cleanup_sys_modules([CUSTOM_CUBES_DIR, ApptestConfiguration.CUBES_DIR])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
        self.config = ApptestConfiguration('data')
13
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    35
        self.config._cubes = ('email', 'file')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
1341
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
    37
    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
    38
        ApptestConfiguration.CUBES_PATH = []
1341
9502d02630bf fix tests
sylvain.thenault@logilab.fr
parents: 1263
diff changeset
    39
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
    def test_reorder_cubes(self):
13
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    41
        # 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
    42
        # email depends on file
2036
68ee0ffb66a7 replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
    43
        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
    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(['email', 'file', 'forge']),
68ee0ffb66a7 replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
    46
                          ('forge', 'email', 'file'))
68ee0ffb66a7 replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
    47
        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
    48
                          ('forge', 'email', 'file'))
68ee0ffb66a7 replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
    49
        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
    50
                          ('forge', 'email', 'file'))
68ee0ffb66a7 replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
    51
        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
    52
                          ('forge', 'email', 'file'))
68ee0ffb66a7 replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
    53
        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
    54
                          ('forge', 'email', 'file'))
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    55
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
    def test_reorder_cubes_recommends(self):
13
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    57
        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
    58
        comment_pkginfo.__recommends_cubes__ = {'file': None}
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
        try:
13
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    60
            # email recommends comment
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    61
            # comment recommends file
2036
68ee0ffb66a7 replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
    62
            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
    63
                              ('forge', 'email', 'comment', 'file'))
68ee0ffb66a7 replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
    64
            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
    65
                              ('forge', 'email', 'comment', 'file'))
68ee0ffb66a7 replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
    66
            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
    67
                              ('forge', 'email', 'comment', 'file'))
68ee0ffb66a7 replace jpl with forge in test
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 1977
diff changeset
    68
            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
    69
                              ('forge', 'email', 'comment', 'file'))
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    70
        finally:
5025
2826f5406201 deprecate __use__ and __recommend__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5021
diff changeset
    71
            comment_pkginfo.__recommends_cubes__ = {}
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    72
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    73
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    74
#     def test_vc_config(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    75
#         vcconf = self.config.vc_config()
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    76
#         self.assertIsInstance(vcconf['EEMAIL'], Version)
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    77
#         self.assertEquals(vcconf['EEMAIL'], (0, 3, 1))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    78
#         self.assertEquals(vcconf['CW'], (2, 31, 2))
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    79
#         self.assertRaises(KeyError, vcconf.__getitem__, 'CW_VERSION')
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    80
#         self.assertRaises(KeyError, vcconf.__getitem__, 'CRM')
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
    81
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    82
    def test_expand_cubes(self):
4490
d45cde54d464 backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    83
        self.assertEquals(self.config.expand_cubes(('email', 'blog')),
d45cde54d464 backport stable branch and some vreg cleanups:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
    84
                          ['email', 'blog', 'file'])
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    85
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    86
    def test_vregistry_path(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    87
        self.assertEquals([unabsolutize(p) for p in self.config.vregistry_path()],
2835
04034421b072 [hooks] major refactoring:
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2446
diff changeset
    88
                          ['entities', 'web/views', 'sobjects', 'hooks',
13
bae30087db21 fix unittests in cubicweb/test
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    89
                           'file/entities.py', 'file/views', 'file/hooks.py',
750
89e997bc2bf1 update test for new test schema
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    90
                           '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
    91
                           '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
    92
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    93
    def test_cubes_path(self):
1023
278f997aa257 fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1015
diff changeset
    94
        # 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
    95
        import email
278f997aa257 fix sys.path adjustment
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 1015
diff changeset
    96
        self.assertNotEquals(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
    97
        self.config.__class__.CUBES_PATH = [CUSTOM_CUBES_DIR]
1015
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
    98
        self.assertEquals(self.config.cubes_search_path(),
4681
5f72584ab1d7 [test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4490
diff changeset
    99
                          [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
   100
        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
   101
                                            self.config.CUBES_DIR, 'unexistant']
1015
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
   102
        # filter out unexistant and duplicates
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
   103
        self.assertEquals(self.config.cubes_search_path(),
4681
5f72584ab1d7 [test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4490
diff changeset
   104
                          [CUSTOM_CUBES_DIR,
1015
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
   105
                           self.config.CUBES_DIR])
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
   106
        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
   107
        # test cubes python path
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
   108
        self.config.adjust_sys_path()
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
   109
        import cubes
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
   110
        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
   111
        # 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
   112
        from cubes import mycube
4681
5f72584ab1d7 [test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4490
diff changeset
   113
        self.assertEquals(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
   114
        # 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
   115
        sys.modules.pop('cubes.file', None)
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
   116
        del cubes.file
b5fdad9208f8 search for cubes in a list of directories
sylvain.thenault@logilab.fr
parents: 515
diff changeset
   117
        from cubes import file
4681
5f72584ab1d7 [test] cleanup
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4490
diff changeset
   118
        self.assertEquals(file.__path__, [join(CUSTOM_CUBES_DIR, 'file')])
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
   119
5021
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   120
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
   121
    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
   122
        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
   123
        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
   124
            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
   125
        return path
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   126
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   127
    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
   128
        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
   129
        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
   130
        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
   131
        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
   132
        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
   133
        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
   134
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   135
    @with_tempdir
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   136
    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
   137
        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
   138
        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
   139
        self.assertEquals(_find_prefix(prefix), prefix)
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   140
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   141
    @with_tempdir
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   142
    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
   143
        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
   144
        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
   145
        file_path = self.make_file('bob.py')
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   146
        self.assertEquals(_find_prefix(file_path), prefix)
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
    @with_tempdir
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   149
    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
   150
        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
   151
        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
   152
        dir_path = 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
   153
        self.assertEquals(_find_prefix(dir_path), prefix)
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   154
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   155
    @with_tempdir
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   156
    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
   157
        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
   158
        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
   159
        file_path = self.make_file('bob', 'toto.py')
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   160
        self.assertEquals(_find_prefix(file_path), prefix)
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_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
   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', 'pyves', 'alain', 'adim', 'syt', 'toto.py')
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   167
        self.assertEquals(_find_prefix(file_path), prefix)
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_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
   171
        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
   172
        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
   173
        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
   174
        file_path = self.make_file('bob', 'pyves', 'alain', 'adim', 'syt', 'toto.py')
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   175
        self.assertEquals(_find_prefix(file_path), prefix)
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   176
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   177
    @with_tempdir
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   178
    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
   179
        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
   180
        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
   181
        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
   182
        file_path = self.make_file('bell', 'toto.py')
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   183
        self.assertEquals(_find_prefix(file_path), prefix)
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   184
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   185
    @with_tempdir
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   186
    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
   187
        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
   188
        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
   189
        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
   190
        file_path = self.make_file('share', 'cubicweb', 'bob', 'pyves', 'alain', 'adim', 'syt', 'toto.py')
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   191
        self.assertEquals(_find_prefix(file_path), prefix)
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   192
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   193
    @with_tempdir
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   194
    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
   195
        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
   196
        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
   197
        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
   198
        file_path = self.make_file('bell', 'toto.py')
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   199
        self.assertEquals(_find_prefix(file_path), prefix)
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   200
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   201
    @with_tempdir
58e89f3dfbae handle nicely typical installation other than debian package / mercurial forest
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4691
diff changeset
   202
    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
   203
        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
   204
        self.assertEquals(_find_prefix(prefix), sys.prefix)
1640
65b60f177eb1 fix tests
sylvain.thenault@logilab.fr
parents: 1341
diff changeset
   205
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   206
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   207
    unittest_main()