Skip to content

Commit

Permalink
Merge pull request #3614 from asottile/upgrade_hooks
Browse files Browse the repository at this point in the history
Upgrade hooks
  • Loading branch information
RonnyPfannschmidt authored Jun 26, 2018
2 parents 8133d19 + f940967 commit f93995e
Show file tree
Hide file tree
Showing 86 changed files with 311 additions and 633 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
exclude: doc/en/example/py2py3/test_py2.py
repos:
- repo: https://github.com/ambv/black
rev: 18.4a4
rev: 18.6b4
hooks:
- id: black
args: [--safe, --quiet]
language_version: python3.6
- repo: https://github.com/asottile/blacken-docs
rev: v0.1.1
rev: v0.2.0
hooks:
- id: blacken-docs
additional_dependencies: [black==18.5b1]
additional_dependencies: [black==18.6b4]
language_version: python3.6
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v1.2.3
rev: v1.3.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand Down
17 changes: 0 additions & 17 deletions doc/en/example/assertion/failure_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def pytest_generate_tests(metafunc):


class TestFailing(object):

def test_simple(self):

def f():
return 42

Expand All @@ -40,15 +38,13 @@ def test_simple_multiline(self):
otherfunc_multi(42, 6 * 9)

def test_not(self):

def f():
return 42

assert not f()


class TestSpecialisedExplanations(object):

def test_eq_text(self):
assert "spam" == "eggs"

Expand Down Expand Up @@ -106,7 +102,6 @@ def test_not_in_text_single_long_term(self):


def test_attribute():

class Foo(object):
b = 1

Expand All @@ -115,17 +110,14 @@ class Foo(object):


def test_attribute_instance():

class Foo(object):
b = 1

assert Foo().b == 2


def test_attribute_failure():

class Foo(object):

def _get_b(self):
raise Exception("Failed to get attrib")

Expand All @@ -136,7 +128,6 @@ def _get_b(self):


def test_attribute_multiple():

class Foo(object):
b = 1

Expand All @@ -151,7 +142,6 @@ def globf(x):


class TestRaises(object):

def test_raises(self):
s = "qwe" # NOQA
raises(TypeError, "int(s)")
Expand Down Expand Up @@ -193,9 +183,7 @@ def test_dynamic_compile_shows_nicely():


class TestMoreErrors(object):

def test_complex_error(self):

def f():
return 44

Expand All @@ -218,7 +206,6 @@ def test_startswith(self):
assert s.startswith(g)

def test_startswith_nested(self):

def f():
return "123"

Expand Down Expand Up @@ -246,17 +233,14 @@ def test_try_finally(self):


class TestCustomAssertMsg(object):

def test_single_line(self):

class A(object):
a = 1

b = 2
assert A.a == b, "A.a appears not to be b"

def test_multiline(self):

class A(object):
a = 1

Expand All @@ -266,7 +250,6 @@ class A(object):
), "A.a appears not to be b\n" "or does not appear to be b\none of those"

def test_custom_repr(self):

class JSON(object):
a = 1

Expand Down
2 changes: 1 addition & 1 deletion doc/en/example/assertion/test_failures.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import py

failure_demo = py.path.local(__file__).dirpath("failure_demo.py")
pytest_plugins = "pytester",
pytest_plugins = ("pytester",)


def test_failure_demo_fails_properly(testdir):
Expand Down
1 change: 0 additions & 1 deletion doc/en/example/assertion/test_setup_flow_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ def setup_module(module):


class TestStateFullThing(object):

def setup_class(cls):
cls.classcount += 1

Expand Down
1 change: 0 additions & 1 deletion doc/en/example/costlysetup/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def setup(request):


class CostlySetup(object):

def __init__(self):
import time

Expand Down
1 change: 0 additions & 1 deletion doc/en/example/multipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def python2(request, python1):


class Python(object):

def __init__(self, version, picklefile):
self.pythonpath = py.path.local.sysfind(version)
if not self.pythonpath:
Expand Down
2 changes: 0 additions & 2 deletions doc/en/example/nonpython/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def pytest_collect_file(parent, path):


class YamlFile(pytest.File):

def collect(self):
import yaml # we need a yaml parser, e.g. PyYAML

Expand All @@ -19,7 +18,6 @@ def collect(self):


class YamlItem(pytest.Item):

def __init__(self, name, parent, spec):
super(YamlItem, self).__init__(name, parent)
self.spec = spec
Expand Down
1 change: 0 additions & 1 deletion doc/en/example/py2py3/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class DummyCollector(pytest.collect.File):

def collect(self):
return []

Expand Down
1 change: 0 additions & 1 deletion doc/en/example/pythoncollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ def test_function():


class TestClass(object):

def test_method(self):
pass

Expand Down
39 changes: 20 additions & 19 deletions src/_pytest/_code/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ class Traceback(list):
""" Traceback objects encapsulate and offer higher level
access to Traceback entries.
"""

Entry = TracebackEntry

def __init__(self, tb, excinfo=None):
Expand Down Expand Up @@ -382,8 +383,11 @@ class ExceptionInfo(object):
""" wraps sys.exc_info() objects and offers
help for navigating the traceback.
"""

_striptext = ""
_assert_start_repr = "AssertionError(u'assert " if _PY2 else "AssertionError('assert "
_assert_start_repr = (
"AssertionError(u'assert " if _PY2 else "AssertionError('assert "
)

def __init__(self, tup=None, exprinfo=None):
import _pytest._code
Expand Down Expand Up @@ -424,7 +428,7 @@ def exconly(self, tryshort=False):
text = text.rstrip()
if tryshort:
if text.startswith(self._striptext):
text = text[len(self._striptext):]
text = text[len(self._striptext) :]
return text

