Skip to content

Commit 6660d45

Browse files
committed
_pytest._py.path: combine PosixPath into LocalPath
1 parent af078f3 commit 6660d45

File tree

1 file changed

+38
-41
lines changed

1 file changed

+38
-41
lines changed

src/_pytest/_py/path.py

+38-41
Original file line numberDiff line numberDiff line change
@@ -491,43 +491,6 @@ def islink(self):
491491
return S_ISLNK(self._osstatresult.st_mode)
492492

493493

494-
class PosixPath(PathBase):
495-
def chown(self, user, group, rec=0):
496-
"""Change ownership to the given user and group.
497-
user and group may be specified by a number or
498-
by a name. if rec is True change ownership
499-
recursively.
500-
"""
501-
uid = getuserid(user)
502-
gid = getgroupid(group)
503-
if rec:
504-
for x in self.visit(rec=lambda x: x.check(link=0)):
505-
if x.check(link=0):
506-
error.checked_call(os.chown, str(x), uid, gid)
507-
error.checked_call(os.chown, str(self), uid, gid)
508-
509-
def readlink(self):
510-
"""Return value of a symbolic link."""
511-
return error.checked_call(os.readlink, self.strpath)
512-
513-
def mklinkto(self, oldname):
514-
"""Posix style hard link to another name."""
515-
error.checked_call(os.link, str(oldname), str(self))
516-
517-
def mksymlinkto(self, value, absolute=1):
518-
"""Create a symbolic link with the given value (pointing to another name)."""
519-
if absolute:
520-
error.checked_call(os.symlink, str(value), self.strpath)
521-
else:
522-
base = self.common(value)
523-
# with posix local paths '/' is always a common base
524-
relsource = self.__class__(value).relto(base)
525-
reldest = self.relto(base)
526-
n = reldest.count(self.sep)
527-
target = self.sep.join(("..",) * n + (relsource,))
528-
error.checked_call(os.symlink, target, self.strpath)
529-
530-
531494
def getuserid(user):
532495
import pwd
533496

@@ -544,10 +507,7 @@ def getgroupid(group):
544507
return group
545508

546509

547-
FSBase = not iswin32 and PosixPath or PathBase
548-
549-
550-
class LocalPath(FSBase):
510+
class LocalPath(PathBase):
551511
"""Object oriented interface to os.path and other local filesystem
552512
related information.
553513
"""
@@ -581,6 +541,43 @@ def __init__(self, path=None, expanduser=False):
581541
path = os.path.expanduser(path)
582542
self.strpath = abspath(path)
583543

544+
if sys.platform != "win32":
545+
546+
def chown(self, user, group, rec=0):
547+
"""Change ownership to the given user and group.
548+
user and group may be specified by a number or
549+
by a name. if rec is True change ownership
550+
recursively.
551+
"""
552+
uid = getuserid(user)
553+
gid = getgroupid(group)
554+
if rec:
555+
for x in self.visit(rec=lambda x: x.check(link=0)):
556+
if x.check(link=0):
557+
error.checked_call(os.chown, str(x), uid, gid)
558+
error.checked_call(os.chown, str(self), uid, gid)
559+
560+
def readlink(self):
561+
"""Return value of a symbolic link."""
562+
return error.checked_call(os.readlink, self.strpath)
563+
564+
def mklinkto(self, oldname):
565+
"""Posix style hard link to another name."""
566+
error.checked_call(os.link, str(oldname), str(self))
567+
568+
def mksymlinkto(self, value, absolute=1):
569+
"""Create a symbolic link with the given value (pointing to another name)."""
570+
if absolute:
571+
error.checked_call(os.symlink, str(value), self.strpath)
572+
else:
573+
base = self.common(value)
574+
# with posix local paths '/' is always a common base
575+
relsource = self.__class__(value).relto(base)
576+
reldest = self.relto(base)
577+
n = reldest.count(self.sep)
578+
target = self.sep.join(("..",) * n + (relsource,))
579+
error.checked_call(os.symlink, target, self.strpath)
580+
584581
def __hash__(self):
585582
s = self.strpath
586583
if iswin32:

0 commit comments

Comments
 (0)