summaryrefslogtreecommitdiffstats
path: root/tests/check_vcs_permalinks_test.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 20:47:18 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-21 20:47:18 +0000
commitceb85610c77b7487b0b7d742415301922c6b13b6 (patch)
tree82456c5d0bc77961759812ddd85414435ba89127 /tests/check_vcs_permalinks_test.py
parentInitial commit. (diff)
downloadpre-commit-hooks-ceb85610c77b7487b0b7d742415301922c6b13b6.tar.xz
pre-commit-hooks-ceb85610c77b7487b0b7d742415301922c6b13b6.zip
Adding upstream version 4.5.0+dfsg.upstream/4.5.0+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/check_vcs_permalinks_test.py')
-rw-r--r--tests/check_vcs_permalinks_test.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/check_vcs_permalinks_test.py b/tests/check_vcs_permalinks_test.py
new file mode 100644
index 0000000..01ce94d
--- /dev/null
+++ b/tests/check_vcs_permalinks_test.py
@@ -0,0 +1,43 @@
+from __future__ import annotations
+
+from pre_commit_hooks.check_vcs_permalinks import main
+
+
+def test_trivial(tmpdir):
+ f = tmpdir.join('f.txt').ensure()
+ assert not main((str(f),))
+
+
+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'
+ # tags are ok
+ b'https://github.com/asottile/test/blob/1.0.0/foo%20bar#L1\n'
+ # links to files but not line numbers are ok
+ b'https://github.com/asottile/test/blob/master/foo%20bar\n'
+ # regression test for overly-greedy regex
+ b'https://github.com/ yes / no ? /blob/master/foo#L1\n',
+ )
+ assert not main((str(f),))
+
+
+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'
+ b'https://example.com/asottile/test/blob/master/foo#L1\n'
+ b'https://example.com/asottile/test/blob/main/foo#L1\n',
+ )
+
+ assert main(('f.txt', '--additional-github-domain', 'example.com'))
+ out, _ = capsys.readouterr()
+ assert out == (
+ 'f.txt:1:https://github.com/asottile/test/blob/master/foo#L1\n'
+ 'f.txt:2:https://example.com/asottile/test/blob/master/foo#L1\n'
+ 'f.txt:3:https://example.com/asottile/test/blob/main/foo#L1\n'
+ '\n'
+ 'Non-permanent github link detected.\n'
+ 'On any page on github press [y] to load a permalink.\n'
+ )