Ejemplo n.º 1
0
    def test_mkdtemp(self):
        try:
            tmpdir = mkdtemp()
            self.assertIsInstance(tmpdir, path)
        finally:
            shutil.rmtree(tmpdir)

        # prefix option
        try:
            tmpdir = mkdtemp(prefix='sphinx')
            self.assertTrue(tmpdir.basename().startswith('sphinx'))
        finally:
            tmpdir.rmtree()

        # suffix option
        try:
            tmpdir = mkdtemp(suffix='sphinx')
            self.assertTrue(tmpdir.basename().endswith('sphinx'))
        finally:
            tmpdir.rmtree()

        # dir option
        try:
            parent = mkdtemp()
            tmpdir = mkdtemp(dir=parent)
            self.assertTrue(parent, tmpdir.dirname())
        finally:
            parent.rmtree()
Ejemplo n.º 2
0
    def test_with_app_bad_args(self, _mkdtemp):
        tmpdir = _mkdtemp.return_value = mkdtemp()
        srcdir = path(__file__).dirname() / 'examples'

        @with_app(srcdir=srcdir, copy_srcdir_to_tmpdir=True)
        def execute(oops):
            pass

        with self.assertRaises(TypeError):
            # TypeError: execute() takes 1 positional argument but 3 were given
            execute()

        self.assertFalse(tmpdir.exists())
Ejemplo n.º 3
0
    def __init__(self, srcdir=None, confdir=None, outdir=None, doctreedir=None,
                 buildername='html', confoverrides=None, status=None,
                 warning=None, freshenv=False, warningiserror=False, tags=None,
                 copy_srcdir_to_tmpdir=False, create_new_srcdir=False,
                 cleanup_on_errors=True, verbosity=0, parallel=0):
        self.cleanup_trees = []
        self.cleanup_on_errors = cleanup_on_errors

        if create_new_srcdir:
            assert srcdir is None, 'conflicted: create_new_srcdir, srcdir'
            tmpdir = mkdtemp()
            self.cleanup_trees.append(tmpdir)
            tmproot = tmpdir / 'root'
            tmproot.makedirs()
            (tmproot / 'conf.py').write_text('')
            srcdir = tmproot

        assert srcdir is not None, 'srcdir not found'
        srcdir = path(srcdir).abspath()

        if copy_srcdir_to_tmpdir:
            tmpdir = mkdtemp()
            self.cleanup_trees.append(tmpdir)
            tmproot = tmpdir / srcdir.basename()
            srcdir.copytree(tmproot)
            srcdir = tmproot
            self.builddir = srcdir.joinpath('_build')
        else:
            self.builddir = mkdtemp()
            self.cleanup_trees.append(self.builddir)

        if confdir is None:
            confdir = srcdir
        if outdir is None:
            outdir = self.builddir.joinpath(buildername)
            if not outdir.isdir():
                outdir.makedirs()
        if doctreedir is None:
            doctreedir = self.builddir.joinpath('doctrees')
            if not doctreedir.isdir():
                doctreedir.makedirs()
        if confoverrides is None:
            confoverrides = {}
        if status is None:
            status = StringIO()
        if warning is None:
            warning = StringIO()

        try:
            sphinx.application.abspath = lambda x: x
            if sphinx_version < '1.3':
                Sphinx.__init__(self, srcdir, confdir, outdir, doctreedir,
                                buildername, confoverrides, status,
                                warning, freshenv, warningiserror, tags)
            else:
                Sphinx.__init__(self, srcdir, confdir, outdir, doctreedir,
                                buildername, confoverrides, status,
                                warning, freshenv, warningiserror, tags,
                                verbosity, parallel)
        finally:
            sphinx.application.abspath = os.path.abspath