diff options
Diffstat (limited to 'tests/test_application.py')
-rw-r--r-- | tests/test_application.py | 91 |
1 files changed, 41 insertions, 50 deletions
diff --git a/tests/test_application.py b/tests/test_application.py index 3d464eb5..1f188de1 100644 --- a/tests/test_application.py +++ b/tests/test_application.py @@ -9,22 +9,21 @@ :license: BSD, see LICENSE for details. """ -from StringIO import StringIO - from docutils import nodes + from sphinx.application import ExtensionError from sphinx.domains import Domain -from util import with_app, raises_msg, TestApp +from util import with_app, raises_msg @with_app() -def test_events(app): - def empty(): pass +def test_events(app, status, warning): + 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") @@ -43,57 +42,49 @@ def test_events(app): @with_app() -def test_emit_with_nonascii_name_node(app): +def test_emit_with_nonascii_name_node(app, status, warning): node = nodes.section(names=[u'\u65e5\u672c\u8a9e']) app.emit('my_event', node) -def test_output(): - status, warnings = StringIO(), StringIO() - app = TestApp(status=status, warning=warnings) - try: - status.truncate(0) # __init__ writes to status - status.seek(0) - app.info("Nothing here...") - assert status.getvalue() == "Nothing here...\n" - status.truncate(0) - status.seek(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() - - -def test_extensions(): - status, warnings = StringIO(), StringIO() - app = TestApp(status=status, warning=warnings) - try: - app.setup_extension('shutil') - assert warnings.getvalue().startswith("WARNING: extension 'shutil'") - finally: - app.cleanup() - -def test_domain_override(): +@with_app() +def test_output(app, status, warning): + status.truncate(0) # __init__ writes to status + status.seek(0) + app.info("Nothing here...") + assert status.getvalue() == "Nothing here...\n" + status.truncate(0) + status.seek(0) + app.info("Nothing here...", True) + assert status.getvalue() == "Nothing here..." + + old_count = app._warncount + app.warn("Bad news!") + assert warning.getvalue() == "WARNING: Bad news!\n" + assert app._warncount == old_count + 1 + + +@with_app() +def test_extensions(app, status, warning): + app.setup_extension('shutil') + assert warning.getvalue().startswith("WARNING: extension 'shutil'") + + +@with_app() +def test_domain_override(app, status, warning): class A(Domain): name = 'foo' + class B(A): name = 'foo' + class C(Domain): name = 'foo' - status, warnings = StringIO(), StringIO() - app = TestApp(status=status, warning=warnings) - try: - # No domain know named foo. - raises_msg(ExtensionError, 'domain foo not yet registered', - app.override_domain, A) - assert app.add_domain(A) is None - assert app.override_domain(B) is None - raises_msg(ExtensionError, 'new domain not a subclass of registered ' - 'foo domain', app.override_domain, C) - finally: - app.cleanup() + + # No domain know named foo. + raises_msg(ExtensionError, 'domain foo not yet registered', + app.override_domain, A) + assert app.add_domain(A) is None + assert app.override_domain(B) is None + raises_msg(ExtensionError, 'new domain not a subclass of registered ' + 'foo domain', app.override_domain, C) |