Skip to content

Commit

Permalink
Add functional test for spelling checker
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Aug 21, 2022
1 parent 1188340 commit cafdc37
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 12 deletions.
26 changes: 14 additions & 12 deletions pylint/checkers/spelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@
WikiWordFilter,
get_tokenizer,
)

PYENCHANT_AVAILABLE = True
except ImportError:
enchant = None
PYENCHANT_AVAILABLE = False

class EmailFilter: # type: ignore[no-redef]
...
Expand All @@ -62,17 +65,16 @@ def get_tokenizer(
return Filter()


if enchant is not None:
br = enchant.Broker()
dicts = br.list_dicts()
dict_choices = [""] + [d[0] for d in dicts]
dicts = [f"{d[0]} ({d[1].name})" for d in dicts]
dicts = ", ".join(dicts)
instr = ""
INSTALL_ENCHANT = " To make it work, install the 'python-enchant' package."
if PYENCHANT_AVAILABLE:
broker = enchant.Broker()
enchant_dicts = broker.list_dicts()
enchant_dict_choices = [""] + [d[0] for d in enchant_dicts]
enchant_dicts = [f"{d[0]} ({d[1].name})" for d in enchant_dicts]
enchant_dicts = ", ".join(enchant_dicts)
else:
dicts = "none"
dict_choices = [""]
instr = " To make it work, install the 'python-enchant' package."
enchant_dicts = "none"
enchant_dict_choices = [""]


class WordsWithDigitsFilter(Filter):
Expand Down Expand Up @@ -235,9 +237,9 @@ class SpellingChecker(BaseTokenChecker):
"default": "",
"type": "choice",
"metavar": "<dict name>",
"choices": dict_choices,
"choices": enchant_dict_choices,
"help": "Spelling dictionary name. "
f"Available dictionaries: {dicts}.{instr}",
f"Available dictionaries: {enchant_dicts}.{INSTALL_ENCHANT}",
},
),
(
Expand Down
6 changes: 6 additions & 0 deletions tests/functional/s/spelling/spelling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""Functional test for speling.""" # [wrong-spelling-in-docstring, wrong-spelling-in-comment]

# mispeled text # [wrong-spelling-in-comment]

def function_name():
"""mispeled text.""" # [wrong-spelling-in-docstring, wrong-spelling-in-comment]
2 changes: 2 additions & 0 deletions tests/functional/s/spelling/spelling.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[SPELLING]
spelling-dict=en_US
20 changes: 20 additions & 0 deletions tests/functional/s/spelling/spelling.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
wrong-spelling-in-comment:1:0:None:None::"Wrong spelling of a word 'docstring' in a comment:
# [wrong-spelling-in-docstring, wrong-spelling-in-comment]
^^^^^^^^^
Did you mean: ''doc string' or 'doc-string' or 'stringing''?":UNDEFINED
wrong-spelling-in-docstring:1:0:None:None::"Wrong spelling of a word 'speling' in a docstring:
Functional test for speling.
^^^^^^^
Did you mean: ''spieling' or 'spelling' or 'spewing' or 'peeling''?":UNDEFINED
wrong-spelling-in-comment:3:0:None:None::"Wrong spelling of a word 'mispeled' in a comment:
# mispeled text # [wrong-spelling-in-comment]
^^^^^^^^
Did you mean: ''misspelled' or 'dispelled' or 'misspell' or 'misled''?":UNDEFINED
wrong-spelling-in-comment:6:0:None:None::"Wrong spelling of a word 'docstring' in a comment:
# [wrong-spelling-in-docstring, wrong-spelling-in-comment]
^^^^^^^^^
Did you mean: ''doc string' or 'doc-string' or 'stringing''?":UNDEFINED
wrong-spelling-in-docstring:6:0:None:None::"Wrong spelling of a word 'mispeled' in a docstring:
mispeled text.
^^^^^^^^
Did you mean: ''misspelled' or 'dispelled' or 'misspell' or 'misled''?":UNDEFINED

0 comments on commit cafdc37

Please sign in to comment.