Skip to content

Commit

Permalink
remove other py.* accesses in _pytest._py.path
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile committed Oct 19, 2022
1 parent f8169fc commit 1d5f957
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/_pytest/_py/path.py
Expand Up @@ -428,9 +428,9 @@ def __fspath__(self):

class Visitor:
def __init__(self, fil, rec, ignore, bf, sort):
if isinstance(fil, py.builtin._basestring):
if isinstance(fil, str):
fil = FNMatcher(fil)
if isinstance(rec, py.builtin._basestring):
if isinstance(rec, str):
self.rec = FNMatcher(rec)
elif not hasattr(rec, "__call__") and rec:
self.rec = lambda path: True
Expand Down Expand Up @@ -882,7 +882,7 @@ def listdir(self, fil=None, sort=None):
if fil is None and sort is None:
names = error.checked_call(os.listdir, self.strpath)
return map_as_list(self._fastjoin, names)
if isinstance(fil, py.builtin._basestring):
if isinstance(fil, str):
if not self._patternchars.intersection(fil):
child = self._fastjoin(fil)
if exists(child.strpath):
Expand Down Expand Up @@ -989,14 +989,14 @@ def write(self, data, mode="w", ensure=False):
if ensure:
self.dirpath().ensure(dir=1)
if "b" in mode:
if not py.builtin._isbytes(data):
if not isinstance(data, bytes):
raise ValueError("can only process bytes")
else:
if not py.builtin._istext(data):
if not py.builtin._isbytes(data):
if not isinstance(data, str):
if not isinstance(data, bytes):
data = str(data)
else:
data = py.builtin._totext(data, sys.getdefaultencoding())
data = data.decode(sys.getdefaultencoding())
f = self.open(mode)
try:
f.write(data)
Expand Down Expand Up @@ -1221,7 +1221,8 @@ def pyimport(self, modname=None, ensuresyspath=True):
mod.__file__ = str(self)
sys.modules[modname] = mod
try:
py.builtin.execfile(str(self), mod.__dict__)
with open(str(self), 'rb') as f:
exec(f.read(), mod.__dict__)
except:
del sys.modules[modname]
raise
Expand All @@ -1239,12 +1240,12 @@ def sysexec(self, *argv, **popen_opts):
proc = Popen([str(self)] + argv, **popen_opts)
stdout, stderr = proc.communicate()
ret = proc.wait()
if py.builtin._isbytes(stdout):
stdout = py.builtin._totext(stdout, sys.getdefaultencoding())
if isinstance(stdout, bytes):
stdout = stdout.decode(sys.getdefaultencoding())
if ret != 0:
if py.builtin._isbytes(stderr):
stderr = py.builtin._totext(stderr, sys.getdefaultencoding())
raise py.process.cmdexec.Error(
if isinstance(stderr, bytes):
stderr = stderr.decode(sys.getdefaultencoding())
raise RuntimeError(
ret,
ret,
str(self),
Expand All @@ -1262,7 +1263,7 @@ def sysfind(cls, name, checker=None, paths=None):
but may work on cygwin.
"""
if isabs(name):
p = py.path.local(name)
p = local(name)
if p.check(file=1):
return p
else:
Expand All @@ -1288,7 +1289,7 @@ def sysfind(cls, name, checker=None, paths=None):

for x in paths:
for addext in tryadd:
p = py.path.local(x).join(name, abs=True) + addext
p = local(x).join(name, abs=True) + addext
try:
if p.check(file=1):
if checker:
Expand Down Expand Up @@ -1323,7 +1324,7 @@ def get_temproot(cls):
"""
import tempfile

return py.path.local(tempfile.gettempdir())
return local(tempfile.gettempdir())

@classmethod
def mkdtemp(cls, rootdir=None):
Expand Down

0 comments on commit 1d5f957

Please sign in to comment.