From 16546b73420ed69401e19495e9f6dafe11a06968 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Mon, 7 Jan 2019 20:46:57 -0800 Subject: [PATCH] Remove some dead code - I wrote a thing: https://github.com/asottile/dead - wanted to try it out, there's lots of false positives and I didn't look through all the things it pointed out but here's some --- src/_pytest/_code/code.py | 5 ----- src/_pytest/assertion/rewrite.py | 13 ------------- src/_pytest/fixtures.py | 6 ------ src/_pytest/junitxml.py | 17 +++++++---------- src/_pytest/python.py | 5 ----- src/_pytest/reports.py | 10 ---------- src/_pytest/resultlog.py | 24 ------------------------ src/_pytest/terminal.py | 9 --------- testing/python/metafunc.py | 1 - testing/test_resultlog.py | 29 ----------------------------- testing/test_runner.py | 7 +------ testing/test_session.py | 1 - testing/test_terminal.py | 11 ----------- 13 files changed, 8 insertions(+), 130 deletions(-) diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py index 1b49fe75bbb..4473547d6bf 100644 --- a/src/_pytest/_code/code.py +++ b/src/_pytest/_code/code.py @@ -23,8 +23,6 @@ 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 @@ def toterminal(self, tw): class ReprEntry(TerminalRepr): - localssep = "_ " - def __init__(self, lines, reprfuncargs, reprlocals, filelocrepr, style): self.lines = lines self.reprfuncargs = reprfuncargs @@ -970,7 +966,6 @@ def toterminal(self, tw): 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: diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py index 1d2c27ed152..eae63acee04 100644 --- a/src/_pytest/assertion/rewrite.py +++ b/src/_pytest/assertion/rewrite.py @@ -51,19 +51,6 @@ def ast_Call(a, b, c): 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.""" diff --git a/src/_pytest/fixtures.py b/src/_pytest/fixtures.py index 0a1f258e571..5f288787e6f 100644 --- a/src/_pytest/fixtures.py +++ b/src/_pytest/fixtures.py @@ -660,12 +660,6 @@ def addfinalizer(self, finalizer): 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") diff --git a/src/_pytest/junitxml.py b/src/_pytest/junitxml.py index 1a06ea6d1fb..a426f537b1c 100644 --- a/src/_pytest/junitxml.py +++ b/src/_pytest/junitxml.py @@ -19,6 +19,7 @@ import time import py +import six import pytest from _pytest import nodes @@ -27,10 +28,6 @@ # 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 @@ def append_failure(self, report): 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) diff --git a/src/_pytest/python.py b/src/_pytest/python.py index 48a50178f65..1da422b5de6 100644 --- a/src/_pytest/python.py +++ b/src/_pytest/python.py @@ -283,9 +283,6 @@ def getmodpath(self, stopatmodule=True, includemodule=False): 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 @@ def _initrequest(self): 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) diff --git a/src/_pytest/reports.py b/src/_pytest/reports.py index b2010cc2e9d..6ea5798cf45 100644 --- a/src/_pytest/reports.py +++ b/src/_pytest/reports.py @@ -158,16 +158,6 @@ def __repr__(self): ) -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 diff --git a/src/_pytest/resultlog.py b/src/_pytest/resultlog.py index bdf8130fdd5..a2dd7309485 100644 --- a/src/_pytest/resultlog.py +++ b/src/_pytest/resultlog.py @@ -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 diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index bea02306bca..c1d4d1f9194 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -841,15 +841,6 @@ def summary_stats(self): 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 diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index 54a6ecb91c2..5c352efd14f 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -784,7 +784,6 @@ def pytest_generate_tests(metafunc): @pytest.fixture def metafunc(request): - assert request._pyfuncitem._genid == "0" return request.param def test_function(metafunc, pytestconfig): diff --git a/testing/test_resultlog.py b/testing/test_resultlog.py index cb7b0cd3ce7..2c5175246d2 100644 --- a/testing/test_resultlog.py +++ b/testing/test_resultlog.py @@ -8,10 +8,6 @@ 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 @@ 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() diff --git a/testing/test_runner.py b/testing/test_runner.py index 91f7d270013..66ae702a44c 100644 --- a/testing/test_runner.py +++ b/testing/test_runner.py @@ -465,12 +465,7 @@ class TestClass(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( diff --git a/testing/test_session.py b/testing/test_session.py index d68fc9d4181..d64a1a51978 100644 --- a/testing/test_session.py +++ b/testing/test_session.py @@ -181,7 +181,6 @@ def test_4(self): 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( diff --git a/testing/test_terminal.py b/testing/test_terminal.py index 06345f88d5d..c0dd21bc246 100644 --- a/testing/test_terminal.py +++ b/testing/test_terminal.py @@ -18,7 +18,6 @@ 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 @@ def test_collectonly_more_quiet(self, testdir): 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(