cubicweb/test/unittest_cubes.py
changeset 11912 c9e6df20e5a4
parent 11457 d404fd8499dd
child 11954 e0d708fb20e8
equal deleted inserted replaced
11911:37726f66ff82 11912:c9e6df20e5a4
    18 """Unit tests for "cubes" importer."""
    18 """Unit tests for "cubes" importer."""
    19 
    19 
    20 from contextlib import contextmanager
    20 from contextlib import contextmanager
    21 import os
    21 import os
    22 from os import path
    22 from os import path
    23 import shutil
       
    24 import sys
    23 import sys
    25 import tempfile
       
    26 import unittest
    24 import unittest
    27 
    25 
    28 from six import PY2
    26 from six import PY2
    29 
    27 
    30 from cubicweb import _CubesImporter
    28 from cubicweb import _CubesImporter
    31 from cubicweb.cwconfig import CubicWebConfiguration
    29 from cubicweb.cwconfig import CubicWebConfiguration
       
    30 from cubicweb.devtools.testlib import TemporaryDirectory
    32 
    31 
    33 
    32 
    34 @contextmanager
    33 @contextmanager
    35 def temp_cube():
    34 def temp_cube():
    36     tempdir = tempfile.mkdtemp()
    35     with TemporaryDirectory() as tempdir:
    37     try:
    36         try:
    38         libdir = path.join(tempdir, 'libpython')
    37             libdir = path.join(tempdir, 'libpython')
    39         cubedir = path.join(libdir, 'cubicweb_foo')
    38             cubedir = path.join(libdir, 'cubicweb_foo')
    40         os.makedirs(cubedir)
    39             os.makedirs(cubedir)
    41         with open(path.join(cubedir, '__init__.py'), 'w') as f:
    40             with open(path.join(cubedir, '__init__.py'), 'w') as f:
    42             f.write('"""cubicweb_foo application package"""')
    41                 f.write('"""cubicweb_foo application package"""')
    43         with open(path.join(cubedir, 'bar.py'), 'w') as f:
    42             with open(path.join(cubedir, 'bar.py'), 'w') as f:
    44             f.write('baz = 1')
    43                 f.write('baz = 1')
    45         sys.path.append(libdir)
    44             sys.path.append(libdir)
    46         yield cubedir
    45             yield cubedir
    47     finally:
    46         finally:
    48         shutil.rmtree(tempdir)
    47             sys.path.remove(libdir)
    49         sys.path.remove(libdir)
       
    50 
    48 
    51 
    49 
    52 class CubesImporterTC(unittest.TestCase):
    50 class CubesImporterTC(unittest.TestCase):
    53 
    51 
    54     def setUp(self):
    52     def setUp(self):