22from pathlib import Path
33from tempfile import TemporaryDirectory
44
5- from gitignore_parser import parse_gitignore , parse_gitignore_string
5+ from gitignore_parser import parse_gitignore , parse_gitignore_str
66
77from unittest import TestCase , main
88
99
1010class Test (TestCase ):
1111 def test_simple (self ):
12- matches = parse_gitignore_string (
12+ matches = parse_gitignore_str (
1313 '__pycache__/\n '
1414 '*.py[cod]' ,
1515 full_path = '/home/michael/.gitignore'
@@ -30,7 +30,7 @@ def test_simple_parse_file(self):
3030 self .assertTrue (matches ('/home/michael/__pycache__' ))
3131
3232 def test_incomplete_filename (self ):
33- matches = parse_gitignore_string ('o.py' , full_path = '/home/michael/.gitignore' )
33+ matches = parse_gitignore_str ('o.py' , full_path = '/home/michael/.gitignore' )
3434 self .assertTrue (matches ('/home/michael/o.py' ))
3535 self .assertFalse (matches ('/home/michael/foo.py' ))
3636 self .assertFalse (matches ('/home/michael/o.pyc' ))
@@ -39,7 +39,7 @@ def test_incomplete_filename(self):
3939 self .assertFalse (matches ('/home/michael/dir/o.pyc' ))
4040
4141 def test_wildcard (self ):
42- matches = parse_gitignore_string (
42+ matches = parse_gitignore_str (
4343 'hello.*' ,
4444 full_path = '/home/michael/.gitignore'
4545 )
@@ -51,7 +51,7 @@ def test_wildcard(self):
5151 self .assertFalse (matches ('/home/michael/helloX' ))
5252
5353 def test_anchored_wildcard (self ):
54- matches = parse_gitignore_string (
54+ matches = parse_gitignore_str (
5555 '/hello.*' ,
5656 full_path = '/home/michael/.gitignore'
5757 )
@@ -60,7 +60,7 @@ def test_anchored_wildcard(self):
6060 self .assertFalse (matches ('/home/michael/a/hello.java' ))
6161
6262 def test_trailingspaces (self ):
63- matches = parse_gitignore_string (
63+ matches = parse_gitignore_str (
6464 'ignoretrailingspace \n '
6565 'notignoredspace\\ \n '
6666 'partiallyignoredspace\\ \n '
@@ -83,7 +83,7 @@ def test_trailingspaces(self):
8383 self .assertFalse (matches ('/home/michael/notignoredmultiplespace' ))
8484
8585 def test_comment (self ):
86- matches = parse_gitignore_string (
86+ matches = parse_gitignore_str (
8787 'somematch\n '
8888 '#realcomment\n '
8989 'othermatch\n '
@@ -97,7 +97,7 @@ def test_comment(self):
9797
9898 def test_ignore_directory (self ):
9999 matches = \
100- parse_gitignore_string ('.venv/' , full_path = '/home/michael/.gitignore' )
100+ parse_gitignore_str ('.venv/' , full_path = '/home/michael/.gitignore' )
101101 self .assertTrue (matches ('/home/michael/.venv' ))
102102 self .assertTrue (matches ('/home/michael/.venv/folder' ))
103103 self .assertTrue (matches ('/home/michael/.venv/file.txt' ))
@@ -106,13 +106,13 @@ def test_ignore_directory(self):
106106
107107 def test_ignore_directory_asterisk (self ):
108108 matches = \
109- parse_gitignore_string ('.venv/*' , full_path = '/home/michael/.gitignore' )
109+ parse_gitignore_str ('.venv/*' , full_path = '/home/michael/.gitignore' )
110110 self .assertFalse (matches ('/home/michael/.venv' ))
111111 self .assertTrue (matches ('/home/michael/.venv/folder' ))
112112 self .assertTrue (matches ('/home/michael/.venv/file.txt' ))
113113
114114 def test_negation (self ):
115- matches = parse_gitignore_string (
115+ matches = parse_gitignore_str (
116116 '''
117117*.ignore
118118!keep.ignore
@@ -124,15 +124,15 @@ def test_negation(self):
124124 self .assertTrue (matches ('/home/michael/waste.ignore' ))
125125
126126 def test_literal_exclamation_mark (self ):
127- matches = parse_gitignore_string (
127+ matches = parse_gitignore_str (
128128 '\\ !ignore_me!' , full_path = '/home/michael/.gitignore'
129129 )
130130 self .assertTrue (matches ('/home/michael/!ignore_me!' ))
131131 self .assertFalse (matches ('/home/michael/ignore_me!' ))
132132 self .assertFalse (matches ('/home/michael/ignore_me' ))
133133
134134 def test_double_asterisks (self ):
135- matches = parse_gitignore_string (
135+ matches = parse_gitignore_str (
136136 'foo/**/Bar' , full_path = '/home/michael/.gitignore'
137137 )
138138 self .assertTrue (matches ('/home/michael/foo/hello/Bar' ))
@@ -142,7 +142,7 @@ def test_double_asterisks(self):
142142
143143 def test_double_asterisk_without_slashes_handled_like_single_asterisk (self ):
144144 matches = \
145- parse_gitignore_string ('a/b**c/d' , full_path = '/home/michael/.gitignore' )
145+ parse_gitignore_str ('a/b**c/d' , full_path = '/home/michael/.gitignore' )
146146 self .assertTrue (matches ('/home/michael/a/bc/d' ))
147147 self .assertTrue (matches ('/home/michael/a/bXc/d' ))
148148 self .assertTrue (matches ('/home/michael/a/bbc/d' ))
@@ -154,16 +154,16 @@ def test_double_asterisk_without_slashes_handled_like_single_asterisk(self):
154154
155155 def test_more_asterisks_handled_like_single_asterisk (self ):
156156 matches = \
157- parse_gitignore_string ('***a/b' , full_path = '/home/michael/.gitignore' )
157+ parse_gitignore_str ('***a/b' , full_path = '/home/michael/.gitignore' )
158158 self .assertTrue (matches ('/home/michael/XYZa/b' ))
159159 self .assertFalse (matches ('/home/michael/foo/a/b' ))
160160 matches = \
161- parse_gitignore_string ('a/b***' , full_path = '/home/michael/.gitignore' )
161+ parse_gitignore_str ('a/b***' , full_path = '/home/michael/.gitignore' )
162162 self .assertTrue (matches ('/home/michael/a/bXYZ' ))
163163 self .assertFalse (matches ('/home/michael/a/b/foo' ))
164164
165165 def test_directory_only_negation (self ):
166- matches = parse_gitignore_string ('''
166+ matches = parse_gitignore_str ('''
167167data/**
168168!data/**/
169169!.gitkeep
@@ -181,20 +181,20 @@ def test_directory_only_negation(self):
181181 )
182182
183183 def test_single_asterisk (self ):
184- matches = parse_gitignore_string ('*' , full_path = '/home/michael/.gitignore' )
184+ matches = parse_gitignore_str ('*' , full_path = '/home/michael/.gitignore' )
185185 self .assertTrue (matches ('/home/michael/file.txt' ))
186186 self .assertTrue (matches ('/home/michael/directory' ))
187187 self .assertTrue (matches ('/home/michael/directory-trailing/' ))
188188
189189 def test_supports_path_type_argument (self ):
190- matches = parse_gitignore_string (
190+ matches = parse_gitignore_str (
191191 'file1\n !file2' , full_path = '/home/michael/.gitignore'
192192 )
193193 self .assertTrue (matches (Path ('/home/michael/file1' )))
194194 self .assertFalse (matches (Path ('/home/michael/file2' )))
195195
196196 def test_slash_in_range_does_not_match_dirs (self ):
197- matches = parse_gitignore_string (
197+ matches = parse_gitignore_str (
198198 'abc[X-Z/]def' , full_path = '/home/michael/.gitignore'
199199 )
200200 self .assertFalse (matches ('/home/michael/abcdef' ))
@@ -208,7 +208,7 @@ def test_symlink_to_another_directory(self):
208208 with TemporaryDirectory () as project_dir :
209209 with TemporaryDirectory () as another_dir :
210210 matches = \
211- parse_gitignore_string ('link' , full_path = f"{ project_dir } /.gitignore" )
211+ parse_gitignore_str ('link' , full_path = f"{ project_dir } /.gitignore" )
212212
213213 # Create a symlink to another directory.
214214 link = Path (project_dir , 'link' )
@@ -228,7 +228,7 @@ def test_symlink_to_symlink_directory(self):
228228 link .symlink_to (project_dir )
229229 file = Path (link , 'file.txt' )
230230 matches = \
231- parse_gitignore_string ('file.txt' , full_path = f"{ link_dir } /.gitignore" )
231+ parse_gitignore_str ('file.txt' , full_path = f"{ link_dir } /.gitignore" )
232232 self .assertTrue (matches (file ))
233233
234234
0 commit comments