new hook tests for broken symlinks
diff --git a/pre_commit_hooks/check_symlinks.py b/pre_commit_hooks/check_symlinks.py new file mode 100644 index 0000000..d0f0f09 --- /dev/null +++ b/pre_commit_hooks/check_symlinks.py
@@ -0,0 +1,26 @@ +from __future__ import absolute_import +from __future__ import print_function +from __future__ import unicode_literals + +import argparse +import os +import os.path + + +def check_symlinks(argv=None): + parser = argparse.ArgumentParser(description='Checks for broken symlinks.') + parser.add_argument('filenames', nargs='*', help='Filenames to check') + args = parser.parse_args(argv) + + retv = 0 + + for filename in args.filenames: + if os.path.islink(filename) and not os.path.exists(filename): + print('{0}: Broken symlink'.format(filename)) + retv = 1 + + return retv + + +if __name__ == '__main__': + exit(check_symlinks())
diff --git a/testing/resources/broken_symlink b/testing/resources/broken_symlink new file mode 120000 index 0000000..ee1f6cb --- /dev/null +++ b/testing/resources/broken_symlink
@@ -0,0 +1 @@ +does_not_exist \ No newline at end of file
diff --git a/testing/resources/does_exist b/testing/resources/does_exist new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/testing/resources/does_exist
diff --git a/testing/resources/working_symlink b/testing/resources/working_symlink new file mode 120000 index 0000000..20b5061 --- /dev/null +++ b/testing/resources/working_symlink
@@ -0,0 +1 @@ +does_exist \ No newline at end of file
diff --git a/tests/check_symlinks_test.py b/tests/check_symlinks_test.py new file mode 100644 index 0000000..2235be0 --- /dev/null +++ b/tests/check_symlinks_test.py
@@ -0,0 +1,13 @@ +import pytest + +from pre_commit_hooks.check_symlinks import check_symlinks +from testing.util import get_resource_path + + +@pytest.mark.parametrize(('filename', 'expected_retval'), ( + ('broken_symlink', 1), + ('working_symlink', 0), +)) +def test_check_symlinks(filename, expected_retval): + ret = check_symlinks([get_resource_path(filename)]) + assert ret == expected_retval