Merge pull request #4661 from asottile/more_py
remove and ban py.io.BytesIO, py.process, py.path.local.sysfind
This commit is contained in:
commit
1bcb2f91cc
|
@ -54,5 +54,14 @@ repos:
|
|||
- id: py-deprecated
|
||||
name: py library is deprecated
|
||||
language: pygrep
|
||||
entry: '\bpy\.(builtin\.|code\.|std\.|io\.saferepr)'
|
||||
entry: >
|
||||
(?x)\bpy\.(
|
||||
_code\.|
|
||||
builtin\.|
|
||||
code\.|
|
||||
io\.(BytesIO|saferepr)|
|
||||
path\.local\.sysfind|
|
||||
process\.|
|
||||
std\.
|
||||
)
|
||||
types: [python]
|
||||
|
|
|
@ -24,10 +24,10 @@ example: specifying and selecting acceptance tests
|
|||
pytest.skip("specify -A to run acceptance tests")
|
||||
self.tmpdir = request.config.mktemp(request.function.__name__, numbered=True)
|
||||
|
||||
def run(self, cmd):
|
||||
def run(self, *cmd):
|
||||
""" called by test code to execute an acceptance test. """
|
||||
self.tmpdir.chdir()
|
||||
return py.process.cmdexec(cmd)
|
||||
return subprocess.check_output(cmd).decode()
|
||||
|
||||
|
||||
and the actual test function example:
|
||||
|
@ -36,7 +36,7 @@ and the actual test function example:
|
|||
|
||||
def test_some_acceptance_aspect(accept):
|
||||
accept.tmpdir.mkdir("somesub")
|
||||
result = accept.run("ls -la")
|
||||
result = accept.run("ls", "-la")
|
||||
assert "somesub" in result
|
||||
|
||||
If you run this test without specifying a command line option
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
module containing a parametrized tests testing cross-python
|
||||
serialization via the pickle module.
|
||||
"""
|
||||
import distutils.spawn
|
||||
import subprocess
|
||||
import textwrap
|
||||
|
||||
import py
|
||||
|
||||
import pytest
|
||||
|
||||
pythonlist = ["python2.7", "python3.4", "python3.5"]
|
||||
|
@ -24,7 +24,7 @@ def python2(request, python1):
|
|||
|
||||
class Python(object):
|
||||
def __init__(self, version, picklefile):
|
||||
self.pythonpath = py.path.local.sysfind(version)
|
||||
self.pythonpath = distutils.spawn.find_executable(version)
|
||||
if not self.pythonpath:
|
||||
pytest.skip("{!r} not found".format(version))
|
||||
self.picklefile = picklefile
|
||||
|
@ -43,7 +43,7 @@ class Python(object):
|
|||
)
|
||||
)
|
||||
)
|
||||
py.process.cmdexec("{} {}".format(self.pythonpath, dumpfile))
|
||||
subprocess.check_call((self.pythonpath, str(dumpfile)))
|
||||
|
||||
def load_and_is_true(self, expression):
|
||||
loadfile = self.picklefile.dirpath("load.py")
|
||||
|
@ -63,7 +63,7 @@ class Python(object):
|
|||
)
|
||||
)
|
||||
print(loadfile)
|
||||
py.process.cmdexec("{} {}".format(self.pythonpath, loadfile))
|
||||
subprocess.check_call((self.pythonpath, str(loadfile)))
|
||||
|
||||
|
||||
@pytest.mark.parametrize("obj", [42, {}, {1: 3}])
|
||||
|
|
|
@ -14,10 +14,10 @@ import attr
|
|||
import py
|
||||
import six
|
||||
from more_itertools import flatten
|
||||
from py._code.code import FormattedExcinfo
|
||||
|
||||
import _pytest
|
||||
from _pytest import nodes
|
||||
from _pytest._code.code import FormattedExcinfo
|
||||
from _pytest._code.code import TerminalRepr
|
||||
from _pytest.compat import _format_args
|
||||
from _pytest.compat import _PytestWrapper
|
||||
|
|
|
@ -4,6 +4,7 @@ from __future__ import division
|
|||
from __future__ import print_function
|
||||
|
||||
import codecs
|
||||
import distutils.spawn
|
||||
import gc
|
||||
import os
|
||||
import platform
|
||||
|
@ -80,7 +81,7 @@ class LsofFdLeakChecker(object):
|
|||
|
||||
def _exec_lsof(self):
|
||||
pid = os.getpid()
|
||||
return py.process.cmdexec("lsof -Ffn0 -p %d" % pid)
|
||||
return subprocess.check_output(("lsof", "-Ffn0", "-p", str(pid))).decode()
|
||||
|
||||
def _parse_lsof_output(self, out):
|
||||
def isopen(line):
|
||||
|
@ -107,11 +108,8 @@ class LsofFdLeakChecker(object):
|
|||
|
||||
def matching_platform(self):
|
||||
try:
|
||||
py.process.cmdexec("lsof -v")
|
||||
except (py.process.cmdexec.Error, UnicodeDecodeError):
|
||||
# cmdexec may raise UnicodeDecodeError on Windows systems with
|
||||
# locale other than English:
|
||||
# https://bitbucket.org/pytest-dev/py/issues/66
|
||||
subprocess.check_output(("lsof", "-v"))
|
||||
except (OSError, subprocess.CalledProcessError):
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
@ -153,7 +151,7 @@ def getexecutable(name, cache={}):
|
|||
try:
|
||||
return cache[name]
|
||||
except KeyError:
|
||||
executable = py.path.local.sysfind(name)
|
||||
executable = distutils.spawn.find_executable(name)
|
||||
if executable:
|
||||
import subprocess
|
||||
|
||||
|
|
|
@ -936,7 +936,7 @@ class Metafunc(fixtures.FuncargnamesCompatAttr):
|
|||
:rtype: List[str]
|
||||
:return: the list of ids for each argname given
|
||||
"""
|
||||
from py.io import saferepr
|
||||
from _pytest._io.saferepr import saferepr
|
||||
|
||||
idfn = None
|
||||
if callable(ids):
|
||||
|
|
|
@ -4,8 +4,10 @@ from __future__ import division
|
|||
from __future__ import print_function
|
||||
|
||||
import contextlib
|
||||
import io
|
||||
import os
|
||||
import pickle
|
||||
import subprocess
|
||||
import sys
|
||||
import textwrap
|
||||
from io import UnsupportedOperation
|
||||
|
@ -851,7 +853,7 @@ class TestCaptureIO(object):
|
|||
|
||||
|
||||
def test_bytes_io():
|
||||
f = py.io.BytesIO()
|
||||
f = io.BytesIO()
|
||||
f.write(b"hello")
|
||||
with pytest.raises(TypeError):
|
||||
f.write(u"hello")
|
||||
|
@ -933,18 +935,18 @@ def test_dupfile(tmpfile):
|
|||
|
||||
|
||||
def test_dupfile_on_bytesio():
|
||||
io = py.io.BytesIO()
|
||||
f = capture.safe_text_dupfile(io, "wb")
|
||||
bio = io.BytesIO()
|
||||
f = capture.safe_text_dupfile(bio, "wb")
|
||||
f.write("hello")
|
||||
assert io.getvalue() == b"hello"
|
||||
assert bio.getvalue() == b"hello"
|
||||
assert "BytesIO object" in f.name
|
||||
|
||||
|
||||
def test_dupfile_on_textio():
|
||||
io = py.io.TextIO()
|
||||
f = capture.safe_text_dupfile(io, "wb")
|
||||
tio = py.io.TextIO()
|
||||
f = capture.safe_text_dupfile(tio, "wb")
|
||||
f.write("hello")
|
||||
assert io.getvalue() == "hello"
|
||||
assert tio.getvalue() == "hello"
|
||||
assert not hasattr(f, "name")
|
||||
|
||||
|
||||
|
@ -952,12 +954,12 @@ def test_dupfile_on_textio():
|
|||
def lsof_check():
|
||||
pid = os.getpid()
|
||||
try:
|
||||
out = py.process.cmdexec("lsof -p %d" % pid)
|
||||
except (py.process.cmdexec.Error, UnicodeDecodeError):
|
||||
out = subprocess.check_output(("lsof", "-p", str(pid))).decode()
|
||||
except (OSError, subprocess.CalledProcessError, UnicodeDecodeError):
|
||||
# about UnicodeDecodeError, see note on pytester
|
||||
pytest.skip("could not run 'lsof'")
|
||||
yield
|
||||
out2 = py.process.cmdexec("lsof -p %d" % pid)
|
||||
out2 = subprocess.check_output(("lsof", "-p", str(pid))).decode()
|
||||
len1 = len([x for x in out.split("\n") if "REG" in x])
|
||||
len2 = len([x for x in out2.split("\n") if "REG" in x])
|
||||
assert len2 < len1 + 3, out2
|
||||
|
|
|
@ -3,6 +3,7 @@ from __future__ import division
|
|||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import distutils.spawn
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
@ -296,7 +297,7 @@ class TestParser(object):
|
|||
|
||||
|
||||
def test_argcomplete(testdir, monkeypatch):
|
||||
if not py.path.local.sysfind("bash"):
|
||||
if not distutils.spawn.find_executable("bash"):
|
||||
pytest.skip("bash not available")
|
||||
script = str(testdir.tmpdir.join("test_argcomplete"))
|
||||
pytest_bin = sys.argv[0]
|
||||
|
|
Loading…
Reference in New Issue