Skip to content

Commit 945cc0b

Browse files
committed
testing: stop relying on comparing to py.path in fnmatcher tests
1 parent 35df3e6 commit 945cc0b

File tree

1 file changed

+11
-28
lines changed

1 file changed

+11
-28
lines changed

testing/test_pathlib.py

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from typing import Generator
99

1010
import pytest
11-
from _pytest.compat import legacy_path
1211
from _pytest.monkeypatch import MonkeyPatch
1312
from _pytest.pathlib import bestrelpath
1413
from _pytest.pathlib import commonpath
@@ -26,23 +25,7 @@
2625

2726

2827
class TestFNMatcherPort:
29-
"""Test that our port of py.common.FNMatcher (fnmatch_ex) produces the
30-
same results as the original legacy_path.fnmatch method."""
31-
32-
@pytest.fixture(params=["pathlib", "py.path"])
33-
def match(self, request):
34-
if request.param == "py.path":
35-
36-
def match_(pattern, path):
37-
return legacy_path(path).fnmatch(pattern)
38-
39-
else:
40-
assert request.param == "pathlib"
41-
42-
def match_(pattern, path):
43-
return fnmatch_ex(pattern, path)
44-
45-
return match_
28+
"""Test our port of py.common.FNMatcher (fnmatch_ex)."""
4629

4730
if sys.platform == "win32":
4831
drv1 = "c:"
@@ -58,36 +41,36 @@ def match_(pattern, path):
5841
("*.py", "bar/foo.py"),
5942
("test_*.py", "foo/test_foo.py"),
6043
("tests/*.py", "tests/foo.py"),
61-
(drv1 + "/*.py", drv1 + "/foo.py"),
62-
(drv1 + "/foo/*.py", drv1 + "/foo/foo.py"),
44+
(f"{drv1}/*.py", f"{drv1}/foo.py"),
45+
(f"{drv1}/foo/*.py", f"{drv1}/foo/foo.py"),
6346
("tests/**/test*.py", "tests/foo/test_foo.py"),
6447
("tests/**/doc/test*.py", "tests/foo/bar/doc/test_foo.py"),
6548
("tests/**/doc/**/test*.py", "tests/foo/doc/bar/test_foo.py"),
6649
],
6750
)
68-
def test_matching(self, match, pattern, path):
69-
assert match(pattern, path)
51+
def test_matching(self, pattern: str, path: str) -> None:
52+
assert fnmatch_ex(pattern, path)
7053

71-
def test_matching_abspath(self, match):
54+
def test_matching_abspath(self) -> None:
7255
abspath = os.path.abspath(os.path.join("tests/foo.py"))
73-
assert match("tests/foo.py", abspath)
56+
assert fnmatch_ex("tests/foo.py", abspath)
7457

7558
@pytest.mark.parametrize(
7659
"pattern, path",
7760
[
7861
("*.py", "foo.pyc"),
7962
("*.py", "foo/foo.pyc"),
8063
("tests/*.py", "foo/foo.py"),
81-
(drv1 + "/*.py", drv2 + "/foo.py"),
82-
(drv1 + "/foo/*.py", drv2 + "/foo/foo.py"),
64+
(f"{drv1}/*.py", f"{drv2}/foo.py"),
65+
(f"{drv1}/foo/*.py", f"{drv2}/foo/foo.py"),
8366
("tests/**/test*.py", "tests/foo.py"),
8467
("tests/**/test*.py", "foo/test_foo.py"),
8568
("tests/**/doc/test*.py", "tests/foo/bar/doc/foo.py"),
8669
("tests/**/doc/test*.py", "tests/foo/bar/test_foo.py"),
8770
],
8871
)
89-
def test_not_matching(self, match, pattern, path):
90-
assert not match(pattern, path)
72+
def test_not_matching(self, pattern: str, path: str) -> None:
73+
assert not fnmatch_ex(pattern, path)
9174

9275

9376
class TestImportPath:

0 commit comments

Comments
 (0)