Download:
child 52:e1ca1959db76
parent 50:8194291e98bc
51:0552f5ca41a3
Anton Shestakov <av6@dwimlabs.net>, Mon, 20 Jun 2016 00:11:57 +0800
incoming: use a list of regular expressions to extract linter output type

2 файлов изменено, 28 вставок(+), 20 удалений(-) [+]
incoming.py file | annotate | diff | comparison | revisions
tests/test_incoming.py file | annotate | diff | comparison | revisions
--- a/incoming.py Sun Jun 19 23:51:50 2016 +0800
+++ b/incoming.py Mon Jun 20 00:11:57 2016 +0800
@@ -46,26 +46,26 @@
item['fileline'] = int(m.group(2))
rest = line[m.end():]
- # pep8-specific E9xx
- # https://pep8.readthedocs.io/en/latest/intro.html#error-codes
- if re.match(r'^E9\d{2}', rest) is not None:
- errors += 1
- item['cls'] = 'error'
- elif re.match(r'^[EWFCN]\d{3}', rest) is not None:
- warnings += 1
- item['cls'] = 'warning'
- elif re.match(r'^\[error\]', rest) is not None:
- errors += 1
- item['cls'] = 'error'
- elif re.match(r'^\[warning\]', rest) is not None:
- warnings += 1
- item['cls'] = 'warning'
- elif re.match(r'^\(E\d{3}\)', rest) is not None:
- errors += 1
- item['cls'] = 'error'
- elif re.match(r'^\(W\d{3}\)', rest) is not None:
- warnings += 1
- item['cls'] = 'warning'
+ patterns = (
+ # pep8-specific E9xx
+ # https://pep8.readthedocs.io/en/latest/intro.html#error-codes
+ (r'^E9\d{2}', 'error'),
+ (r'^[EWFCN]\d{3}', 'warning'),
+ (r'^\[error\]', 'error'),
+ (r'^\[warning\]', 'warning'),
+ (r'^\(E\d{3}\)', 'error'),
+ (r'^\(W\d{3}\)', 'warning'),
+ )
+
+ for regex, cls in patterns:
+ m = re.match(regex, rest)
+ if m is not None:
+ item['cls'] = cls
+ if cls == 'error':
+ errors += 1
+ elif cls == 'warning':
+ warnings += 1
+ break
else:
warnings += 1
item['cls'] = 'warning'
--- a/tests/test_incoming.py Sun Jun 19 23:51:50 2016 +0800
+++ b/tests/test_incoming.py Mon Jun 20 00:11:57 2016 +0800
@@ -19,6 +19,14 @@
assert extra['filename'] == 'file with spaces'
assert extra['fileline'] == 7
+ errors, warnings, extra = mlo('requirements.txt:1:1: PIL is obsolete.')
+ assert errors == 0
+ assert warnings == 1
+ assert sorted(extra.keys()) == ['cls', 'fileline', 'filename']
+ assert extra['cls'] == 'warning'
+ assert extra['filename'] == 'requirements.txt'
+ assert extra['fileline'] == 1
+
def test_parse_project_url():
result = parse_project_url('https://example.com/alice/hello-world')