|
7 | 7 | import subprocess |
8 | 8 | import sys |
9 | 9 |
|
| 10 | +import mock |
10 | 11 | import pytest |
11 | 12 |
|
12 | 13 | import pre_commit.constants as C |
@@ -782,7 +783,7 @@ def test_files_running_subdir(repo_with_passing_hook, tempdir_factory): |
782 | 783 | '--files', 'foo.py', |
783 | 784 | tempdir_factory=tempdir_factory, |
784 | 785 | ) |
785 | | - assert 'subdir/foo.py'.replace('/', os.sep) in stdout |
| 786 | + assert 'subdir/foo.py' in stdout |
786 | 787 |
|
787 | 788 |
|
788 | 789 | @pytest.mark.parametrize( |
@@ -826,6 +827,23 @@ def test_classifier_removes_dne(): |
826 | 827 | assert classifier.filenames == [] |
827 | 828 |
|
828 | 829 |
|
| 830 | +def test_classifier_normalizes_filenames_on_windows_to_forward_slashes(tmpdir): |
| 831 | + with tmpdir.as_cwd(): |
| 832 | + tmpdir.join('a/b/c').ensure() |
| 833 | + with mock.patch.object(os, 'altsep', '/'): |
| 834 | + with mock.patch.object(os, 'sep', '\\'): |
| 835 | + classifier = Classifier((r'a\b\c',)) |
| 836 | + assert classifier.filenames == ['a/b/c'] |
| 837 | + |
| 838 | + |
| 839 | +def test_classifier_does_not_normalize_backslashes_non_windows(tmpdir): |
| 840 | + with mock.patch.object(os.path, 'lexists', return_value=True): |
| 841 | + with mock.patch.object(os, 'altsep', None): |
| 842 | + with mock.patch.object(os, 'sep', '/'): |
| 843 | + classifier = Classifier((r'a/b\c',)) |
| 844 | + assert classifier.filenames == [r'a/b\c'] |
| 845 | + |
| 846 | + |
829 | 847 | @pytest.fixture |
830 | 848 | def some_filenames(): |
831 | 849 | return ( |
|
0 commit comments