Skip to content

Commit

Permalink
add non-functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk-thomas committed Mar 19, 2018
1 parent c1545c0 commit 22c8a11
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/spell_check.words
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
39 changes: 39 additions & 0 deletions test/test_copyright_license.py
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
47 changes: 47 additions & 0 deletions test/test_flake8.py
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())
46 changes: 46 additions & 0 deletions test/test_spell_check.py
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'

0 comments on commit 22c8a11

Please sign in to comment.