sphinxcontrib-spelling-1.4/ 0000755 0001017 0000765 00000000000 12041052234 020003 5 ustar dhellmann dhellmann 0000000 0000000 sphinxcontrib-spelling-1.4/LICENSE 0000644 0001017 0000765 00000002422 12002336165 021015 0 ustar dhellmann dhellmann 0000000 0000000 Copyright (c) 2010 by Doug Hellmann.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
sphinxcontrib-spelling-1.4/MANIFEST.in 0000644 0001017 0000765 00000000120 12002336165 021537 0 ustar dhellmann dhellmann 0000000 0000000 include README
include LICENSE
include CHANGES.*
include test/test_wordlist.txt
sphinxcontrib-spelling-1.4/PKG-INFO 0000644 0001017 0000765 00000004460 12041052234 021104 0 ustar dhellmann dhellmann 0000000 0000000 Metadata-Version: 1.0
Name: sphinxcontrib-spelling
Version: 1.4
Summary: Sphinx "spelling" extension
Home-page: http://bitbucket.org/dhellmann/sphinxcontrib-spelling
Author: Doug Hellmann
Author-email: doug.hellmann@gmail.com
License: BSD
Description: .. -*- mode: rst -*-
=========================
sphinxcontrib-spelling
=========================
This package contains sphinxcontrb.spelling, a spelling checker for
Sphinx-based documentation. It uses PyEnchant_ to produce a report
showing misspelled words.
Refer to the `main documentation page
`__ for
installation and setup details.
License
=======
Copyright Doug Hellmann, All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Doug Hellmann not be used
in advertising or publicity pertaining to distribution of the software
without specific, written prior permission.
DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
.. _PyEnchant: http://www.rfk.id.au/software/pyenchant/
Platform: any
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Topic :: Documentation
Classifier: Topic :: Utilities
sphinxcontrib-spelling-1.4/README 0000644 0001017 0000765 00000002621 12002336165 020671 0 ustar dhellmann dhellmann 0000000 0000000 .. -*- mode: rst -*-
=========================
sphinxcontrib-spelling
=========================
This package contains sphinxcontrb.spelling, a spelling checker for
Sphinx-based documentation. It uses PyEnchant_ to produce a report
showing misspelled words.
Refer to the `main documentation page
`__ for
installation and setup details.
License
=======
Copyright Doug Hellmann, All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Doug Hellmann not be used
in advertising or publicity pertaining to distribution of the software
without specific, written prior permission.
DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
.. _PyEnchant: http://www.rfk.id.au/software/pyenchant/
sphinxcontrib-spelling-1.4/setup.cfg 0000644 0001017 0000765 00000000141 12041052234 021620 0 ustar dhellmann dhellmann 0000000 0000000 [egg_info]
tag_build =
tag_date = 0
tag_svn_revision = 0
[aliases]
release = egg_info -RDb ''
sphinxcontrib-spelling-1.4/setup.py 0000644 0001017 0000765 00000002074 12041052023 021514 0 ustar dhellmann dhellmann 0000000 0000000 # -*- coding: utf-8 -*-
from setuptools import setup, find_packages
f = open('README', 'r')
try:
long_desc = f.read()
finally:
f.close()
requires = ['Sphinx>=0.6',
#'PyEnchant>=1.6.5',
]
setup(
name='sphinxcontrib-spelling',
version='1.4',
url='http://bitbucket.org/dhellmann/sphinxcontrib-spelling',
license='BSD',
author='Doug Hellmann',
author_email='doug.hellmann@gmail.com',
description='Sphinx "spelling" extension',
long_description=long_desc,
zip_safe=False,
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Console',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Documentation',
'Topic :: Utilities',
],
platforms='any',
packages=find_packages(),
include_package_data=True,
install_requires=requires,
namespace_packages=['sphinxcontrib'],
)
sphinxcontrib-spelling-1.4/sphinxcontrib/ 0000755 0001017 0000765 00000000000 12041052234 022675 5 ustar dhellmann dhellmann 0000000 0000000 sphinxcontrib-spelling-1.4/sphinxcontrib/__init__.py 0000644 0001017 0000765 00000000556 12002336165 025021 0 ustar dhellmann dhellmann 0000000 0000000 # -*- coding: utf-8 -*-
"""
sphinxcontrib
~~~~~~~~~~~~~
This package is a namespace package that contains all extensions
distributed in the ``sphinx-contrib`` distribution.
:copyright: Copyright 2007-2009 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
__import__('pkg_resources').declare_namespace(__name__)
sphinxcontrib-spelling-1.4/sphinxcontrib/spelling.py 0000644 0001017 0000765 00000027253 12007236137 025105 0 ustar dhellmann dhellmann 0000000 0000000 #!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann. All rights reserved.
#
"""Spelling checker extension for Sphinx.
"""
import __builtin__
import codecs
import collections
import imp
import itertools
import os
import re
import textwrap
import tempfile
import xmlrpclib
#from docutils import core
from docutils.frontend import OptionParser
from docutils.io import StringOutput
import docutils.nodes
from docutils.nodes import GenericNodeVisitor
from docutils.parsers import rst
from docutils.writers import Writer
from sphinx.builders import Builder
from sphinx.util.console import bold, darkgreen
from sphinx.util.console import purple, red, darkgreen, darkgray
from sphinx.util.nodes import inline_all_toctrees
import enchant
from enchant.tokenize import (get_tokenizer, tokenize,
Filter, EmailFilter, WikiWordFilter,
unit_tokenize, wrap_tokenizer,
)
# TODO - Words with multiple uppercase letters treated as classes and ignored
class SpellingDirective(rst.Directive):
"""Custom directive for passing instructions to the spelling checker.
.. spelling::
word1
word2
"""
option_spec = {}
has_content = True
def run(self):
env = self.state.document.settings.env
# Initialize the per-document filters
if not hasattr(env, 'spelling_document_filters'):
env.spelling_document_filters = collections.defaultdict(list)
good_words = []
for entry in self.content:
if not entry:
continue
good_words.extend(entry.split())
if good_words:
env.app.info('Extending local dictionary for %s with %s' % (
env.docname, str(good_words)))
env.spelling_document_filters[env.docname].append(
IgnoreWordsFilterFactory(good_words)
)
return []
class AcronymFilter(Filter):
"""If a word looks like an acronym (all upper case letters),
ignore it.
"""
def _skip(self, word):
return (word == word.upper() # all caps
or
# pluralized acronym ("URLs")
(word[-1].lower() == 's'
and
word[:-1] == word[:-1].upper()
)
)
class list_tokenize(tokenize):
def __init__(self, words):
tokenize.__init__(self, '')
self._words = words
def next(self):
if not self._words:
raise StopIteration()
word = self._words.pop(0)
return (word, 0)
class ContractionFilter(Filter):
"""Strip common contractions from words.
"""
splits = {
"won't":['will', 'not'],
"isn't":['is', 'not'],
"can't":['can', 'not'],
"i'm":['I', 'am'],
}
def _split(self, word):
# Fixed responses
if word.lower() in self.splits:
return list_tokenize(self.splits[word.lower()])
# Possessive
if word.lower().endswith("'s"):
return unit_tokenize(word[:-2])
# * not
if word.lower().endswith("n't"):
return unit_tokenize(word[:-3])
return unit_tokenize(word)
class IgnoreWordsFilter(Filter):
"""Given a set of words, ignore them all.
"""
def __init__(self, tokenizer, word_set):
self.word_set = set(word_set)
Filter.__init__(self, tokenizer)
def _skip(self, word):
return word in self.word_set
class IgnoreWordsFilterFactory(object):
def __init__(self, words):
self.words = words
def __call__(self, tokenizer):
return IgnoreWordsFilter(tokenizer, self.words)
class PyPIFilterFactory(IgnoreWordsFilterFactory):
"""Build an IgnoreWordsFilter for all of the names of packages on PyPI.
"""
def __init__(self):
client = xmlrpclib.ServerProxy('http://pypi.python.org/pypi')
IgnoreWordsFilterFactory.__init__(self, client.list_packages())
class PythonBuiltinsFilter(Filter):
"""Ignore names of built-in Python symbols.
"""
def _skip(self, word):
return hasattr(__builtin__, word)
class ImportableModuleFilter(Filter):
"""Ignore names of modules that we could import.
"""
def __init__(self, tokenizer):
Filter.__init__(self, tokenizer)
self.found_modules = set()
self.sought_modules = set()
def _skip(self, word):
if word not in self.sought_modules:
self.sought_modules.add(word)
try:
imp.find_module(word)
except UnicodeEncodeError:
return False
except ImportError:
return False
else:
self.found_modules.add(word)
return True
return word in self.found_modules
class SpellingChecker(object):
"""Checks the spelling of blocks of text.
Uses options defined in the sphinx configuration file to control
the checking and filtering behavior.
"""
def __init__(self, lang, suggest, word_list_filename, filters=[]):
self.dictionary = enchant.DictWithPWL(lang, word_list_filename)
self.tokenizer = get_tokenizer(lang, filters)
self.original_tokenizer = self.tokenizer
self.suggest = suggest
def push_filters(self, new_filters):
"""Add a filter to the tokenizer chain.
"""
t = self.tokenizer
for f in new_filters:
t = f(t)
self.tokenizer = t
def pop_filters(self):
"""Remove the filters pushed during the last call to push_filters().
"""
self.tokenizer = self.original_tokenizer
def check(self, text):
"""Generator function that yields bad words and suggested alternate spellings.
"""
for word, pos in self.tokenizer(text):
correct = self.dictionary.check(word)
if correct:
continue
yield word, self.dictionary.suggest(word) if self.suggest else []
return
TEXT_NODES = set([ 'block_quote',
'paragraph',
'list_item',
'term',
'definition_list_item',
'title',
])
class SpellingBuilder(Builder):
"""
Spell checks a document
"""
name = 'spelling'
def init(self):
self.docnames = []
self.document_data = []
# Initialize the per-document filters
if not hasattr(self.env, 'spelling_document_filters'):
self.env.spelling_document_filters = collections.defaultdict(list)
# Initialize the global filters
filters = [ ContractionFilter,
EmailFilter,
]
if self.config.spelling_ignore_wiki_words:
filters.append(WikiWordFilter)
if self.config.spelling_ignore_acronyms:
filters.append(AcronymFilter)
if self.config.spelling_ignore_pypi_package_names:
self.info('Adding package names from PyPI to local spelling dictionary...')
filters.append(PyPIFilterFactory())
if self.config.spelling_ignore_python_builtins:
filters.append(PythonBuiltinsFilter)
if self.config.spelling_ignore_importable_modules:
filters.append(ImportableModuleFilter)
filters.extend(self.config.spelling_filters)
project_words = os.path.join(self.srcdir, self.config.spelling_word_list_filename)
self.checker = SpellingChecker(lang=self.config.spelling_lang,
suggest=self.config.spelling_show_suggestions,
word_list_filename=project_words,
filters=filters,
)
self.output_filename = os.path.join(self.outdir, 'output.txt')
self.output = codecs.open(self.output_filename, 'wt', encoding='UTF-8')
def get_outdated_docs(self):
return 'all documents'
def prepare_writing(self, docnames):
return
def get_target_uri(self, docname, typ=None):
return ''
def format_suggestions(self, suggestions):
if not self.config.spelling_show_suggestions or not suggestions:
return u''
return u'[' + u', '.join(u'"%s"' % s for s in suggestions) + u']'
def write_doc(self, docname, doctree):
self.checker.push_filters(self.env.spelling_document_filters[docname])
for node in doctree.traverse(docutils.nodes.Text):
if node.tagname == '#text' and node.parent and node.parent.tagname in TEXT_NODES:
# Figure out the line number for this node by climbing the
# tree until we find a node that has a line number.
lineno = None
parent = node
seen = set()
while lineno is None:
#self.info('looking for line number on %r' % node)
seen.add(parent)
parent = node.parent
if parent is None or parent in seen:
break
lineno = parent.line
filename = self.env.doc2path(docname, base=None)
# Check the text of the node.
for word, suggestions in self.checker.check(node.astext()):
msg_parts = [ docname ]
if lineno:
msg_parts.append(darkgreen('(line %3d)' % lineno))
msg_parts.append(red(word))
msg_parts.append(self.format_suggestions(suggestions))
msg = ' '.join(msg_parts)
self.info(msg)
self.output.write(u"%s:%s: (%s) %s\n" % (
self.env.doc2path(docname, None),
lineno, word,
self.format_suggestions(suggestions),
))
# We found at least one bad spelling, so set the status
# code for the app to a value that indicates an error.
self.app.statuscode = 1
self.checker.pop_filters()
return
def finish(self):
self.output.close()
self.info('Spelling checker messages written to %s' % self.output_filename)
return
def setup(app):
app.info('Initializing Spelling Checker')
app.add_builder(SpellingBuilder)
# Register the 'spelling' directive for setting parameters within a document
app.add_directive('spelling', SpellingDirective)
# Report guesses about correct spelling
app.add_config_value('spelling_show_suggestions', False, 'env')
# Set the language for the text
app.add_config_value('spelling_lang', 'en_US', 'env')
# Set a user-provided list of words known to be spelled properly
app.add_config_value('spelling_word_list_filename', 'spelling_wordlist.txt', 'env')
# Assume anything that looks like a PyPI package name is spelled properly
app.add_config_value('spelling_ignore_pypi_package_names', False, 'env')
# Assume words that look like wiki page names are spelled properly
app.add_config_value('spelling_ignore_wiki_words', True, 'env')
# Assume words that are all caps, or all caps with trailing s, are spelled properly
app.add_config_value('spelling_ignore_acronyms', True, 'env')
# Assume words that are part of __builtins__ are spelled properly
app.add_config_value('spelling_ignore_python_builtins', True, 'env')
# Assume words that look like the names of importable modules are spelled properly
app.add_config_value('spelling_ignore_importable_modules', True, 'env')
# Add any user-defined filter classes
app.add_config_value('spelling_filters', [], 'env')
return
sphinxcontrib-spelling-1.4/sphinxcontrib_spelling.egg-info/ 0000755 0001017 0000765 00000000000 12041052234 026264 5 ustar dhellmann dhellmann 0000000 0000000 sphinxcontrib-spelling-1.4/sphinxcontrib_spelling.egg-info/dependency_links.txt 0000644 0001017 0000765 00000000001 12041052233 032331 0 ustar dhellmann dhellmann 0000000 0000000
sphinxcontrib-spelling-1.4/sphinxcontrib_spelling.egg-info/namespace_packages.txt 0000644 0001017 0000765 00000000016 12041052233 032613 0 ustar dhellmann dhellmann 0000000 0000000 sphinxcontrib
sphinxcontrib-spelling-1.4/sphinxcontrib_spelling.egg-info/not-zip-safe 0000644 0001017 0000765 00000000001 12007235255 030522 0 ustar dhellmann dhellmann 0000000 0000000
sphinxcontrib-spelling-1.4/sphinxcontrib_spelling.egg-info/PKG-INFO 0000644 0001017 0000765 00000004460 12041052233 027364 0 ustar dhellmann dhellmann 0000000 0000000 Metadata-Version: 1.0
Name: sphinxcontrib-spelling
Version: 1.4
Summary: Sphinx "spelling" extension
Home-page: http://bitbucket.org/dhellmann/sphinxcontrib-spelling
Author: Doug Hellmann
Author-email: doug.hellmann@gmail.com
License: BSD
Description: .. -*- mode: rst -*-
=========================
sphinxcontrib-spelling
=========================
This package contains sphinxcontrb.spelling, a spelling checker for
Sphinx-based documentation. It uses PyEnchant_ to produce a report
showing misspelled words.
Refer to the `main documentation page
`__ for
installation and setup details.
License
=======
Copyright Doug Hellmann, All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Doug Hellmann not be used
in advertising or publicity pertaining to distribution of the software
without specific, written prior permission.
DOUG HELLMANN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
EVENT SHALL DOUG HELLMANN BE LIABLE FOR ANY SPECIAL, INDIRECT OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
.. _PyEnchant: http://www.rfk.id.au/software/pyenchant/
Platform: any
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Topic :: Documentation
Classifier: Topic :: Utilities
sphinxcontrib-spelling-1.4/sphinxcontrib_spelling.egg-info/requires.txt 0000644 0001017 0000765 00000000013 12041052233 030655 0 ustar dhellmann dhellmann 0000000 0000000 Sphinx>=0.6 sphinxcontrib-spelling-1.4/sphinxcontrib_spelling.egg-info/SOURCES.txt 0000644 0001017 0000765 00000000753 12041052233 030154 0 ustar dhellmann dhellmann 0000000 0000000 LICENSE
MANIFEST.in
README
setup.cfg
setup.py
sphinxcontrib/__init__.py
sphinxcontrib/spelling.py
sphinxcontrib_spelling.egg-info/PKG-INFO
sphinxcontrib_spelling.egg-info/SOURCES.txt
sphinxcontrib_spelling.egg-info/dependency_links.txt
sphinxcontrib_spelling.egg-info/namespace_packages.txt
sphinxcontrib_spelling.egg-info/not-zip-safe
sphinxcontrib_spelling.egg-info/requires.txt
sphinxcontrib_spelling.egg-info/top_level.txt
test/test_builder.py
test/test_checker.py
test/test_wordlist.txt sphinxcontrib-spelling-1.4/sphinxcontrib_spelling.egg-info/top_level.txt 0000644 0001017 0000765 00000000016 12041052233 031012 0 ustar dhellmann dhellmann 0000000 0000000 sphinxcontrib
sphinxcontrib-spelling-1.4/test/ 0000755 0001017 0000765 00000000000 12041052234 020762 5 ustar dhellmann dhellmann 0000000 0000000 sphinxcontrib-spelling-1.4/test/test_builder.py 0000644 0001017 0000765 00000007315 12002336165 024034 0 ustar dhellmann dhellmann 0000000 0000000 #!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann. All rights reserved.
#
"""Tests for SpellingBuilder
"""
import codecs
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()
with codecs.open(app.builder.output_filename, 'r') as f:
output_text = f.read()
def check_one(word):
print output_text
assert word in output_text
for word in [ '(Speeling)', ]:
yield check_one, word
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()
print 'reading from %s' % app.builder.output_filename
with codecs.open(app.builder.output_filename, 'r') as f:
output_text = f.read()
def check_one(word):
assert word in output_text
for word in [ '(mispelled)', '(txt)' ]:
yield check_one, word
return
def test_ignore_literals():
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 misspelled words in this text.
::
Literal blocks are ignoreed.
Inline ``litterals`` are ignored, too.
''')
stdout = StringIO()
stderr = StringIO()
app = Sphinx(_srcdir, _srcdir, _outdir, _outdir, 'spelling',
status=stdout, warning=stderr,
freshenv=True,
)
app.build()
print 'reading from %s' % app.builder.output_filename
with codecs.open(app.builder.output_filename, 'r') as f:
output_text = f.read()
def check_one(word):
assert word not in output_text
for word in [ '(ignoreed)', '(litterals)' ]:
yield check_one, word
return
sphinxcontrib-spelling-1.4/test/test_checker.py 0000644 0001017 0000765 00000002521 12002336165 024004 0 ustar dhellmann dhellmann 0000000 0000000 #!/usr/bin/env python
# encoding: utf-8
#
# Copyright (c) 2010 Doug Hellmann. All rights reserved.
#
"""Tests for SpellingChecker.
"""
import os
from sphinxcontrib.spelling import SpellingChecker
def test_errors_only():
checker = SpellingChecker(lang='en_US',
suggest=False,
word_list_filename=None,
)
for word, suggestions in checker.check('This txt is wrong'):
assert not suggestions, 'Suggesting'
assert word == 'txt'
return
def test_with_suggestions():
checker = SpellingChecker(lang='en_US',
suggest=True,
word_list_filename=None,
)
for word, suggestions in checker.check('This txt is wrong'):
assert suggestions, 'Not suggesting'
assert word == 'txt'
return
def test_with_wordlist():
checker = SpellingChecker(lang='en_US',
suggest=False,
word_list_filename=os.path.join(os.path.dirname(__file__),
'test_wordlist.txt')
)
words = [ w for w, s in checker.check('This txt is wrong') ]
assert not words, 'Did not use personal word list file'
return
sphinxcontrib-spelling-1.4/test/test_wordlist.txt 0000644 0001017 0000765 00000000004 12002336165 024430 0 ustar dhellmann dhellmann 0000000 0000000 txt