Skip to content

Commit

Permalink
Remove some dead code
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
asottile committed Jan 14, 2019
1 parent 0da5531 commit 16546b7
Show file tree
Hide file tree
Showing 13 changed files with 8 additions and 130 deletions.
5 changes: 0 additions & 5 deletions src/_pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
13 changes: 0 additions & 13 deletions src/_pytest/assertion/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
6 changes: 0 additions & 6 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
17 changes: 7 additions & 10 deletions src/_pytest/junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import time

import py
import six

import pytest
from _pytest import nodes
Expand All @@ -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):
Expand All @@ -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
Expand All @@ -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)))

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 0 additions & 10 deletions src/_pytest/reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 0 additions & 24 deletions src/_pytest/resultlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions src/_pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion testing/python/metafunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
29 changes: 0 additions & 29 deletions testing/test_resultlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
7 changes: 1 addition & 6 deletions testing/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion testing/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 0 additions & 11 deletions testing/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 16546b7

Please sign in to comment.