summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-08-23 15:04:45 +0000
committerGeorg Brandl <georg@python.org>2008-08-23 15:04:45 +0000
commitf0605a40a40dbd58b929d5535a1a6e04a3ed9c82 (patch)
tree211c722ee0079311e599b3b665a778f15c84bf09 /tests
parent5f0c30ac90c107b69f180bb94dfa2e6bdad5003e (diff)
downloadsphinx-git-f0605a40a40dbd58b929d5535a1a6e04a3ed9c82.tar.gz
Merged revisions 65640,65675,65699,65701 via svnmerge from
svn+ssh://pythondev@svn.python.org/doctools/branches/0.4.x ........ r65640 | georg.brandl | 2008-08-11 16:11:17 +0200 (Mon, 11 Aug 2008) | 2 lines More info in intro. ........ r65675 | georg.brandl | 2008-08-14 13:53:02 +0200 (Thu, 14 Aug 2008) | 2 lines #3546: add missing linebreak. ........ r65699 | benjamin.peterson | 2008-08-15 23:02:22 +0200 (Fri, 15 Aug 2008) | 4 lines rename util.with_testapp to util.with_app; nose was running it also make an assert more informative ........ r65701 | benjamin.peterson | 2008-08-16 00:00:54 +0200 (Sat, 16 Aug 2008) | 1 line add some tests for sphinx.application ........
Diffstat (limited to 'tests')
-rw-r--r--tests/test_application.py59
-rw-r--r--tests/test_build.py10
-rw-r--r--tests/test_config.py4
-rw-r--r--tests/test_i18n.py2
-rw-r--r--tests/util.py6
5 files changed, 70 insertions, 11 deletions
diff --git a/tests/test_application.py b/tests/test_application.py
new file mode 100644
index 000000000..e00e990f6
--- /dev/null
+++ b/tests/test_application.py
@@ -0,0 +1,59 @@
+# -*- coding: utf-8 -*-
+"""
+ test_application
+ ~~~~~~~~~~~~~~~~
+
+ Test the Sphinx class.
+
+ :copyright: 2008 by Benjamin Peterson.
+ :license: BSD.
+"""
+
+from StringIO import StringIO
+
+from sphinx.application import ExtensionError
+
+from util import *
+
+
+@with_app()
+def test_events(app):
+ def empty(): pass
+ raises_msg(ExtensionError, "Unknown event name: invalid",
+ app.connect, "invalid", empty)
+
+
+ app.add_event("my_event")
+ raises_msg(ExtensionError, "Event 'my_event' already present",
+ app.add_event, "my_event")
+
+ def mock_callback(a_app, *args):
+ assert a_app is app
+ assert emit_args == args
+ return "ret"
+ emit_args = (1, 3, "string")
+ listener_id = app.connect("my_event", mock_callback)
+ assert app.emit("my_event", *emit_args) == ["ret"], "Callback not called"
+
+ app.disconnect(listener_id)
+ assert app.emit("my_event", *emit_args) == [], \
+ "Callback called when disconnected"
+
+
+def test_output():
+ status, warnings = StringIO(), StringIO()
+ app = TestApp(status=status, warning=warnings)
+ try:
+ status.truncate(0) # __init__ writes to status
+ app.info("Nothing here...")
+ assert status.getvalue() == "Nothing here...\n"
+ status.truncate(0)
+ app.info("Nothing here...", True)
+ assert status.getvalue() == "Nothing here..."
+
+ old_count = app._warncount
+ app.warn("Bad news!")
+ assert warnings.getvalue() == "WARNING: Bad news!\n"
+ assert app._warncount == old_count + 1
+ finally:
+ app.cleanup()
diff --git a/tests/test_build.py b/tests/test_build.py
index 234c1d5b7..e15119681 100644
--- a/tests/test_build.py
+++ b/tests/test_build.py
@@ -65,7 +65,7 @@ class NslessParser(ET.XMLParser):
return name
-@with_testapp(buildername='html', warning=html_warnfile)
+@with_app(buildername='html', warning=html_warnfile)
def test_html(app):
app.builder.build_all()
html_warnings = html_warnfile.getvalue().replace(os.sep, '/')
@@ -94,7 +94,7 @@ def test_html(app):
'path %s in %s' % (text, path, fname))
-@with_testapp(buildername='latex', warning=latex_warnfile)
+@with_app(buildername='latex', warning=latex_warnfile)
def test_latex(app):
LaTeXTranslator.ignore_missing_images = True
app.builder.build_all()
@@ -124,14 +124,14 @@ def test_latex(app):
# just let the remaining ones run for now
-@with_testapp(buildername='linkcheck')
+@with_app(buildername='linkcheck')
def test_linkcheck(app):
app.builder.build_all()
-@with_testapp(buildername='text')
+@with_app(buildername='text')
def test_text(app):
app.builder.build_all()
-@with_testapp(buildername='changes', cleanenv=True)
+@with_app(buildername='changes', cleanenv=True)
def test_changes(app):
app.builder.build_all()
diff --git a/tests/test_config.py b/tests/test_config.py
index 4e05c77d1..3b9ea6920 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -15,7 +15,7 @@ from util import *
from sphinx.application import ExtensionError
-@with_testapp(confoverrides={'master_doc': 'master', 'nonexisting_value': 'True'})
+@with_app(confoverrides={'master_doc': 'master', 'nonexisting_value': 'True'})
def test_core_config(app):
cfg = app.config
@@ -61,7 +61,7 @@ def test_core_config(app):
assert cfg['project'] == cfg.project == 'Sphinx Tests'
-@with_testapp()
+@with_app()
def test_extension_values(app):
cfg = app.config
diff --git a/tests/test_i18n.py b/tests/test_i18n.py
index 2e214ad87..da0af246d 100644
--- a/tests/test_i18n.py
+++ b/tests/test_i18n.py
@@ -12,6 +12,6 @@
from util import *
-@with_testapp(confoverrides={'language': 'de'})
+@with_app(confoverrides={'language': 'de'})
def test_i18n(app):
app.builder.build_all()
diff --git a/tests/util.py b/tests/util.py
index f2eb3fd58..fffdcce19 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -25,7 +25,7 @@ from nose import tools
__all__ = [
'test_root',
'raises', 'raises_msg', 'Struct',
- 'ListOutput', 'TestApp', 'with_testapp',
+ 'ListOutput', 'TestApp', 'with_app',
'path', 'with_tempdir', 'write_file',
'sprint',
]
@@ -60,7 +60,7 @@ def raises_msg(exc, msg, func, *args, **kwds):
try:
func(*args, **kwds)
except exc, err:
- assert msg in str(err)
+ assert msg in str(err), "\"%s\" not in \"%s\"" % (msg, err)
else:
raise AssertionError('%s did not raise %s' %
(func.__name__, _excstr(exc)))
@@ -140,7 +140,7 @@ class TestApp(application.Sphinx):
shutil.rmtree(tree, True)
-def with_testapp(*args, **kwargs):
+def with_app(*args, **kwargs):
"""
Make a TestApp with args and kwargs, pass it to the test and clean up
properly.