pre-commit-hooks/tests/check_symlinks_test.py

26 lines
627 B
Python
Raw Permalink Normal View History

from __future__ import annotations
2016-01-15 11:03:11 +08:00
import os
2016-01-15 07:25:46 +08:00
import pytest
from pre_commit_hooks.check_symlinks import main
2016-01-15 07:25:46 +08:00
xfail_symlink = pytest.mark.xfail(os.name == 'nt', reason='No symlink support')
@xfail_symlink
2017-07-16 03:56:51 +08:00
@pytest.mark.parametrize(
('dest', 'expected'), (('exists', 0), ('does-not-exist', 1)),
2017-07-16 03:56:51 +08:00
)
def test_main(tmpdir, dest, expected): # pragma: no cover (symlinks)
tmpdir.join('exists').ensure()
symlink = tmpdir.join('symlink')
symlink.mksymlinkto(tmpdir.join(dest))
2020-05-21 00:07:45 +08:00
assert main((str(symlink),)) == expected
def test_main_normal_file(tmpdir):
2020-05-21 00:07:45 +08:00
assert main((str(tmpdir.join('f').ensure()),)) == 0