cubicweb/test/unittest_cwconfig.py
branch3.25
changeset 12117 49beb974888f
parent 12115 8d0127498a28
child 12118 d7947c3c0eeb
equal deleted inserted replaced
12116:3522b19f35d6 12117:49beb974888f
    91          sys.path[:], sys.meta_path[:]) = old
    91          sys.path[:], sys.meta_path[:]) = old
    92         for module in set(sys.modules) - old_modules:
    92         for module in set(sys.modules) - old_modules:
    93             del sys.modules[module]
    93             del sys.modules[module]
    94 
    94 
    95 
    95 
       
    96 def iter_entry_points(group, name):
       
    97     """Mock pkg_resources.iter_entry_points to yield EntryPoint from
       
    98     packages found in test/data/libpython even though these are not
       
    99     installed.
       
   100     """
       
   101     libpython = CubicWebConfigurationTC.datapath('libpython')
       
   102     prefix = 'cubicweb_'
       
   103     for pkgname in os.listdir(libpython):
       
   104         if not pkgname.startswith(prefix):
       
   105             continue
       
   106         location = join(libpython, pkgname)
       
   107         yield EntryPoint(pkgname[len(prefix):], pkgname,
       
   108                          dist=Distribution(location))
       
   109 
       
   110 
    96 class CubicWebConfigurationTC(BaseTestCase):
   111 class CubicWebConfigurationTC(BaseTestCase):
    97 
   112 
    98     @classmethod
   113     @classmethod
    99     def setUpClass(cls):
   114     def setUpClass(cls):
   100         sys.path.append(cls.datapath('libpython'))
   115         sys.path.append(cls.datapath('libpython'))
   107         self.config = ApptestConfiguration('data', __file__)
   122         self.config = ApptestConfiguration('data', __file__)
   108         self.config._cubes = ('email', 'file')
   123         self.config._cubes = ('email', 'file')
   109 
   124 
   110     def tearDown(self):
   125     def tearDown(self):
   111         ApptestConfiguration.CUBES_PATH = []
   126         ApptestConfiguration.CUBES_PATH = []
   112 
       
   113     def iter_entry_points(group, name):
       
   114         """Mock pkg_resources.iter_entry_points to yield EntryPoint from
       
   115         packages found in test/data/libpython even though these are not
       
   116         installed.
       
   117         """
       
   118         libpython = CubicWebConfigurationTC.datapath('libpython')
       
   119         prefix = 'cubicweb_'
       
   120         for pkgname in os.listdir(libpython):
       
   121             if not pkgname.startswith(prefix):
       
   122                 continue
       
   123             location = join(libpython, pkgname)
       
   124             yield EntryPoint(pkgname[len(prefix):], pkgname,
       
   125                              dist=Distribution(location))
       
   126 
   127 
   127     @patch('pkg_resources.iter_entry_points', side_effect=iter_entry_points)
   128     @patch('pkg_resources.iter_entry_points', side_effect=iter_entry_points)
   128     def test_available_cubes(self, mock_iter_entry_points):
   129     def test_available_cubes(self, mock_iter_entry_points):
   129         expected_cubes = [
   130         expected_cubes = [
   130             'card', 'comment', 'cubicweb_comment', 'cubicweb_email', 'file',
   131             'card', 'comment', 'cubicweb_comment', 'cubicweb_email', 'file',