nodes: inline `_imply_path`
Only one usage left, and we certainly don't expect more! Rename `_imply_path_only` to `_imply_path`, that's a less confusing name now.
This commit is contained in:
parent
6be3f31dba
commit
afc7442e22
|
@ -4,8 +4,9 @@ from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from ..compat import LEGACY_PATH
|
from ..compat import LEGACY_PATH
|
||||||
|
from ..compat import legacy_path
|
||||||
from ..deprecated import HOOK_LEGACY_PATH_ARG
|
from ..deprecated import HOOK_LEGACY_PATH_ARG
|
||||||
from _pytest.nodes import _imply_path
|
from _pytest.nodes import _check_path
|
||||||
|
|
||||||
# hookname: (Path, LEGACY_PATH)
|
# hookname: (Path, LEGACY_PATH)
|
||||||
imply_paths_hooks = {
|
imply_paths_hooks = {
|
||||||
|
@ -52,7 +53,15 @@ class PathAwareHookProxy:
|
||||||
),
|
),
|
||||||
stacklevel=2,
|
stacklevel=2,
|
||||||
)
|
)
|
||||||
path_value, fspath_value = _imply_path(path_value, fspath_value)
|
if path_value is not None:
|
||||||
|
if fspath_value is not None:
|
||||||
|
_check_path(path_value, fspath_value)
|
||||||
|
else:
|
||||||
|
fspath_value = legacy_path(path_value)
|
||||||
|
else:
|
||||||
|
assert fspath_value is not None
|
||||||
|
path_value = Path(fspath_value)
|
||||||
|
|
||||||
kw[path_var] = path_value
|
kw[path_var] = path_value
|
||||||
kw[fspath_var] = fspath_value
|
kw[fspath_var] = fspath_value
|
||||||
return hook(**kw)
|
return hook(**kw)
|
||||||
|
|
|
@ -101,23 +101,7 @@ def _check_path(path: Path, fspath: LEGACY_PATH) -> None:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _imply_path(
|
def _imply_path(path: Optional[Path], fspath: Optional[LEGACY_PATH]) -> Path:
|
||||||
path: Optional[Path], fspath: Optional[LEGACY_PATH]
|
|
||||||
) -> Tuple[Path, LEGACY_PATH]:
|
|
||||||
if path is not None:
|
|
||||||
if fspath is not None:
|
|
||||||
_check_path(path, fspath)
|
|
||||||
else:
|
|
||||||
fspath = legacy_path(path)
|
|
||||||
return path, fspath
|
|
||||||
else:
|
|
||||||
assert fspath is not None
|
|
||||||
return Path(fspath), fspath
|
|
||||||
|
|
||||||
|
|
||||||
# Optimization: use _imply_path_only over _imply_path when only need Path.
|
|
||||||
# This is to avoid `legacy_path(path)` which is surprisingly heavy.
|
|
||||||
def _imply_path_only(path: Optional[Path], fspath: Optional[LEGACY_PATH]) -> Path:
|
|
||||||
if path is not None:
|
if path is not None:
|
||||||
if fspath is not None:
|
if fspath is not None:
|
||||||
_check_path(path, fspath)
|
_check_path(path, fspath)
|
||||||
|
@ -212,7 +196,7 @@ class Node(metaclass=NodeMeta):
|
||||||
#: Filesystem path where this node was collected from (can be None).
|
#: Filesystem path where this node was collected from (can be None).
|
||||||
if path is None and fspath is None:
|
if path is None and fspath is None:
|
||||||
path = getattr(parent, "path", None)
|
path = getattr(parent, "path", None)
|
||||||
self.path = _imply_path_only(path, fspath=fspath)
|
self.path = _imply_path(path, fspath=fspath)
|
||||||
|
|
||||||
# The explicit annotation is to avoid publicly exposing NodeKeywords.
|
# The explicit annotation is to avoid publicly exposing NodeKeywords.
|
||||||
#: Keywords/markers collected from all scopes.
|
#: Keywords/markers collected from all scopes.
|
||||||
|
@ -589,7 +573,7 @@ class FSCollector(Collector):
|
||||||
assert path is None
|
assert path is None
|
||||||
path = path_or_parent
|
path = path_or_parent
|
||||||
|
|
||||||
path = _imply_path_only(path, fspath=fspath)
|
path = _imply_path(path, fspath=fspath)
|
||||||
if name is None:
|
if name is None:
|
||||||
name = path.name
|
name = path.name
|
||||||
if parent is not None and parent.path != path:
|
if parent is not None and parent.path != path:
|
||||||
|
|
Loading…
Reference in New Issue