Download:
child 51:0552f5ca41a3
parent 49:82badf3033e4
50:8194291e98bc
Anton Shestakov <av6@dwimlabs.net>, Sun, 19 Jun 2016 23:51:50 +0800
incoming: move linter output matching to a function, test it

2 файлов изменено, 62 вставок(+), 30 удалений(-) [+]
incoming.py file | annotate | diff | comparison | revisions
tests/test_incoming.py file | annotate | diff | comparison | revisions
--- a/incoming.py Sun Jun 19 23:44:42 2016 +0800
+++ b/incoming.py Sun Jun 19 23:51:50 2016 +0800
@@ -35,6 +35,44 @@
return domain, user, name
+def match_linter_output(line):
+ errors = 0
+ warnings = 0
+ item = {}
+
+ m = re.match(r'^(.+):(\d+):\d+: ', line)
+ if m is not None:
+ item['filename'] = m.group(1)
+ 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'
+ else:
+ warnings += 1
+ item['cls'] = 'warning'
+
+ return errors, warnings, item
+
+
def insert_check(lines):
text = ''.join(lines)
@@ -102,35 +140,10 @@
message = m.group(1)
elif state == 'checks':
- m = re.match(r'^(.+):(\d+):\d+: ', line)
- if m is not None:
- item['filename'] = m.group(1)
- item['fileline'] = 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'
- else:
- warnings += 1
- item['cls'] = 'warning'
+ de, dw, extra = match_linter_output(line)
+ errors += de
+ warnings += dw
+ item.update(extra)
result.append(item)
--- a/tests/test_incoming.py Sun Jun 19 23:44:42 2016 +0800
+++ b/tests/test_incoming.py Sun Jun 19 23:51:50 2016 +0800
@@ -1,4 +1,23 @@
-from incoming import parse_project_url
+from incoming import match_linter_output, parse_project_url
+
+
+def test_match_linter_output():
+ mlo = match_linter_output
+ errors, warnings, extra = mlo('hello.py:42:1: W123 clowntown ahoy')
+ assert errors == 0
+ assert warnings == 1
+ assert sorted(extra.keys()) == ['cls', 'fileline', 'filename']
+ assert extra['cls'] == 'warning'
+ assert extra['filename'] == 'hello.py'
+ assert extra['fileline'] == 42
+
+ errors, warnings, extra = mlo('file with spaces:007:001: [error] oops!')
+ assert errors == 1
+ assert warnings == 0
+ assert sorted(extra.keys()) == ['cls', 'fileline', 'filename']
+ assert extra['cls'] == 'error'
+ assert extra['filename'] == 'file with spaces'
+ assert extra['fileline'] == 7
def test_parse_project_url():