Files
sphinx/tests/test_application.py
Georg Brandl f0605a40a4 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
........
2008-08-23 15:04:45 +00:00

60 lines
1.6 KiB
Python

# -*- 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()