-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Align linter tests with the rest of the colcon packages (#33)
This change makes colcon-lcov-result "catch up" to accumulated changes to the linters run in other colcon packages. The most noteworthy change is the switch from enchant to scspell to get better cross-platform consistency. There are no changes to the actual code in this package.
- Loading branch information
Showing
5 changed files
with
100 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,29 @@ | ||
CMake | ||
ament | ||
apache | ||
cmake | ||
colcon | ||
filt | ||
demangle | ||
gcno | ||
gcov | ||
genhtml | ||
html | ||
iterdir | ||
lcov | ||
lcovrc | ||
linter | ||
nargs | ||
nofilt | ||
noqa | ||
pragma | ||
pathlib | ||
pkgs | ||
plugin | ||
pydocstyle | ||
pytest | ||
returncode | ||
rtype | ||
stderr | ||
stdout | ||
str | ||
scspell | ||
setuptools | ||
staticmethod | ||
thomas | ||
tracefile | ||
tracefiles | ||
zerocounters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,59 @@ | ||
# Copyright 2016-2018 Dirk Thomas | ||
# Copyright 2016-2019 Dirk Thomas | ||
# Licensed under the Apache License, Version 2.0 | ||
|
||
from pathlib import Path | ||
|
||
from pylint.lint import Run | ||
import pytest | ||
|
||
|
||
spell_check_words_path = Path(__file__).parent / 'spell_check.words' | ||
|
||
|
||
def test_spell_check(): | ||
@pytest.fixture(scope='module') | ||
def known_words(): | ||
global spell_check_words_path | ||
return spell_check_words_path.read_text().splitlines() | ||
|
||
try: | ||
import enchant # noqa: F401 | ||
except ImportError: # pragma: no cover | ||
pytest.skip( | ||
"Skipping spell checking tests since 'enchant' was not found") | ||
|
||
try: | ||
Run([ | ||
'--disable=all', | ||
'--enable=spelling', | ||
'--spelling-dict=en_US', | ||
'--ignore-comments=no', | ||
'--spelling-private-dict-file=' + str(spell_check_words_path), | ||
str(Path(__file__).parents[1] / 'colcon_lcov_result'), | ||
] + [ | ||
str(p) for p in | ||
(Path(__file__).parents[1] / 'test').glob('**/*.py') | ||
]) | ||
except SystemExit as e: | ||
assert not e.code, 'Some spell checking errors' | ||
else: | ||
assert False, 'The pylint API is supposed to raise a SystemExit' | ||
|
||
|
||
def test_spell_check_word_list(): | ||
global spell_check_words_path | ||
with spell_check_words_path.open('r') as h: | ||
lines = h.read().splitlines() | ||
assert lines == sorted(lines), \ | ||
|
||
@pytest.mark.linter | ||
def test_spell_check(known_words): | ||
from scspell import Report | ||
from scspell import SCSPELL_BUILTIN_DICT | ||
from scspell import spell_check | ||
|
||
source_filenames = [Path(__file__).parents[1] / 'setup.py'] + \ | ||
list( | ||
(Path(__file__).parents[1] / 'colcon_lcov_result') | ||
.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, \ | ||
f'Found {unknown_word_count} unknown words: ' + \ | ||
', '.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, \ | ||
f'{unused_known_word_count} words in the word list are not used: ' + \ | ||
', '.join(sorted(unused_known_words)) | ||
|
||
|
||
@pytest.mark.linter | ||
def test_spell_check_word_list_order(known_words): | ||
assert known_words == sorted(known_words), \ | ||
'The word list should be ordered alphabetically' | ||
|
||
|
||
@pytest.mark.linter | ||
def test_spell_check_word_list_duplicates(known_words): | ||
assert len(known_words) == len(set(known_words)), \ | ||
'The word list should not contain duplicates' |