Skip to content

Commit 8e7e8f7

Browse files
committed
Add unit tests for spell checker + docstr lines that look like comments
1 parent f70cda4 commit 8e7e8f7

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed

tests/checkers/unittest_spelling.py

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,140 @@ def test_more_than_one_error_in_same_line_for_same_word_on_comment(self):
363363
),
364364
):
365365
self.checker.process_tokens(_tokenize_str("# bad coment coment"))
366+
367+
@skip_on_missing_package_or_dict
368+
@set_config(spelling_dict=spell_dict)
369+
def test_docstring_lines_that_look_like_comments_1(self):
370+
stmt = astroid.extract_node(
371+
# fmt: off
372+
'def f():\n'
373+
' """\n'
374+
' # msitake\n'
375+
' """'
376+
# fmt: on
377+
)
378+
with self.assertAddsMessages(
379+
Message(
380+
"wrong-spelling-in-docstring",
381+
line=3,
382+
args=(
383+
"msitake",
384+
" # msitake",
385+
" ^^^^^^^",
386+
self._get_msg_suggestions("msitake"),
387+
),
388+
)
389+
):
390+
self.checker.visit_functiondef(stmt)
391+
392+
@skip_on_missing_package_or_dict
393+
@set_config(spelling_dict=spell_dict)
394+
def test_docstring_lines_that_look_like_comments_2(self):
395+
stmt = astroid.extract_node(
396+
# fmt: off
397+
'def f():\n'
398+
' """# msitake"""'
399+
# fmt: on
400+
)
401+
with self.assertAddsMessages(
402+
Message(
403+
"wrong-spelling-in-docstring",
404+
line=2,
405+
args=(
406+
"msitake",
407+
"# msitake",
408+
" ^^^^^^^",
409+
self._get_msg_suggestions("msitake"),
410+
),
411+
)
412+
):
413+
self.checker.visit_functiondef(stmt)
414+
415+
@skip_on_missing_package_or_dict
416+
@set_config(spelling_dict=spell_dict)
417+
def test_docstring_lines_that_look_like_comments_3(self):
418+
stmt = astroid.extract_node(
419+
# fmt: off
420+
'def f():\n'
421+
' """\n'
422+
'# msitake\n'
423+
' """'
424+
# fmt: on
425+
)
426+
with self.assertAddsMessages(
427+
Message(
428+
"wrong-spelling-in-docstring",
429+
line=3,
430+
args=(
431+
"msitake",
432+
"# msitake",
433+
" ^^^^^^^",
434+
self._get_msg_suggestions("msitake"),
435+
),
436+
)
437+
):
438+
self.checker.visit_functiondef(stmt)
439+
440+
@skip_on_missing_package_or_dict
441+
@set_config(spelling_dict=spell_dict)
442+
def test_docstring_lines_that_look_like_comments_4(self):
443+
stmt = astroid.extract_node(
444+
# fmt: off
445+
'def f():\n'
446+
' """\n'
447+
' # cat\n'
448+
' """'
449+
# fmt: on
450+
)
451+
with self.assertAddsMessages():
452+
self.checker.visit_functiondef(stmt)
453+
454+
@skip_on_missing_package_or_dict
455+
@set_config(spelling_dict=spell_dict)
456+
def test_docstring_lines_that_look_like_comments_5(self):
457+
stmt = astroid.extract_node(
458+
# fmt: off
459+
'def f():\n'
460+
' """\n'
461+
' msitake # cat\n'
462+
' """'
463+
# fmt: on
464+
)
465+
with self.assertAddsMessages(
466+
Message(
467+
"wrong-spelling-in-docstring",
468+
line=3,
469+
args=(
470+
"msitake",
471+
" msitake # cat",
472+
" ^^^^^^^",
473+
self._get_msg_suggestions("msitake"),
474+
),
475+
)
476+
):
477+
self.checker.visit_functiondef(stmt)
478+
479+
@skip_on_missing_package_or_dict
480+
@set_config(spelling_dict=spell_dict)
481+
def test_docstring_lines_that_look_like_comments_6(self):
482+
stmt = astroid.extract_node(
483+
# fmt: off
484+
'def f():\n'
485+
' """\n'
486+
' cat # msitake\n'
487+
' """'
488+
# fmt: on
489+
)
490+
with self.assertAddsMessages(
491+
Message(
492+
"wrong-spelling-in-docstring",
493+
line=3,
494+
args=(
495+
"msitake",
496+
" cat # msitake",
497+
" ^^^^^^^",
498+
self._get_msg_suggestions("msitake"),
499+
),
500+
)
501+
):
502+
self.checker.visit_functiondef(stmt)

0 commit comments

Comments
 (0)