diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2018-09-02 09:04:49 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2018-09-02 10:03:43 -0400 |
commit | 56b9c7e4db40df6515d4ca5d913cb4678da2b753 (patch) | |
tree | e5236fc3347124fbfb6c8bbde10a2c8ed87e5347 /tests/test_files.py | |
parent | 8bb8175d9e14f1a47180ccd356060d5068bc769b (diff) | |
download | python-coveragepy-git-56b9c7e4db40df6515d4ca5d913cb4678da2b753.tar.gz |
Move fiddly fnmatch logic into its own testable function
Diffstat (limited to 'tests/test_files.py')
-rw-r--r-- | tests/test_files.py | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/tests/test_files.py b/tests/test_files.py index 2e705a1b..b4490ea6 100644 --- a/tests/test_files.py +++ b/tests/test_files.py @@ -12,7 +12,7 @@ import pytest from coverage import files from coverage.files import ( TreeMatcher, FnmatchMatcher, ModuleMatcher, PathAliases, - find_python_files, abs_file, actual_path, flat_rootname, + find_python_files, abs_file, actual_path, flat_rootname, fnmatches_to_regex, ) from coverage.misc import CoverageException from coverage import env @@ -77,6 +77,55 @@ def test_flat_rootname(original, flat): assert flat_rootname(original) == flat +@pytest.mark.parametrize( + "patterns, case_insensitive, partial," + "matches," + "nomatches", +[ + ( + ["abc", "xyz"], False, False, + ["abc", "xyz"], + ["ABC", "xYz", "abcx", "xabc", "axyz", "xyza"], + ), + ( + ["abc", "xyz"], True, False, + ["abc", "xyz", "Abc", "XYZ", "AbC"], + ["abcx", "xabc", "axyz", "xyza"], + ), + ( + ["abc/hi.py"], True, False, + ["abc/hi.py", "ABC/hi.py", r"ABC\hi.py"], + ["abc_hi.py", "abc/hi.pyc"], + ), + ( + [r"abc\hi.py"], True, False, + [r"abc\hi.py", r"ABC\hi.py"], + ["abc/hi.py", "ABC/hi.py", "abc_hi.py", "abc/hi.pyc"], + ), + ( + ["abc/*/hi.py"], True, False, + ["abc/foo/hi.py", "ABC/foo/bar/hi.py", r"ABC\foo/bar/hi.py"], + ["abc/hi.py", "abc/hi.pyc"], + ), + ( + ["abc/[a-f]*/hi.py"], True, False, + ["abc/foo/hi.py", "ABC/foo/bar/hi.py", r"ABC\foo/bar/hi.py"], + ["abc/zoo/hi.py", "abc/hi.py", "abc/hi.pyc"], + ), + ( + ["abc/"], True, True, + ["abc/foo/hi.py", "ABC/foo/bar/hi.py", r"ABC\foo/bar/hi.py"], + ["abcd/foo.py", "xabc/hi.py"], + ), +]) +def test_fnmatches_to_regex(patterns, case_insensitive, partial, matches, nomatches): + regex = fnmatches_to_regex(patterns, case_insensitive=case_insensitive, partial=partial) + for s in matches: + assert regex.match(s) + for s in nomatches: + assert not regex.match(s) + + class MatcherTest(CoverageTest): """Tests of file matchers.""" |