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