mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
* provide _copy_to_temp option for TestApp()
This commit is contained in:
parent
14353b30c2
commit
ed9de1c9e8
@ -36,6 +36,9 @@ class path(text_type):
|
||||
"""
|
||||
return self.__class__(os.path.dirname(self))
|
||||
|
||||
def basename(self):
|
||||
return os.path.basename(self)
|
||||
|
||||
def abspath(self):
|
||||
"""
|
||||
Returns the absolute path.
|
||||
|
@ -76,6 +76,6 @@ def test_nonascii_path():
|
||||
builder_names.append('man')
|
||||
|
||||
for buildername in builder_names:
|
||||
app = TestApp(buildername=buildername, srcdir='(temp)')
|
||||
app = TestApp(buildername=buildername, _copy_to_temp=True)
|
||||
yield _test_nonascii_path, app
|
||||
app.cleanup()
|
||||
|
@ -20,7 +20,7 @@ warnings = []
|
||||
|
||||
def setup_module():
|
||||
global app, env
|
||||
app = TestApp(srcdir='(temp)', freshenv=True)
|
||||
app = TestApp(freshenv=True, _copy_to_temp=True)
|
||||
env = app.env
|
||||
env.set_warnfunc(lambda *args: warnings.append(args))
|
||||
|
||||
|
@ -13,7 +13,7 @@ import os
|
||||
from util import with_app
|
||||
|
||||
|
||||
@with_app(srcdir='(temp)', buildername='html', tags=['test_linkcode'])
|
||||
@with_app(buildername='html', tags=['test_linkcode'], _copy_to_temp=True)
|
||||
def test_html(app):
|
||||
app.builder.build_all()
|
||||
|
||||
|
@ -23,7 +23,7 @@ warnings = []
|
||||
def setup_module():
|
||||
# Is there a better way of generating this doctree than manually iterating?
|
||||
global app, env
|
||||
app = TestApp(srcdir='(temp)')
|
||||
app = TestApp(_copy_to_temp=True)
|
||||
env = app.env
|
||||
msg, num, it = env.update(app.config, app.srcdir, app.doctreedir, app)
|
||||
for docname in it:
|
||||
|
@ -130,7 +130,9 @@ class TestApp(application.Sphinx):
|
||||
buildername='html', confoverrides=None,
|
||||
status=None, warning=None, freshenv=None,
|
||||
warningiserror=None, tags=None,
|
||||
confname='conf.py', cleanenv=False):
|
||||
confname='conf.py', cleanenv=False,
|
||||
_copy_to_temp=False,
|
||||
):
|
||||
|
||||
application.CONFIG_FILENAME = confname
|
||||
|
||||
@ -138,12 +140,6 @@ class TestApp(application.Sphinx):
|
||||
|
||||
if srcdir is None:
|
||||
srcdir = test_root
|
||||
if srcdir == '(temp)':
|
||||
tempdir = path(tempfile.mkdtemp())
|
||||
self.cleanup_trees.append(tempdir)
|
||||
temproot = tempdir / 'root'
|
||||
test_root.copytree(temproot)
|
||||
srcdir = temproot
|
||||
elif srcdir == '(empty)':
|
||||
tempdir = path(tempfile.mkdtemp())
|
||||
self.cleanup_trees.append(tempdir)
|
||||
@ -153,6 +149,14 @@ class TestApp(application.Sphinx):
|
||||
srcdir = temproot
|
||||
else:
|
||||
srcdir = path(srcdir)
|
||||
|
||||
if _copy_to_temp:
|
||||
tempdir = path(tempfile.mkdtemp())
|
||||
self.cleanup_trees.append(tempdir)
|
||||
temproot = tempdir / srcdir.basename()
|
||||
srcdir.copytree(temproot)
|
||||
srcdir = temproot
|
||||
|
||||
self.builddir = srcdir.joinpath('_build')
|
||||
if confdir is None:
|
||||
confdir = srcdir
|
||||
|
Loading…
Reference in New Issue
Block a user