Merge pull request #4615 from asottile/some_dead_code

Remove some dead code
This commit is contained in:
Anthony Sottile 2019-01-14 07:35:21 -08:00 committed by GitHub
commit 5bb0be1e24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 8 additions and 130 deletions

View File

@ -23,8 +23,6 @@ from _pytest.compat import _PY3
from _pytest.compat import PY35
from _pytest.compat import safe_str
builtin_repr = repr
if _PY3:
from traceback import format_exception_only
else:
@ -947,8 +945,6 @@ class ReprEntryNative(TerminalRepr):
class ReprEntry(TerminalRepr):
localssep = "_ "
def __init__(self, lines, reprfuncargs, reprlocals, filelocrepr, style):
self.lines = lines
self.reprfuncargs = reprfuncargs
@ -970,7 +966,6 @@ class ReprEntry(TerminalRepr):
red = line.startswith("E ")
tw.line(line, bold=True, red=red)
if self.reprlocals:
# tw.sep(self.localssep, "Locals")
tw.line("")
self.reprlocals.toterminal(tw)
if self.reprfileloc:

View File

@ -51,19 +51,6 @@ else:
return ast.Call(a, b, c, None, None)
def ast_Call_helper(func_name, *args, **kwargs):
"""
func_name: str
args: Iterable[ast.expr]
kwargs: Dict[str,ast.expr]
"""
return ast.Call(
ast.Name(func_name, ast.Load()),
list(args),
[ast.keyword(key, val) for key, val in kwargs.items()],
)
class AssertionRewritingHook(object):
"""PEP302 Import hook which rewrites asserts."""

View File

@ -660,12 +660,6 @@ class SubRequest(FixtureRequest):
self._fixturedef.addfinalizer(finalizer)
class ScopeMismatchError(Exception):
""" A fixture function tries to use a different fixture function which
which has a lower scope (e.g. a Session one calls a function one)
"""
scopes = "session package module class function".split()
scopenum_function = scopes.index("function")

View File

@ -19,6 +19,7 @@ import sys
import time
import py
import six
import pytest
from _pytest import nodes
@ -27,10 +28,6 @@ from _pytest.config import filename_arg
# Python 2.X and 3.X compatibility
if sys.version_info[0] < 3:
from codecs import open
else:
unichr = chr
unicode = str
long = int
class Junit(py.xml.Namespace):
@ -45,12 +42,12 @@ class Junit(py.xml.Namespace):
_legal_chars = (0x09, 0x0A, 0x0D)
_legal_ranges = ((0x20, 0x7E), (0x80, 0xD7FF), (0xE000, 0xFFFD), (0x10000, 0x10FFFF))
_legal_xml_re = [
unicode("%s-%s") % (unichr(low), unichr(high))
u"%s-%s" % (six.unichr(low), six.unichr(high))
for (low, high) in _legal_ranges
if low < sys.maxunicode
]
_legal_xml_re = [unichr(x) for x in _legal_chars] + _legal_xml_re
illegal_xml_re = re.compile(unicode("[^%s]") % unicode("").join(_legal_xml_re))
_legal_xml_re = [six.unichr(x) for x in _legal_chars] + _legal_xml_re
illegal_xml_re = re.compile(u"[^%s]" % u"".join(_legal_xml_re))
del _legal_chars
del _legal_ranges
del _legal_xml_re
@ -62,9 +59,9 @@ def bin_xml_escape(arg):
def repl(matchobj):
i = ord(matchobj.group())
if i <= 0xFF:
return unicode("#x%02X") % i
return u"#x%02X" % i
else:
return unicode("#x%04X") % i
return u"#x%04X" % i
return py.xml.raw(illegal_xml_re.sub(repl, py.xml.escape(arg)))
@ -194,7 +191,7 @@ class _NodeReporter(object):
else:
if hasattr(report.longrepr, "reprcrash"):
message = report.longrepr.reprcrash.message
elif isinstance(report.longrepr, (unicode, str)):
elif isinstance(report.longrepr, six.string_types):
message = report.longrepr
else:
message = str(report.longrepr)

View File

