_pytest._py.path: combine Checkers classes
This commit is contained in:
parent
73349ef3e1
commit
af078f3a96
|
@ -35,12 +35,6 @@ class Checkers:
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
def dir(self):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def file(self):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def dotfile(self):
|
def dotfile(self):
|
||||||
return self.path.basename.startswith(".")
|
return self.path.basename.startswith(".")
|
||||||
|
|
||||||
|
@ -49,9 +43,6 @@ class Checkers:
|
||||||
arg = "." + arg
|
arg = "." + arg
|
||||||
return self.path.ext == arg
|
return self.path.ext == arg
|
||||||
|
|
||||||
def exists(self):
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def basename(self, arg):
|
def basename(self, arg):
|
||||||
return self.path.basename == arg
|
return self.path.basename == arg
|
||||||
|
|
||||||
|
@ -105,6 +96,29 @@ class Checkers:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _stat(self):
|
||||||
|
try:
|
||||||
|
return self._statcache
|
||||||
|
except AttributeError:
|
||||||
|
try:
|
||||||
|
self._statcache = self.path.stat()
|
||||||
|
except error.ELOOP:
|
||||||
|
self._statcache = self.path.lstat()
|
||||||
|
return self._statcache
|
||||||
|
|
||||||
|
def dir(self):
|
||||||
|
return S_ISDIR(self._stat().mode)
|
||||||
|
|
||||||
|
def file(self):
|
||||||
|
return S_ISREG(self._stat().mode)
|
||||||
|
|
||||||
|
def exists(self):
|
||||||
|
return self._stat()
|
||||||
|
|
||||||
|
def link(self):
|
||||||
|
st = self.path.lstat()
|
||||||
|
return S_ISLNK(st.mode)
|
||||||
|
|
||||||
|
|
||||||
class NeverRaised(Exception):
|
class NeverRaised(Exception):
|
||||||
pass
|
pass
|
||||||
|
@ -113,8 +127,6 @@ class NeverRaised(Exception):
|
||||||
class PathBase:
|
class PathBase:
|
||||||
"""shared implementation for filesystem path objects."""
|
"""shared implementation for filesystem path objects."""
|
||||||
|
|
||||||
Checkers = Checkers
|
|
||||||
|
|
||||||
def __div__(self, other):
|
def __div__(self, other):
|
||||||
return self.join(os.fspath(other))
|
return self.join(os.fspath(other))
|
||||||
|
|
||||||
|
@ -217,7 +229,7 @@ class PathBase:
|
||||||
"""
|
"""
|
||||||
if not kw:
|
if not kw:
|
||||||
kw = {"exists": 1}
|
kw = {"exists": 1}
|
||||||
return self.Checkers(self)._evaluate(kw)
|
return Checkers(self)._evaluate(kw)
|
||||||
|
|
||||||
def fnmatch(self, pattern):
|
def fnmatch(self, pattern):
|
||||||
"""Return true if the basename/fullname matches the glob-'pattern'.
|
"""Return true if the basename/fullname matches the glob-'pattern'.
|
||||||
|
@ -545,30 +557,6 @@ class LocalPath(FSBase):
|
||||||
|
|
||||||
sep = os.sep
|
sep = os.sep
|
||||||
|
|
||||||
class Checkers(Checkers):
|
|
||||||
def _stat(self):
|
|
||||||
try:
|
|
||||||
return self._statcache
|
|
||||||
except AttributeError:
|
|
||||||
try:
|
|
||||||
self._statcache = self.path.stat()
|
|
||||||
except error.ELOOP:
|
|
||||||
self._statcache = self.path.lstat()
|
|
||||||
return self._statcache
|
|
||||||
|
|
||||||
def dir(self):
|
|
||||||
return S_ISDIR(self._stat().mode)
|
|
||||||
|
|
||||||
def file(self):
|
|
||||||
return S_ISREG(self._stat().mode)
|
|
||||||
|
|
||||||
def exists(self):
|
|
||||||
return self._stat()
|
|
||||||
|
|
||||||
def link(self):
|
|
||||||
st = self.path.lstat()
|
|
||||||
return S_ISLNK(st.mode)
|
|
||||||
|
|
||||||
def __init__(self, path=None, expanduser=False):
|
def __init__(self, path=None, expanduser=False):
|
||||||
"""Initialize and return a local Path instance.
|
"""Initialize and return a local Path instance.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue