@@ -88,11 +88,30 @@ def test_glob_matcher(self):
8888 cases = [
8989 ("dir" , "dir" , True ),
9090 ("dir" , "file" , False ),
91+ ("*.txt" , "file.txt" , True ),
92+ ("*.txt" , "file.csv" , False ),
93+
9194 ("dir" , "dir/file" , False ),
95+ ("dir/*" , "file" , False ),
96+ ("dir/*" , "dir/file" , True ),
97+ ("dir/*" , "dir/sub/file" , False ),
9298 ("dir/*.txt" , "file" , False ),
9399 ("dir/*.txt" , "dir/file" , False ),
94100 ("dir/*.txt" , "dir/file.txt" , True ),
95101 ("dir/*.txt" , "dir/.txt" , True ),
102+
103+ # recursive wildcard pattern using "/" (input paths using OS separator)
104+ ("dir/**/*" , "dirfile.txt" , False ),
105+ ("dir/**/*" , os .path .join ("dirother" , "a.txt" ), False ),
106+ ("dir/**/*" , os .path .join ("dir" , "a.txt" ), True ),
107+ ("dir/**/*" , os .path .join ("dir" , "sub" , "a.txt" ), True ),
108+ ("dir/**/*.txt" , os .path .join ("dirother" , "a.txt" ), False ),
109+ ("dir/**/*.txt" , os .path .join ("dir" , "a.txt" ), True ),
110+ ("dir/**/*.txt" , os .path .join ("dir" , "a.csv" ), False ),
111+ ("dir/**/*.txt" , os .path .join ("dir" , "sub" , "a.txt" ), True ),
112+ ("dir/**/*.txt" , os .path .join ("dir" , "sub" , "a.csv" ), False ),
113+
114+ # recursive wildcards using OS path separator.
96115 (os .path .join ("dir" , "**" , "*.txt" ), os .path .join ("dir" , "a.txt" ), True ),
97116 (os .path .join ("dir" , "**" , "*.txt" ), os .path .join ("dir" , "sub" , "a.txt" ), True ),
98117 (os .path .join ("dir" , "**" , "*.txt" ), os .path .join ("dir" , "sub" , "sub" , "a.txt" ), True ),
@@ -103,15 +122,13 @@ def test_glob_matcher(self):
103122 (os .path .join ("dir" , "**" , "*" ), os .path .join ("dir" , "abc" ), True ),
104123 ]
105124
106- for case in cases :
107- matcher = GlobMatcher (case [0 ])
108- msg = "Pattern: %s, Path: %s, expected: %s, got: %s" % (
109- case [0 ],
110- case [1 ],
111- case [2 ],
112- not case [2 ],
125+ for pattern , path , expected in cases :
126+ matcher = GlobMatcher (pattern )
127+ self .assertEqual (
128+ matcher .matches (path ),
129+ expected ,
130+ f"pattern: { pattern } ; path: { path } ; expected: { expected } " ,
113131 )
114- self .assertEqual (matcher .matches (case [1 ]), case [2 ], msg )
115132
116133 with self .assertRaises (ValueError ):
117134 GlobMatcher (os .path .join ("." , "blah" , "**" , "blah" , "**" , "*.txt" ))
0 commit comments