forked from colcon/colcon-cmake
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1545c0
commit 22c8a11
Showing
4 changed files
with
155 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
argcomplete | ||
args | ||
basepath | ||
bool | ||
buildfile | ||
cmake | ||
colcon | ||
config | ||
cpu | ||
ctest | ||
dict | ||
github | ||
https | ||
jobserver | ||
kislyuk | ||
makeflags | ||
noqa | ||
pragma | ||
rtype | ||
str | ||
todo | ||
txt | ||
xml |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2016-2018 Dirk Thomas | ||
# Licensed under the Apache License, Version 2.0 | ||
|
||
from pathlib import Path | ||
import sys | ||
|
||
|
||
def test_copyright_licence(): | ||
missing = check_files([Path(__file__).parents[1]]) | ||
assert not len(missing), \ | ||
'In some files no copyright / license line was found' | ||
|
||
|
||
def check_files(paths): | ||
missing = [] | ||
for path in paths: | ||
if path.is_dir(): | ||
for p in sorted(path.iterdir()): | ||
if p.name.startswith('.'): | ||
continue | ||
if p.name.endswith('.py') or p.is_dir(): | ||
missing += check_files([p]) | ||
if path.is_file(): | ||
content = path.read_text() | ||
if not content: | ||
continue | ||
lines = content.splitlines() | ||
has_copyright = \ | ||
any(l for l in lines if l.startswith('# Copyright')) | ||
has_license = \ | ||
'# Licensed under the Apache License, Version 2.0' in lines | ||
if not has_copyright or not has_license: | ||
print( | ||
'Could not find copyright / license in:', path, | ||
file=sys.stderr) | ||
missing .append(path) | ||
else: | ||
print('Found copyright / license in:', path) | ||
return missing |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Copyright 2016-2018 Dirk Thomas | ||
# Licensed under the Apache License, Version 2.0 | ||
|
||
import logging | ||
from pathlib import Path | ||
import sys | ||
|
||
from flake8 import LOG | ||
from flake8.api.legacy import get_style_guide | ||
|
||
|
||
# avoid debug and info messages from flake8 internals | ||
LOG.setLevel(logging.WARN) | ||
|
||
|
||
def test_flake8(): | ||
style_guide = get_style_guide( | ||
ignore=['D100', 'D104'], | ||
show_source=True, | ||
) | ||
style_guide_tests = get_style_guide( | ||
ignore=['D100', 'D101', 'D102', 'D103', 'D104', 'D105', 'D107'], | ||
show_source=True, | ||
) | ||
|
||
stdout = sys.stdout | ||
sys.stdout = sys.stderr | ||
# implicitly calls report_errors() | ||
report = style_guide.check_files([ | ||
str(Path(__file__).parents[1] / 'colcon_cmake'), | ||
]) | ||
report_tests = style_guide_tests.check_files([ | ||
str(Path(__file__).parents[1] / 'test'), | ||
]) | ||
sys.stdout = stdout | ||
|
||
total_errors = report.total_errors + report_tests.total_errors | ||
if total_errors: # pragma: no cover | ||
# output summary with per-category counts | ||
print() | ||
report._application.formatter.show_statistics(report._stats) | ||
print( | ||
'flake8 reported {total_errors} errors' | ||
.format_map(locals()), file=sys.stderr) | ||
|
||
assert not report.total_errors, \ | ||
'flake8 reported {total_errors} errors'.format_map(locals()) |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright 2016-2018 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(): | ||
global spell_check_words_path | ||
|
||
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_cmake'), | ||
] + [ | ||
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), \ | ||
'The word list should be ordered alphabetically' |