def test_no_paths(self): patterns = [ "*,b,*", "a,*,*", "*,*,c", "foo,bar,baz", "w,x,*,*", "*,x,y,z" ] paths = [] self.assertEqual(get_matching_patterns(patterns, paths), ["NO MATCH"], "Should be ['NO MATCH']")
def test_base_case(self): patterns = [ "*,b,*", "a,*,*", "*,*,c", "foo,bar,baz", "w,x,*,*", "*,x,y,z" ] paths = ["/w/x/y/z/", "a/b/c", "foo/", "foo/bar/", "foo/bar/baz/"] self.assertEqual( get_matching_patterns(patterns, paths), ["*,x,y,z", "a,*,*", "NO MATCH", "NO MATCH", "foo,bar,baz"], "Should be ['*,x,y,z', 'a,*,*', 'NO MATCH', 'NO MATCH', 'foo,bar,baz']" )
def main(): # check if an input file is piped into terminal command and exit if not if stdin.isatty(): print("NO MATCH") exit(1) patterns, paths = process_input() matching_patterns = get_matching_patterns(patterns, paths) for m in matching_patterns: print(m) exit()
def test_no_patterns_or_paths(self): patterns = [] paths = [] self.assertEqual(get_matching_patterns(patterns, paths), ["NO MATCH"], "Should be ['NO MATCH']")
def test_no_patterns(self): patterns = [] paths = ["/w/x/y/z/", "a/b/c", "foo/", "foo/bar/", "foo/bar/baz/"] self.assertEqual(get_matching_patterns(patterns, paths), ["NO MATCH"], "Should be ['NO MATCH']")
def test_leftmost_wildcard(self): patterns = ["*,b,*", "*,*,c"] paths = ["a/b/c"] self.assertEqual(get_matching_patterns(patterns, paths), ["*,b,*"], "Should be ['*,b,*'] ")
def test_min_wildcards(self): patterns = ["w,x,*,*", "*,x,y,z"] paths = ["/w/x/y/z/"] self.assertEqual(get_matching_patterns(patterns, paths), ["*,x,y,z"], "Should be ['*,x,y,z'] ")
def test_no_matches(self): patterns = ["a,*,z,e", "*,f,e,c", "a,q,d,*"] paths = ["/h/i/j/k/"] self.assertEqual(get_matching_patterns(patterns, paths), ["NO MATCH"], "Should be ['NO MATCH'] ")
def test_one_match(self): patterns = ["a,b,c,e", "a,b,e,c", "a,b,d,e"] paths = ["a/b/c/e"] self.assertEqual(get_matching_patterns(patterns, paths), ["a,b,c,e"], "Should be ['a,b,c,e'] ")