16 # You should have received a copy of the GNU Lesser General Public License along |
16 # You should have received a copy of the GNU Lesser General Public License along |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 """cubicweb.cwconfig unit tests""" |
18 """cubicweb.cwconfig unit tests""" |
19 |
19 |
20 import contextlib |
20 import contextlib |
21 import compileall |
|
22 import functools |
21 import functools |
23 import sys |
22 import sys |
24 import os |
23 import os |
25 import pkgutil |
24 import pkgutil |
26 from os.path import dirname, join |
25 from os.path import dirname, join |
27 from pkg_resources import EntryPoint, Distribution |
26 from pkg_resources import EntryPoint, Distribution |
|
27 from tempfile import TemporaryDirectory |
28 import unittest |
28 import unittest |
29 |
29 |
30 from mock import patch |
30 from mock import patch |
31 from six import PY3 |
|
32 |
31 |
33 from logilab.common.modutils import cleanup_sys_modules |
32 from logilab.common.modutils import cleanup_sys_modules |
34 |
33 |
35 from cubicweb.devtools import ApptestConfiguration |
34 from cubicweb.devtools import ApptestConfiguration |
36 from cubicweb.devtools.testlib import BaseTestCase, TemporaryDirectory |
35 from cubicweb.devtools.testlib import BaseTestCase |
37 from cubicweb.cwconfig import ( |
36 from cubicweb.cwconfig import ( |
38 CubicWebConfiguration, _expand_modname) |
37 CubicWebConfiguration, _expand_modname) |
39 |
38 |
40 |
39 |
41 def templibdir(func): |
40 def templibdir(func): |
266 for source in ( |
265 for source in ( |
267 join(tempdir, 'c.py'), |
266 join(tempdir, 'c.py'), |
268 join(tempdir, 'b', 'c.py'), |
267 join(tempdir, 'b', 'c.py'), |
269 join(tempdir, 'b', 'd', '__init__.py'), |
268 join(tempdir, 'b', 'd', '__init__.py'), |
270 ): |
269 ): |
271 if not PY3: |
|
272 # ensure pyc file exists. |
|
273 # Doesn't required for PY3 since it create __pycache__ |
|
274 # directory and will not import if source file doesn't |
|
275 # exists. |
|
276 compileall.compile_file(source, force=True) |
|
277 self.assertTrue(os.path.exists(source + 'c')) |
|
278 # remove source file |
270 # remove source file |
279 os.remove(source) |
271 os.remove(source) |
280 self.assertEqual(list(_expand_modname('lib.c')), []) |
272 self.assertEqual(list(_expand_modname('lib.c')), []) |
281 self.assertEqual(list(_expand_modname('lib.b')), [ |
273 self.assertEqual(list(_expand_modname('lib.b')), [ |
282 ('lib.b', join(tempdir, 'b', '__init__.py')), |
274 ('lib.b', join(tempdir, 'b', '__init__.py')), |