File: test_spell_check.py

package info (click to toggle)
ros2-colcon-bash 0.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 140 kB
  • sloc: python: 180; makefile: 2
file content (57 lines) | stat: -rw-r--r-- 1,987 bytes parent folder | download | duplicates (2)
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
# Copyright 2016-2019 Dirk Thomas
# Licensed under the Apache License, Version 2.0

from pathlib import Path

import pytest
try:
    from scspell import Report
    from scspell import SCSPELL_BUILTIN_DICT
    from scspell import spell_check
except ModuleNotFoundError:
    pytest.skip("skipping spell check tests", allow_module_level=True)


spell_check_words_path = Path(__file__).parent / 'spell_check.words'


@pytest.fixture(scope='module')
def known_words():
    global spell_check_words_path
    return spell_check_words_path.read_text().splitlines()


def test_spell_check(known_words):
    source_filenames = [Path(__file__).parents[1] / 'setup.py'] + \
        list((Path(__file__).parents[1] / 'colcon_bash').glob('**/*.py')) + \
        list((Path(__file__).parents[1] / 'test').glob('**/*.py'))

    for source_filename in sorted(source_filenames):
        print('Spell checking:', source_filename)

    # check all files
    report = Report(known_words)
    spell_check(
        [str(p) for p in source_filenames], base_dicts=[SCSPELL_BUILTIN_DICT],
        report_only=report, additional_extensions=[('', 'Python')])

    unknown_word_count = len(report.unknown_words)
    assert unknown_word_count == 0, \
        'Found {unknown_word_count} unknown words: '.format_map(locals()) + \
        ', '.join(sorted(report.unknown_words))

    unused_known_words = set(known_words) - report.found_known_words
    unused_known_word_count = len(unused_known_words)
    assert unused_known_word_count == 0, \
        '{unused_known_word_count} words in the word list are not used: ' \
        .format_map(locals()) + ', '.join(sorted(unused_known_words))


def test_spell_check_word_list_order(known_words):
    assert known_words == sorted(known_words), \
        'The word list should be ordered alphabetically'


def test_spell_check_word_list_duplicates(known_words):
    assert len(known_words) == len(set(known_words)), \
        'The word list should not contain duplicates'