1
+ from __future__ import annotations
2
+
1
3
import sys
2
4
3
5
import pytest
4
6
5
- from pre_commit_hooks .check_illegal_windows_names import (
6
- find_illegal_windows_names ,
7
- main ,
8
- parents ,
9
- )
7
+ from pre_commit_hooks .check_illegal_windows_names import find_illegal_windows_names
8
+ from pre_commit_hooks .check_illegal_windows_names import main
9
+ from pre_commit_hooks .check_illegal_windows_names import parents
10
10
from pre_commit_hooks .util import cmd_output
11
11
12
12
skip_win32 = pytest .mark .skipif (
13
- sys .platform == " win32" ,
14
- reason = " case conflicts between directories and files" ,
13
+ sys .platform == ' win32' ,
14
+ reason = ' case conflicts between directories and files' ,
15
15
)
16
16
17
17
18
18
def test_parents ():
19
- assert set (parents ("a" )) == set ()
20
- assert set (parents (" a/b" )) == {"a" }
21
- assert set (parents (" a/b/c" )) == {" a/b" , "a" }
22
- assert set (parents (" a/b/c/d" )) == {" a/b/c" , " a/b" , "a" }
19
+ assert set (parents ('a' )) == set ()
20
+ assert set (parents (' a/b' )) == {'a' }
21
+ assert set (parents (' a/b/c' )) == {' a/b' , 'a' }
22
+ assert set (parents (' a/b/c/d' )) == {' a/b/c' , ' a/b' , 'a' }
23
23
24
24
25
25
def test_nothing_added (temp_git_dir ):
26
26
with temp_git_dir .as_cwd ():
27
- assert find_illegal_windows_names ([" f.py" ]) == 0
27
+ assert find_illegal_windows_names ([' f.py' ]) == 0
28
28
29
29
30
30
def test_adding_something (temp_git_dir ):
31
31
with temp_git_dir .as_cwd ():
32
- temp_git_dir .join (" f.py" ).write ("print('hello world')" )
33
- cmd_output (" git" , " add" , " f.py" )
32
+ temp_git_dir .join (' f.py' ).write ("print('hello world')" )
33
+ cmd_output (' git' , ' add' , ' f.py' )
34
34
35
- assert find_illegal_windows_names ([" f.py" ]) == 0
35
+ assert find_illegal_windows_names ([' f.py' ]) == 0
36
36
37
37
38
38
@skip_win32 # pragma: win32 no cover
39
39
def test_adding_something_with_illegal_filename (temp_git_dir ):
40
40
with temp_git_dir .as_cwd ():
41
- temp_git_dir .join (" CoM3.py" ).write ("print('hello world')" )
42
- cmd_output (" git" , " add" , " CoM3.py" )
41
+ temp_git_dir .join (' CoM3.py' ).write ("print('hello world')" )
42
+ cmd_output (' git' , ' add' , ' CoM3.py' )
43
43
44
- assert find_illegal_windows_names ([" CoM3.py" ]) == 1
44
+ assert find_illegal_windows_names ([' CoM3.py' ]) == 1
45
45
46
46
47
47
@skip_win32 # pragma: win32 no cover
48
48
def test_adding_files_with_illegal_directory (temp_git_dir ):
49
49
with temp_git_dir .as_cwd ():
50
- temp_git_dir .mkdir (" lpt2" ).join ("x" ).write (" foo" )
51
- cmd_output (" git" , " add" , "-A" )
50
+ temp_git_dir .mkdir (' lpt2' ).join ('x' ).write (' foo' )
51
+ cmd_output (' git' , ' add' , '-A' )
52
52
53
53
assert find_illegal_windows_names ([]) == 1
54
54
55
55
56
56
@skip_win32 # pragma: win32 no cover
57
57
def test_adding_files_with_illegal_deep_directories (temp_git_dir ):
58
58
with temp_git_dir .as_cwd ():
59
- temp_git_dir .mkdir ("x" ).mkdir ("y" ).join (" pRn" ).write (" foo" )
60
- cmd_output (" git" , " add" , "-A" )
59
+ temp_git_dir .mkdir ('x' ).mkdir ('y' ).join (' pRn' ).write (' foo' )
60
+ cmd_output (' git' , ' add' , '-A' )
61
61
62
62
assert find_illegal_windows_names ([]) == 1
63
63
@@ -67,12 +67,12 @@ def test_integration(temp_git_dir):
67
67
with temp_git_dir .as_cwd ():
68
68
assert main (argv = []) == 0
69
69
70
- temp_git_dir .join (" f.py" ).write ("print('hello world')" )
71
- cmd_output (" git" , " add" , " f.py" )
70
+ temp_git_dir .join (' f.py' ).write ("print('hello world')" )
71
+ cmd_output (' git' , ' add' , ' f.py' )
72
72
73
- assert main (argv = [" f.py" ]) == 0
73
+ assert main (argv = [' f.py' ]) == 0
74
74
75
- temp_git_dir .join (" CON.py" ).write ("print('hello world')" )
76
- cmd_output (" git" , " add" , " CON.py" )
75
+ temp_git_dir .join (' CON.py' ).write ("print('hello world')" )
76
+ cmd_output (' git' , ' add' , ' CON.py' )
77
77
78
- assert main (argv = [" CON.py" ]) == 1
78
+ assert main (argv = [' CON.py' ]) == 1
0 commit comments