mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 03:26:53 +00:00
Add hook for ensuring vcs permalinks
This commit is contained in:
parent
dec98f7bc8
commit
9db0a745f6
6 changed files with 96 additions and 0 deletions
36
tests/check_vcs_permalinks_test.py
Normal file
36
tests/check_vcs_permalinks_test.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
from __future__ import absolute_import
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from pre_commit_hooks.check_vcs_permalinks import main
|
||||
|
||||
|
||||
def test_trivial(tmpdir):
|
||||
f = tmpdir.join('f.txt').ensure()
|
||||
assert not main((f.strpath,))
|
||||
|
||||
|
||||
def test_passing(tmpdir):
|
||||
f = tmpdir.join('f.txt')
|
||||
f.write_binary(
|
||||
# permalinks are ok
|
||||
b'https://github.com/asottile/test/blob/649e6/foo%20bar#L1\n'
|
||||
# links to files but not line numbers are ok
|
||||
b'https://github.com/asottile/test/blob/master/foo%20bar\n',
|
||||
)
|
||||
assert not main((f.strpath,))
|
||||
|
||||
|
||||
def test_failing(tmpdir, capsys):
|
||||
with tmpdir.as_cwd():
|
||||
tmpdir.join('f.txt').write_binary(
|
||||
b'https://github.com/asottile/test/blob/master/foo#L1\n',
|
||||
)
|
||||
|
||||
assert main(('f.txt',))
|
||||
out, _ = capsys.readouterr()
|
||||
assert out == (
|
||||
'f.txt:1:https://github.com/asottile/test/blob/master/foo#L1\n'
|
||||
'\n'
|
||||
'Non-permanent github link detected.\n'
|
||||
'On any page on github press [y] to load a permalink.\n'
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue