MCPcopy
hub / github.com/pytest-dev/pytest / relto

Method relto

src/_pytest/_py/path.py:431–448  ·  view source on GitHub ↗

Return a string which is the relative part of the path to the given 'relpath'.

(self, relpath)

Source from the content-addressed store, hash-verified

429 return FNMatcher(pattern)(self)
430
431 def relto(self, relpath):
432 """Return a string which is the relative part of the path
433 to the given 'relpath'.
434 """
435 if not isinstance(relpath, str | LocalPath):
436 raise TypeError(f"{relpath!r}: not a string or path object")
437 strrelpath = str(relpath)
438 if strrelpath and strrelpath[-1] != self.sep:
439 strrelpath += self.sep
440 # assert strrelpath[-1] == self.sep
441 # assert strrelpath[-2] != self.sep
442 strself = self.strpath
443 if sys.platform == "win32" or getattr(os, "_name", None) == "nt":
444 if os.path.normcase(strself).startswith(os.path.normcase(strrelpath)):
445 return strself[len(strrelpath) :]
446 elif strself.startswith(strrelpath):
447 return strself[len(strrelpath) :]
448 return ""
449
450 def ensure_dir(self, *args):
451 """Ensure the path joined with args is a directory."""

Callers 2

mksymlinktoMethod · 0.95
bestrelpathMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected