Merge pull request #8472 from bluetech/rm-unnecessary-py-path-4
testing: stop relying on comparing to py.path in fnmatcher tests
This commit is contained in:
commit
d9f4cedf17
|
@ -8,7 +8,6 @@ from types import ModuleType
|
||||||
from typing import Generator
|
from typing import Generator
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from _pytest.compat import legacy_path
|
|
||||||
from _pytest.monkeypatch import MonkeyPatch
|
from _pytest.monkeypatch import MonkeyPatch
|
||||||
from _pytest.pathlib import bestrelpath
|
from _pytest.pathlib import bestrelpath
|
||||||
from _pytest.pathlib import commonpath
|
from _pytest.pathlib import commonpath
|
||||||
|
@ -26,23 +25,7 @@ from _pytest.tmpdir import TempPathFactory
|
||||||
|
|
||||||
|
|
||||||
class TestFNMatcherPort:
|
class TestFNMatcherPort:
|
||||||
"""Test that our port of py.common.FNMatcher (fnmatch_ex) produces the
|
"""Test our port of py.common.FNMatcher (fnmatch_ex)."""
|
||||||
same results as the original legacy_path.fnmatch method."""
|
|
||||||
|
|
||||||
@pytest.fixture(params=["pathlib", "py.path"])
|
|
||||||
def match(self, request):
|
|
||||||
if request.param == "py.path":
|
|
||||||
|
|
||||||
def match_(pattern, path):
|
|
||||||
return legacy_path(path).fnmatch(pattern)
|
|
||||||
|
|
||||||
else:
|
|
||||||
assert request.param == "pathlib"
|
|
||||||
|
|
||||||
def match_(pattern, path):
|
|
||||||
return fnmatch_ex(pattern, path)
|
|
||||||
|
|
||||||
return match_
|
|
||||||
|
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
drv1 = "c:"
|
drv1 = "c:"
|
||||||
|
@ -58,19 +41,19 @@ class TestFNMatcherPort:
|
||||||
("*.py", "bar/foo.py"),
|
("*.py", "bar/foo.py"),
|
||||||
("test_*.py", "foo/test_foo.py"),
|
("test_*.py", "foo/test_foo.py"),
|
||||||
("tests/*.py", "tests/foo.py"),
|
("tests/*.py", "tests/foo.py"),
|
||||||
(drv1 + "/*.py", drv1 + "/foo.py"),
|
(f"{drv1}/*.py", f"{drv1}/foo.py"),
|
||||||
(drv1 + "/foo/*.py", drv1 + "/foo/foo.py"),
|
(f"{drv1}/foo/*.py", f"{drv1}/foo/foo.py"),
|
||||||
("tests/**/test*.py", "tests/foo/test_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/bar/doc/test_foo.py"),
|
||||||
("tests/**/doc/**/test*.py", "tests/foo/doc/bar/test_foo.py"),
|
("tests/**/doc/**/test*.py", "tests/foo/doc/bar/test_foo.py"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_matching(self, match, pattern, path):
|
def test_matching(self, pattern: str, path: str) -> None:
|
||||||
assert match(pattern, path)
|
assert fnmatch_ex(pattern, path)
|
||||||
|
|
||||||
def test_matching_abspath(self, match):
|
def test_matching_abspath(self) -> None:
|
||||||
abspath = os.path.abspath(os.path.join("tests/foo.py"))
|
abspath = os.path.abspath(os.path.join("tests/foo.py"))
|
||||||
assert match("tests/foo.py", abspath)
|
assert fnmatch_ex("tests/foo.py", abspath)
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"pattern, path",
|
"pattern, path",
|
||||||
|
@ -78,16 +61,16 @@ class TestFNMatcherPort:
|
||||||
("*.py", "foo.pyc"),
|
("*.py", "foo.pyc"),
|
||||||
("*.py", "foo/foo.pyc"),
|
("*.py", "foo/foo.pyc"),
|
||||||
("tests/*.py", "foo/foo.py"),
|
("tests/*.py", "foo/foo.py"),
|
||||||
(drv1 + "/*.py", drv2 + "/foo.py"),
|
(f"{drv1}/*.py", f"{drv2}/foo.py"),
|
||||||
(drv1 + "/foo/*.py", drv2 + "/foo/foo.py"),
|
(f"{drv1}/foo/*.py", f"{drv2}/foo/foo.py"),
|
||||||
("tests/**/test*.py", "tests/foo.py"),
|
("tests/**/test*.py", "tests/foo.py"),
|
||||||
("tests/**/test*.py", "foo/test_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/doc/foo.py"),
|
||||||
("tests/**/doc/test*.py", "tests/foo/bar/test_foo.py"),
|
("tests/**/doc/test*.py", "tests/foo/bar/test_foo.py"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_not_matching(self, match, pattern, path):
|
def test_not_matching(self, pattern: str, path: str) -> None:
|
||||||
assert not match(pattern, path)
|
assert not fnmatch_ex(pattern, path)
|
||||||
|
|
||||||
|
|
||||||
class TestImportPath:
|
class TestImportPath:
|
||||||
|
|
Loading…
Reference in New Issue