def errisinstance(self, exc):
Expand Down Expand Up @@ -497,6 +501,7 @@ def match(self, regexp):
@attr.s
class FormattedExcinfo(object):
""" presenting information about failing Functions and Generators. """

# for traceback entries
flow_marker = ">"
fail_marker = "E"
Expand Down Expand Up @@ -556,7 +561,7 @@ def get_source(self, source, line_index=-1, excinfo=None, short=False):
for line in source.lines[:line_index]:
lines.append(space_prefix + line)
lines.append(self.flow_marker + " " + source.lines[line_index])
for line in source.lines[line_index + 1:]:
for line in source.lines[line_index + 1 :]:
lines.append(space_prefix + line)
if excinfo is not None:
indent = 4 if short else self._getindent(source)
Expand Down Expand Up @@ -691,7 +696,7 @@ def _truncate_recursive_traceback(self, traceback):
else:
if recursionindex is not None:
extraline = "!!! Recursion detected (same locals & position)"
traceback = traceback[:recursionindex + 1]
traceback = traceback[: recursionindex + 1]
else:
extraline = None

Expand Down Expand Up @@ -722,15 +727,19 @@ def repr_excinfo(self, excinfo):
repr_chain += [(reprtraceback, reprcrash, descr)]
if e.__cause__ is not None:
e = e.__cause__
excinfo = ExceptionInfo(
(type(e), e, e.__traceback__)
) if e.__traceback__ else None
excinfo = (
ExceptionInfo((type(e), e, e.__traceback__))
if e.__traceback__
else None
)
descr = "The above exception was the direct cause of the following exception:"
elif (e.__context__ is not None and not e.__suppress_context__):
elif e.__context__ is not None and not e.__suppress_context__:
e = e.__context__
excinfo = ExceptionInfo(
(type(e), e, e.__traceback__)
) if e.__traceback__ else None
excinfo = (
ExceptionInfo((type(e), e, e.__traceback__))
if e.__traceback__
else None
)
descr = "During handling of the above exception, another exception occurred:"
else:
e = None
Expand All @@ -739,7 +748,6 @@ def repr_excinfo(self, excinfo):


class TerminalRepr(object):

def __str__(self):
s = self.__unicode__()
if _PY2:
Expand All @@ -759,7 +767,6 @@ def __repr__(self):


class ExceptionRepr(TerminalRepr):

def __init__(self):
self.sections = []

Expand All @@ -773,7 +780,6 @@ def toterminal(self, tw):


class ExceptionChainRepr(ExceptionRepr):

def __init__(self, chain):
super(ExceptionChainRepr, self).__init__()
self.chain = chain
Expand All @@ -792,7 +798,6 @@ def toterminal(self, tw):


class ReprExceptionInfo(ExceptionRepr):

def __init__(self, reprtraceback, reprcrash):
super(ReprExceptionInfo, self).__init__()
self.reprtraceback = reprtraceback
Expand Down Expand Up @@ -831,7 +836,6 @@ def toterminal(self, tw):


class ReprTracebackNative(ReprTraceback):

def __init__(self, tblines):
self.style = "native"
self.reprentries = [ReprEntryNative(tblines)]
Expand Down Expand Up @@ -885,7 +889,6 @@ def __str__(self):


class ReprFileLocation(TerminalRepr):

def __init__(self, path, lineno, message):
self.path = str(path)
self.lineno = lineno
Expand All @@ -903,7 +906,6 @@ def toterminal(self, tw):


class ReprLocals(TerminalRepr):

def __init__(self, lines):
self.lines = lines

Expand All @@ -913,7 +915,6 @@ def toterminal(self, tw):


class ReprFuncArgs(TerminalRepr):

def __init__(self, args):
self.args = args

Expand Down
7 changes: 4 additions & 3 deletions src/_pytest/_code/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Source(object):
""" an immutable object holding a source code fragment,
possibly deindenting it.
"""

_compilecounter = 0

def __init__(self, *parts, **kwargs):
Expand Down Expand Up @@ -60,7 +61,7 @@ def __getitem__(self, key):
if key.step not in (None, 1):
raise IndexError("cannot slice a Source with a step")
newsource = Source()
newsource.lines = self.lines[key.start:key.stop]
newsource.lines = self.lines[key.start : key.stop]
return newsource

def __len__(self):
Expand Down Expand Up @@ -178,7 +179,7 @@ def compile(
except SyntaxError:
ex = sys.exc_info()[1]
# re-represent syntax errors from parsing python strings
msglines = self.lines[:ex.lineno]
msglines = self.lines[: ex.lineno]
if ex.offset:
msglines.append(" " * ex.offset + "^")
msglines.append("(code was compiled probably from here: %s)" % filename)
Expand Down Expand Up @@ -313,7 +314,7 @@ def readline_generator(lines):
except (IndentationError, tokenize.TokenError):
pass
# Add any lines we didn't see. E.g. if an exception was raised.
newlines.extend(lines[len(newlines):])
newlines.extend(lines[len(newlines) :])
return newlines


Expand Down
2 changes: 1 addition & 1 deletion src/_pytest/assertion/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def _rewrite_test(config, fn):
if (
not source.startswith(BOM_UTF8)
and cookie_re.match(source[0:end1]) is None
and cookie_re.match(source[end1 + 1:end2]) is None
and cookie_re.match(source[end1 + 1 : end2]) is None
):
if hasattr(state, "_indecode"):
# encodings imported us again, so don't rewrite.
Expand Down
Loading

0 comments on commit f93995e

Please sign in to comment.