forked from colcon/colcon-cmake
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_flake8.py
More file actions
59 lines (49 loc) · 1.82 KB
/
Copy pathtest_flake8.py
File metadata and controls
59 lines (49 loc) · 1.82 KB
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
58
59
# Copyright 2016-2018 Dirk Thomas
# Licensed under the Apache License, Version 2.0
import logging
from pathlib import Path
import sys
import pytest
@pytest.mark.flake8
@pytest.mark.linter
def test_flake8():
from flake8.api.legacy import get_style_guide
# avoid debug / info / warning messages from flake8 internals
logging.getLogger('flake8').setLevel(logging.ERROR)
# for some reason the pydocstyle logger changes to an effective level of 1
# set higher level to prevent the output to be flooded with debug messages
logging.getLogger('pydocstyle').setLevel(logging.WARNING)
style_guide = get_style_guide(
extend_ignore=[
'D100', 'D104', 'F824', 'I100', 'I201'
],
show_source=True,
)
style_guide_tests = get_style_guide(
extend_ignore=[
'D100', 'D101', 'D102', 'D103', 'D104', 'D105', 'D107',
'F824', 'I100', 'I201'
],
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()
if report.total_errors:
report._application.formatter.show_statistics(report._stats)
if report_tests.total_errors:
report_tests._application.formatter.show_statistics(
report_tests._stats)
print(f'flake8 reported {total_errors} errors', file=sys.stderr)
assert not total_errors, f'flake8 reported {total_errors} errors'