2022-01-16 08:24:05 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2016-01-15 11:03:11 +08:00
|
|
|
import os
|
|
|
|
|
2016-01-15 07:25:46 +08:00
|
|
|
import pytest
|
|
|
|
|
2019-02-01 11:19:10 +08:00
|
|
|
from pre_commit_hooks.check_symlinks import main
|
2016-01-15 07:25:46 +08:00
|
|
|
|
|
|
|
|
2017-09-08 23:27:04 +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(
|
2017-09-08 23:27:04 +08:00
|
|
|
('dest', 'expected'), (('exists', 0), ('does-not-exist', 1)),
|
2017-07-16 03:56:51 +08:00
|
|
|
)
|
2019-02-01 11:19:10 +08:00
|
|
|
def test_main(tmpdir, dest, expected): # pragma: no cover (symlinks)
|
2017-09-08 23:27:04 +08:00
|
|
|
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
|
2017-09-08 23:27:04 +08:00
|
|
|
|
|
|
|
|
2019-02-01 11:19:10 +08:00
|
|
|
def test_main_normal_file(tmpdir):
|
2020-05-21 00:07:45 +08:00
|
|
|
assert main((str(tmpdir.join('f').ensure()),)) == 0
|