Skip to content

Commit

Permalink
add tests for the spelling builder; use info() instead of printing to…
Browse files Browse the repository at this point in the history
… stdout directly; ignore the wordlist file created by pyenchant when the tests run
  • Loading branch information
dhellmann committed Dec 28, 2010
1 parent 48192fa commit 8eca452
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 6 deletions.
1 change: 1 addition & 0 deletions .hgignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ TAGS
\.ropeproject/
,*~
.DS_Store
spelling/spelling_wordlist.txt

syntax: glob
*/distribute-*.tar.gz
Expand Down
9 changes: 3 additions & 6 deletions spelling/sphinxcontrib/spelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,10 @@ def write(self, *ignored):
return

def finish(self):
# TODO - Use color output?
print
print
self.info()
for text in self.output:
print text
print
self.info('done')
self.info(text)
return

def setup(app):
print 'Initializing Spelling Checker'
Expand Down
90 changes: 90 additions & 0 deletions spelling/test/test_builder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann. All rights reserved.
#
"""Tests for SpellingBuilder
"""

import os
import shutil
import tempfile
from cStringIO import StringIO

from sphinxcontrib import spelling

from sphinx.application import Sphinx
from sphinx.config import Config

def setup():
global _tempdir, _srcdir, _outdir
_tempdir = tempfile.mkdtemp()
_srcdir = os.path.join(_tempdir, 'src')
_outdir = os.path.join(_tempdir, 'out')
os.mkdir(_srcdir)
os.mkdir(_outdir)

def teardown():
shutil.rmtree(_tempdir)

def test_setup():
with open(os.path.join(_srcdir, 'conf.py'), 'w') as f:
f.write('''
extensions = [ 'sphinxcontrib.spelling' ]
''')
stdout = StringIO()
stderr = StringIO()
# If the spelling builder is not properly initialized,
# trying to use it with the Sphinx app class will
# generate an exception.
app = Sphinx(_srcdir, _srcdir, _outdir, _outdir, 'spelling',
status=stdout, warning=stderr,
freshenv=True,
)
return

def test_title():
with open(os.path.join(_srcdir, 'conf.py'), 'w') as f:
f.write('''
extensions = [ 'sphinxcontrib.spelling' ]
''')
with open(os.path.join(_srcdir, 'contents.rst'), 'w') as f:
f.write('''
Welcome to Speeling Checker documentation!
==========================================
''')
stdout = StringIO()
stderr = StringIO()
app = Sphinx(_srcdir, _srcdir, _outdir, _outdir, 'spelling',
status=stdout, warning=stderr,
freshenv=True,
)
app.build()
assert '"Speeling"' in app.builder.output[0]
return


def test_body():
with open(os.path.join(_srcdir, 'conf.py'), 'w') as f:
f.write('''
extensions = [ 'sphinxcontrib.spelling' ]
''')
with open(os.path.join(_srcdir, 'contents.rst'), 'w') as f:
f.write('''
Welcome to Spelling Checker documentation!
==========================================
There are several mispelled words in this txt.
''')
stdout = StringIO()
stderr = StringIO()
app = Sphinx(_srcdir, _srcdir, _outdir, _outdir, 'spelling',
status=stdout, warning=stderr,
freshenv=True,
)
app.build()
output_text = app.builder.output[0]
assert '"mispelled"' in output_text
assert '"txt"' in output_text
return

0 comments on commit 8eca452

Please sign in to comment.