@ -283,9 +283,6 @@ class PyobjMixin(PyobjContext):
s = ".".join(parts)
return s.replace(".[", "[")
def _getfslineno(self):
return getfslineno(self.obj)
def reportinfo(self):
# XXX caching?
obj = self.obj
@ -1252,7 +1249,6 @@ class Function(FunctionMixin, nodes.Item, fixtures.FuncargnamesCompatAttr):
Python test function.
"""
_genid = None
# disable since functions handle it themselves
_ALLOW_MARKERS = False
@ -1327,7 +1323,6 @@ class Function(FunctionMixin, nodes.Item, fixtures.FuncargnamesCompatAttr):
if hasattr(self, "callspec"):
callspec = self.callspec
assert not callspec.funcargs
self._genid = callspec.id
if hasattr(callspec, "param"):
self.param = callspec.param
self._request = fixtures.FixtureRequest(self)

View File

@ -158,16 +158,6 @@ class TestReport(BaseReport):
)
class TeardownErrorReport(BaseReport):
outcome = "failed"
when = "teardown"
def __init__(self, longrepr, **extra):
self.longrepr = longrepr
self.sections = []
self.__dict__.update(extra)
class CollectReport(BaseReport):
def __init__(self, nodeid, outcome, longrepr, result, sections=(), **extra):
self.nodeid = nodeid

View File

@ -47,30 +47,6 @@ def pytest_unconfigure(config):
config.pluginmanager.unregister(resultlog)
def generic_path(item):
chain = item.listchain()
gpath = [chain[0].name]
fspath = chain[0].fspath
fspart = False
for node in chain[1:]:
newfspath = node.fspath
if newfspath == fspath:
if fspart:
gpath.append(":")
fspart = False
else:
gpath.append(".")
else:
gpath.append("/")
fspart = True
name = node.name
if name[0] in "([":
gpath.pop()
gpath.append(name)
fspath = newfspath
return "".join(gpath)
class ResultLog(object):
def __init__(self, config, logfile):
self.config = config

View File

@ -841,15 +841,6 @@ class TerminalReporter(object):
self.write_line(msg, **markup)
def repr_pythonversion(v=None):
if v is None:
v = sys.version_info
try:
return "%s.%s.%s-%s-%s" % v
except (TypeError, ValueError):
return str(v)
def build_summary_stats_line(stats):
keys = ("failed passed skipped deselected xfailed xpassed warnings error").split()
unknown_key_seen = False

View File

@ -784,7 +784,6 @@ class TestMetafuncFunctional(object):
@pytest.fixture
def metafunc(request):
assert request._pyfuncitem._genid == "0"
return request.param
def test_function(metafunc, pytestconfig):

View File

@ -8,10 +8,6 @@ import py
import _pytest._code
import pytest
from _pytest.nodes import FSCollector
from _pytest.nodes import Item
from _pytest.nodes import Node
from _pytest.resultlog import generic_path
from _pytest.resultlog import pytest_configure
from _pytest.resultlog import pytest_unconfigure
from _pytest.resultlog import ResultLog
@ -20,31 +16,6 @@ from _pytest.resultlog import ResultLog
pytestmark = pytest.mark.filterwarnings("ignore:--result-log is deprecated")
def test_generic_path(testdir):
from _pytest.main import Session
config = testdir.parseconfig()
session = Session(config)
p1 = Node("a", config=config, session=session, nodeid="a")
# assert p1.fspath is None
p2 = Node("B", parent=p1)
p3 = Node("()", parent=p2)
item = Item("c", parent=p3)
res = generic_path(item)
assert res == "a.B().c"
p0 = FSCollector("proj/test", config=config, session=session)
p1 = FSCollector("proj/test/a", parent=p0)
p2 = Node("B", parent=p1)
p3 = Node("()", parent=p2)
p4 = Node("c", parent=p3)
item = Item("[1]", parent=p4)
res = generic_path(item)
assert res == "test/a:B().c[1]"
def test_write_log_entry():
reslog = ResultLog(None, None)
reslog.logfile = py.io.TextIO()

View File

@ -465,12 +465,7 @@ class TestSessionReports(object):
assert res[1].name == "TestClass"
reporttypes = [
reports.BaseReport,
reports.TestReport,
reports.TeardownErrorReport,
reports.CollectReport,
]
reporttypes = [reports.BaseReport, reports.TestReport, reports.CollectReport]
@pytest.mark.parametrize(

View File

@ -181,7 +181,6 @@ class TestNewSession(SessionTests):
passed, skipped, failed = reprec.countoutcomes()
assert failed == skipped == 0
assert passed == 7
# also test listnames() here ...
def test_collect_only_with_various_situations(self, testdir):
p = testdir.makepyfile(

View File

@ -18,7 +18,6 @@ from _pytest.main import EXIT_NOTESTSCOLLECTED
from _pytest.terminal import _plugin_nameversions
from _pytest.terminal import build_summary_stats_line
from _pytest.terminal import getreportopt
from _pytest.terminal import repr_pythonversion
from _pytest.terminal import TerminalReporter
DistInfo = collections.namedtuple("DistInfo", ["project_name", "version"])
@ -361,16 +360,6 @@ class TestCollectonly(object):
result.stdout.fnmatch_lines(["*test_fun.py: 1*"])
def test_repr_python_version(monkeypatch):
try:
monkeypatch.setattr(sys, "version_info", (2, 5, 1, "final", 0))
assert repr_pythonversion() == "2.5.1-final-0"
sys.version_info = x = (2, 3)
assert repr_pythonversion() == str(x)
finally:
monkeypatch.undo() # do this early as pytest can get confused
class TestFixtureReporting(object):
def test_setup_fixture_error(self, testdir):
testdir.makepyfile(