summaryrefslogtreecommitdiff
path: root/tests/test_env.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_env.py')
-rw-r--r--tests/test_env.py55
1 files changed, 31 insertions, 24 deletions
diff --git a/tests/test_env.py b/tests/test_env.py
index 390c6999..a06656d6 100644
--- a/tests/test_env.py
+++ b/tests/test_env.py
@@ -12,7 +12,8 @@
from util import *
from sphinx.environment import BuildEnvironment
-from sphinx.builder import StandaloneHTMLBuilder, LaTeXBuilder
+from sphinx.builders.html import StandaloneHTMLBuilder
+from sphinx.builders.latex import LaTeXBuilder
app = env = None
warnings = []
@@ -21,14 +22,14 @@ def setup_module():
global app, env
app = TestApp(srcdir='(temp)')
env = BuildEnvironment(app.srcdir, app.doctreedir, app.config)
- env.set_warnfunc(warnings.append)
+ env.set_warnfunc(lambda *args: warnings.append(args))
def teardown_module():
app.cleanup()
def warning_emitted(file, text):
for warning in warnings:
- if file+':' in warning and text in warning:
+ if len(warning) == 2 and file+':' in warning[1] and text in warning[0]:
return True
return False
@@ -36,8 +37,7 @@ def warning_emitted(file, text):
# afford to not run update() in the setup but in its own test
def test_first_update():
- it = env.update(app.config, app.srcdir, app.doctreedir, app)
- msg = it.next()
+ msg, num, it = env.update(app.config, app.srcdir, app.doctreedir, app)
assert msg.endswith('%d added, 0 changed, 0 removed' % len(env.found_docs))
docnames = set()
for docname in it: # the generator does all the work
@@ -45,44 +45,51 @@ def test_first_update():
assert docnames == env.found_docs == set(env.all_docs)
def test_images():
- assert warning_emitted('images.txt', 'Image file not readable: foo.png')
- assert warning_emitted('images.txt', 'Nonlocal image URI found: '
+ assert warning_emitted('images.txt', 'image file not readable: foo.png')
+ assert warning_emitted('images.txt', 'nonlocal image URI found: '
'http://www.python.org/logo.png')
tree = env.get_doctree('images')
app._warning.reset()
htmlbuilder = StandaloneHTMLBuilder(app, env)
htmlbuilder.post_process_images(tree)
- assert "no matching candidate for image URI u'foo.*'" in app._warning.content[-1]
- assert set(htmlbuilder.images.keys()) == set(['subdir/img.png', 'img.png',
- 'subdir/simg.png'])
- assert set(htmlbuilder.images.values()) == set(['img.png', 'img1.png',
- 'simg.png'])
+ assert "no matching candidate for image URI u'foo.*'" in \
+ app._warning.content[-1]
+ assert set(htmlbuilder.images.keys()) == \
+ set(['subdir/img.png', 'img.png', 'subdir/simg.png', 'svgimg.svg'])
+ assert set(htmlbuilder.images.values()) == \
+ set(['img.png', 'img1.png', 'simg.png', 'svgimg.svg'])
app._warning.reset()
latexbuilder = LaTeXBuilder(app, env)
latexbuilder.post_process_images(tree)
- assert "no matching candidate for image URI u'foo.*'" in app._warning.content[-1]
- assert set(latexbuilder.images.keys()) == set(['subdir/img.png', 'subdir/simg.png',
- 'img.png', 'img.pdf'])
- assert set(latexbuilder.images.values()) == set(['img.pdf', 'img.png',
- 'img1.png', 'simg.png'])
+ assert "no matching candidate for image URI u'foo.*'" in \
+ app._warning.content[-1]
+ assert set(latexbuilder.images.keys()) == \
+ set(['subdir/img.png', 'subdir/simg.png', 'img.png', 'img.pdf',
+ 'svgimg.pdf'])
+ assert set(latexbuilder.images.values()) == \
+ set(['img.pdf', 'img.png', 'img1.png', 'simg.png', 'svgimg.pdf'])
def test_second_update():
# delete, add and "edit" (change saved mtime) some files and update again
env.all_docs['contents'] = 0
root = path(app.srcdir)
- (root / 'images.txt').unlink()
+ # important: using "autodoc" because it is the last one to be included in
+ # the contents.txt toctree; otherwise section numbers would shift
+ (root / 'autodoc.txt').unlink()
(root / 'new.txt').write_text('New file\n========\n')
- it = env.update(app.config, app.srcdir, app.doctreedir, app)
- msg = it.next()
- assert '1 added, 1 changed, 1 removed' in msg
+ msg, num, it = env.update(app.config, app.srcdir, app.doctreedir, app)
+ assert '1 added, 3 changed, 1 removed' in msg
docnames = set()
for docname in it:
docnames.add(docname)
- assert docnames == set(['contents', 'new'])
- assert 'images' not in env.all_docs
- assert 'images' not in env.found_docs
+ # "includes" and "images" are in there because they contain references
+ # to nonexisting downloadable or image files, which are given another
+ # chance to exist
+ assert docnames == set(['contents', 'new', 'includes', 'images'])
+ assert 'autodoc' not in env.all_docs
+ assert 'autodoc' not in env.found_docs
def test_object_inventory():
refs = env.descrefs