forked from pytest-dev/pytest
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a PurePath instance to do matching against patterns in assertion …
…rewrite This way we don't need to have real file system path, which prevents the original pytest-dev#3973 bug.
- Loading branch information
1 parent
1df6d28
commit f642728
Showing
4 changed files
with
121 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import sys | ||
|
||
import py | ||
|
||
import pytest | ||
|
||
from _pytest.paths import fnmatch_ex | ||
|
||
|
||
class TestPort: | ||
"""Test that our port of py.common.FNMatcher (fnmatch_ex) produces the same results as the | ||
original py.path.local.fnmatch method. | ||
""" | ||
|
||
@pytest.fixture(params=["pathlib", "py.path"]) | ||
def match(self, request): | ||
if request.param == "py.path": | ||
|
||
def match_(pattern, path): | ||
return py.path.local(path).fnmatch(pattern) | ||
|
||
else: | ||
assert request.param == "pathlib" | ||
|
||
def match_(pattern, path): | ||
return fnmatch_ex(pattern, path) | ||
|
||
return match_ | ||
|
||
if sys.platform == "win32": | ||
drv1 = "c:" | ||
drv2 = "d:" | ||
else: | ||
drv1 = "" | ||
drv2 = "" | ||
|
||
@pytest.mark.parametrize( | ||
"pattern, path", | ||
[ | ||
("*.py", "foo.py"), | ||
("*.py", "bar/foo.py"), | ||
("test_*.py", "foo/test_foo.py"), | ||
("tests/*.py", "tests/foo.py"), | ||
(drv1 + "/*.py", drv1 + "/foo.py"), | ||
(drv1 + "/foo/*.py", drv1 + "/foo/foo.py"), | ||
("tests/**/test*.py", "tests/foo/test_foo.py"), | ||
("tests/**/doc/test*.py", "tests/foo/bar/doc/test_foo.py"), | ||
("tests/**/doc/**/test*.py", "tests/foo/doc/bar/test_foo.py"), | ||
], | ||
) | ||
def test_matching(self, match, pattern, path): | ||
assert match(pattern, path) | ||
|
||
@pytest.mark.parametrize( | ||
"pattern, path", | ||
[ | ||
("*.py", "foo.pyc"), | ||
("*.py", "foo/foo.pyc"), | ||
("tests/*.py", "foo/foo.py"), | ||
(drv1 + "/*.py", drv2 + "/foo.py"), | ||
(drv1 + "/foo/*.py", drv2 + "/foo/foo.py"), | ||
("tests/**/test*.py", "tests/foo.py"), | ||
("tests/**/test*.py", "foo/test_foo.py"), | ||
("tests/**/doc/test*.py", "tests/foo/bar/doc/foo.py"), | ||
("tests/**/doc/test*.py", "tests/foo/bar/test_foo.py"), | ||
], | ||
) | ||
def test_not_matching(self, match, pattern, path): | ||
assert not match(pattern, path) |