Anthony Sottile | 8f61529 | 2022-01-15 19:24:05 -0500 | [diff] [blame] | 1 | from __future__ import annotations |
| 2 | |
Anthony Sottile | da88228 | 2016-01-14 19:03:11 -0800 | [diff] [blame] | 3 | import os |
| 4 | |
Benjamin Chess | 896c0cf | 2016-01-14 15:25:46 -0800 | [diff] [blame] | 5 | import pytest |
| 6 | |
Anthony Sottile | 030bfac | 2019-01-31 19:19:10 -0800 | [diff] [blame] | 7 | from pre_commit_hooks.check_symlinks import main |
Benjamin Chess | 896c0cf | 2016-01-14 15:25:46 -0800 | [diff] [blame] | 8 | |
| 9 | |
Anthony Sottile | c5b7c35 | 2017-09-08 08:27:04 -0700 | [diff] [blame] | 10 | xfail_symlink = pytest.mark.xfail(os.name == 'nt', reason='No symlink support') |
| 11 | |
| 12 | |
| 13 | @xfail_symlink |
Anthony Sottile | e9aea74 | 2017-07-15 12:56:51 -0700 | [diff] [blame] | 14 | @pytest.mark.parametrize( |
Anthony Sottile | c5b7c35 | 2017-09-08 08:27:04 -0700 | [diff] [blame] | 15 | ('dest', 'expected'), (('exists', 0), ('does-not-exist', 1)), |
Anthony Sottile | e9aea74 | 2017-07-15 12:56:51 -0700 | [diff] [blame] | 16 | ) |
Anthony Sottile | 030bfac | 2019-01-31 19:19:10 -0800 | [diff] [blame] | 17 | def test_main(tmpdir, dest, expected): # pragma: no cover (symlinks) |
Anthony Sottile | c5b7c35 | 2017-09-08 08:27:04 -0700 | [diff] [blame] | 18 | tmpdir.join('exists').ensure() |
| 19 | symlink = tmpdir.join('symlink') |
| 20 | symlink.mksymlinkto(tmpdir.join(dest)) |
Max Rozentsveyg | f35bfed | 2020-05-20 12:07:45 -0400 | [diff] [blame] | 21 | assert main((str(symlink),)) == expected |
Anthony Sottile | c5b7c35 | 2017-09-08 08:27:04 -0700 | [diff] [blame] | 22 | |
| 23 | |
Anthony Sottile | 030bfac | 2019-01-31 19:19:10 -0800 | [diff] [blame] | 24 | def test_main_normal_file(tmpdir): |
Max Rozentsveyg | f35bfed | 2020-05-20 12:07:45 -0400 | [diff] [blame] | 25 | assert main((str(tmpdir.join('f').ensure()),)) == 0 |