325:9ee96b2a1610
Anton Shestakov <av6@dwimlabs.net>, Tue, 28 Nov 2017 11:58:11 +0800
viewer: return early in CheckHandler.get_chart_data()

previous change 318:1c0790b558b7

tests/test_incoming.py

Permissions: -rw-r--r--

Other formats: Feeds:
from incoming import match_linter_output, parse_project_url
def test_match_linter_output():
mlo = match_linter_output
usual_keys = {'cls', 'filename', 'line_number', 'link_end', 'link_start'}
# flake8
errors, warnings, extra = mlo('hello.py:42:1: W123 clowntown ahoy')
assert errors == 0
assert warnings == 1
assert set(extra) == usual_keys | {'code'}
assert extra['cls'] == 'warning'
assert extra['code'] == 'W123'
assert extra['filename'] == 'hello.py'
assert extra['line_number'] == 42
assert extra['link_start'] == 0
assert extra['link_end'] == 11
# yamllint
errors, warnings, extra = mlo('s p a c e.yml:07:01: [error] oops! (uh-oh)')
assert errors == 1
assert warnings == 0
assert set(extra) == usual_keys | {'code'}
assert extra['cls'] == 'error'
assert extra['code'] == 'uh-oh'
assert extra['filename'] == 's p a c e.yml'
assert extra['line_number'] == 7
assert extra['link_start'] == 0
assert extra['link_end'] == 16
# luacheck
errors, warnings, extra = mlo('ham.lua:414:90: (E101) ham is stale')
assert errors == 1
assert warnings == 0
assert set(extra) == usual_keys | {'code'}
assert extra['cls'] == 'error'
assert extra['code'] == 'E101'
assert extra['filename'] == 'ham.lua'
assert extra['line_number'] == 414
assert extra['link_start'] == 0
assert extra['link_end'] == 11
# jshint
errors, warnings, extra = mlo('backwards.js:9091:1: not perfect (W201)')
assert errors == 0
assert warnings == 1
assert set(extra) == usual_keys | {'code'}
assert extra['cls'] == 'warning'
assert extra['code'] == 'W201'
assert extra['filename'] == 'backwards.js'
assert extra['line_number'] == 9091
assert extra['link_start'] == 0
assert extra['link_end'] == 17
# shellcheck
errors, warnings, extra = mlo('helper.sh:121:5: note: hello. [SC1234]')
assert errors == 0
assert warnings == 1
assert set(extra) == usual_keys | {'code'}
assert extra['cls'] == 'warning'
assert extra['code'] == 'SC1234'
assert extra['filename'] == 'helper.sh'
assert extra['line_number'] == 121
assert extra['link_start'] == 0
assert extra['link_end'] == 13
# generic
errors, warnings, extra = mlo('requirements.txt:5:1: PIL is obsolete.')
assert errors == 0
assert warnings == 1
assert set(extra) == usual_keys
assert extra['cls'] == 'warning'
assert extra['filename'] == 'requirements.txt'
assert extra['line_number'] == 5
assert extra['link_start'] == 0
assert extra['link_end'] == 18
def test_parse_project_url():
result = parse_project_url('https://example.com/alice/hello-world')
assert result == ('example.com', 'alice', 'hello-world')
result = parse_project_url('https://example.com/bob/a/b/c/')
assert result == ('example.com', 'bob', 'a/b/c')
result = parse_project_url('~alice/hello-world')
assert result == ('self', '~alice', 'hello-world')
result = parse_project_url('https://code.example.com/hello-world')
assert result == ('code.example.com', None, 'hello-world')
result = parse_project_url('https://example.com///hello-world//')
assert result == ('example.com', None, 'hello-world')