test/unittest_cwconfig.py
branchtls-sprint
changeset 1263 01152fffd593
parent 750 89e997bc2bf1
parent 1023 278f997aa257
child 1341 9502d02630bf
equal deleted inserted replaced
1246:76b3cd5d4f31 1263:01152fffd593
       
     1 import sys
     1 import os
     2 import os
       
     3 from os.path import dirname, join, abspath
     2 from tempfile import mktemp
     4 from tempfile import mktemp
     3 
     5 
     4 from logilab.common.testlib import TestCase, unittest_main
     6 from logilab.common.testlib import TestCase, unittest_main
     5 from logilab.common.changelog import Version
     7 from logilab.common.changelog import Version
     6 
     8 
    68         self.assertEquals([unabsolutize(p) for p in self.config.vregistry_path()],
    70         self.assertEquals([unabsolutize(p) for p in self.config.vregistry_path()],
    69                           ['entities', 'web/views', 'sobjects',
    71                           ['entities', 'web/views', 'sobjects',
    70                            'file/entities.py', 'file/views', 'file/hooks.py',
    72                            'file/entities.py', 'file/views', 'file/hooks.py',
    71                            'email/entities.py', 'email/views', 'email/hooks.py',
    73                            'email/entities.py', 'email/views', 'email/hooks.py',
    72                            'test/data/entities.py'])
    74                            'test/data/entities.py'])
    73             
    75 
       
    76     def test_cubes_path(self):
       
    77         # make sure we don't import the email cube, but the stdlib email package
       
    78         import email
       
    79         self.assertNotEquals(dirname(email.__file__), self.config.CUBES_DIR)
       
    80         os.environ['CW_CUBES_PATH'] = join(dirname(__file__), 'data', 'cubes')
       
    81         self.assertEquals(self.config.cubes_search_path(),
       
    82                           [abspath(join(dirname(__file__), 'data', 'cubes')),
       
    83                            self.config.CUBES_DIR])
       
    84         os.environ['CW_CUBES_PATH'] = '%s%s%s%s%s' % (join(dirname(__file__), 'data', 'cubes'),
       
    85                                                       os.pathsep, self.config.CUBES_DIR,
       
    86                                                       os.pathsep, 'unexistant')
       
    87         # filter out unexistant and duplicates
       
    88         self.assertEquals(self.config.cubes_search_path(),
       
    89                           [abspath(join(dirname(__file__), 'data', 'cubes')),
       
    90                            self.config.CUBES_DIR])
       
    91         self.failUnless('mycube' in self.config.available_cubes())
       
    92         # test cubes python path
       
    93         self.config.adjust_sys_path()
       
    94         import cubes
       
    95         self.assertEquals(cubes.__path__, self.config.cubes_search_path())
       
    96         # this import should succeed once path is adjusted
       
    97         from cubes import mycube
       
    98         self.assertEquals(mycube.__path__, [abspath(join(dirname(__file__), 'data', 'cubes', 'mycube'))])
       
    99         # file cube should be overriden by the one found in data/cubes
       
   100         sys.modules.pop('cubes.file', None)
       
   101         del cubes.file
       
   102         from cubes import file
       
   103         self.assertEquals(file.__path__, [abspath(join(dirname(__file__), 'data', 'cubes', 'file'))])
       
   104                                        
       
   105                           
    74 if __name__ == '__main__':
   106 if __name__ == '__main__':
    75     unittest_main()
   107     unittest_main()