1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
"""Test the spelling on all docstrings we can find in this module.
This serves two purposes - to provide a lot of test data for the
checker routines, and to make sure we don't suffer the embarrassment
of having spelling errors in a spellchecking package!
"""
import os
WORDS = [
"spellchecking",
"utf",
"dict",
"unicode",
"bytestring",
"bytestrings",
"str",
"pyenchant",
"ascii",
"utils",
"setup",
"distutils",
"pkg",
"filename",
"tokenization",
"tuple",
"tuples",
"tokenizer",
"tokenizers",
"testcase",
"testcases",
"whitespace",
"wxpython",
"spellchecker",
"dialog",
"urls",
"wikiwords",
"enchantobject",
"providerdesc",
"spellcheck",
"pwl",
"aspell",
"myspell",
"docstring",
"docstrings",
"stopiteration",
"pwls",
"pypwl",
"dictwithpwl",
"skippable",
"dicts",
"dict's",
"filenames",
"fr",
"trie",
"api",
"ctypes",
"wxspellcheckerdialog",
"stateful",
"cmdlinechecker",
"spellchecks",
"callback",
"clunkier",
"iterator",
"ispell",
"cor",
"backends",
"subclasses",
"initialise",
"runtime",
"py",
"meth",
"attr",
"func",
"exc",
"enchant",
]
def test_docstrings():
"""Test that all our docstrings are error-free."""
import enchant
import enchant.checker
import enchant.checker.CmdLineChecker
import enchant.pypwl
import enchant.tokenize
import enchant.tokenize.en
import enchant.utils
try:
import enchant.checker.GtkSpellCheckerDialog
except ImportError:
pass
try:
import enchant.checker.WxSpellCheckerDialog
except ImportError:
pass
errors = []
# Naive recursion here would blow the stack, instead we
# simulate it with our own stack
tocheck = [enchant]
checked = []
while tocheck:
obj = tocheck.pop()
checked.append(obj)
newobjs = list(_check_docstrings(obj, errors))
tocheck.extend([obj for obj in newobjs if obj not in checked])
assert not errors
def _check_docstrings(obj, errors):
import enchant
if hasattr(obj, "__doc__"):
skip_errors = [w for w in getattr(obj, "_DOC_ERRORS", [])]
chkr = enchant.checker.SpellChecker(
"en_US", obj.__doc__, filters=[enchant.tokenize.URLFilter]
)
for err in chkr:
if len(err.word) == 1:
continue
if err.word.lower() in WORDS:
continue
if skip_errors and skip_errors[0] == err.word:
skip_errors.pop(0)
continue
errors.append((obj, err.word, err.wordpos))
# Find and yield all child objects that should be checked
for name in dir(obj):
if name.startswith("__"):
continue
child = getattr(obj, name)
if hasattr(child, "__file__"):
if not hasattr(globals(), "__file__"):
continue
if not child.__file__.startswith(os.path.dirname(__file__)):
continue
else:
cmod = getattr(child, "__module__", None)
if not cmod:
cclass = getattr(child, "__class__", None)
cmod = getattr(cclass, "__module__", None)
if cmod and not cmod.startswith("enchant"):
continue
yield child
|