Skip to content

Commit 9e3e58a

Browse files
authored
Merge pull request #2594 from nicoddemus/fix-flake8-errors
Merge master into features and fix flake8 errors
2 parents eb79fa7 + d44565f commit 9e3e58a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+2220
-1406
lines changed

AUTHORS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Ahn Ki-Wook
99
Alexander Johnson
1010
Alexei Kozlenok
1111
Anatoly Bubenkoff
12+
Andras Tim
1213
Andreas Zeidler
1314
Andrzej Ostrowski
1415
Andy Freeland
@@ -104,6 +105,7 @@ Marcin Bachry
104105
Mark Abramowitz
105106
Markus Unterwaditzer
106107
Martijn Faassen
108+
Martin Altmayer
107109
Martin K. Scherer
108110
Martin Prusse
109111
Mathieu Clabaut

_pytest/_argcomplete.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,16 @@
6262
import os
6363
from glob import glob
6464

65+
6566
class FastFilesCompleter:
6667
'Fast file completer class'
68+
6769
def __init__(self, directories=True):
6870
self.directories = directories
6971

7072
def __call__(self, prefix, **kwargs):
7173
"""only called on non option completions"""
72-
if os.path.sep in prefix[1:]: #
74+
if os.path.sep in prefix[1:]:
7375
prefix_dir = len(os.path.dirname(prefix) + os.path.sep)
7476
else:
7577
prefix_dir = 0
@@ -98,5 +100,6 @@ def __call__(self, prefix, **kwargs):
98100
def try_argcomplete(parser):
99101
argcomplete.autocomplete(parser)
100102
else:
101-
def try_argcomplete(parser): pass
103+
def try_argcomplete(parser):
104+
pass
102105
filescompleter = None

_pytest/_code/_py2traceback.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from __future__ import absolute_import, division, print_function
66
import types
77

8+
89
def format_exception_only(etype, value):
910
"""Format the exception part of a traceback.
1011
@@ -30,7 +31,7 @@ def format_exception_only(etype, value):
3031
# would throw another exception and mask the original problem.
3132
if (isinstance(etype, BaseException) or
3233
isinstance(etype, types.InstanceType) or
33-
etype is None or type(etype) is str):
34+
etype is None or type(etype) is str):
3435
return [_format_final_exc_line(etype, value)]
3536

3637
stype = etype.__name__
@@ -62,6 +63,7 @@ def format_exception_only(etype, value):
6263
lines.append(_format_final_exc_line(stype, value))
6364
return lines
6465

66+
6567
def _format_final_exc_line(etype, value):
6668
"""Return a list of a single line -- normal case for format_exception_only"""
6769
valuestr = _some_str(value)
@@ -71,6 +73,7 @@ def _format_final_exc_line(etype, value):
7173
line = "%s: %s\n" % (etype, valuestr)
7274
return line
7375

76+
7477
def _some_str(value):
7578
try:
7679
return unicode(value)

_pytest/_code/code.py

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
class Code(object):
2020
""" wrapper around Python code objects """
21+
2122
def __init__(self, rawcode):
2223
if not hasattr(rawcode, "co_filename"):
2324
rawcode = getrawcode(rawcode)
@@ -26,7 +27,7 @@ def __init__(self, rawcode):
2627
self.firstlineno = rawcode.co_firstlineno - 1
2728
self.name = rawcode.co_name
2829
except AttributeError:
29-
raise TypeError("not a code object: %r" %(rawcode,))
30+
raise TypeError("not a code object: %r" % (rawcode,))
3031
self.raw = rawcode
3132

3233
def __eq__(self, other):
@@ -82,6 +83,7 @@ def getargs(self, var=False):
8283
argcount += raw.co_flags & CO_VARKEYWORDS
8384
return raw.co_varnames[:argcount]
8485

86+
8587
class Frame(object):
8688
"""Wrapper around a Python frame holding f_locals and f_globals
8789
in which expressions can be evaluated."""
@@ -119,7 +121,7 @@ def exec_(self, code, **vars):
119121
"""
120122
f_locals = self.f_locals.copy()
121123
f_locals.update(vars)
122-
py.builtin.exec_(code, self.f_globals, f_locals )
124+
py.builtin.exec_(code, self.f_globals, f_locals)
123125

124126
def repr(self, object):
125127
""" return a 'safe' (non-recursive, one-line) string repr for 'object'
@@ -143,6 +145,7 @@ def getargs(self, var=False):
143145
pass # this can occur when using Psyco
144146
return retval
145147

148+
146149
class TracebackEntry(object):
147150
""" a single entry in a traceback """
148151

@@ -168,7 +171,7 @@ def relline(self):
168171
return self.lineno - self.frame.code.firstlineno
169172

170173
def __repr__(self):
171-
return "<TracebackEntry %s:%d>" %(self.frame.code.path, self.lineno+1)
174+
return "<TracebackEntry %s:%d>" % (self.frame.code.path, self.lineno + 1)
172175

173176
@property
174177
def statement(self):
@@ -249,17 +252,19 @@ def __str__(self):
249252
raise
250253
except:
251254
line = "???"
252-
return " File %r:%d in %s\n %s\n" %(fn, self.lineno+1, name, line)
255+
return " File %r:%d in %s\n %s\n" % (fn, self.lineno + 1, name, line)
253256

254257
def name(self):
255258
return self.frame.code.raw.co_name
256259
name = property(name, None, None, "co_name of underlaying code")
257260

261+
258262
class Traceback(list):
259263
""" Traceback objects encapsulate and offer higher level
260264
access to Traceback entries.
261265
"""
262266
Entry = TracebackEntry
267+
263268
def __init__(self, tb, excinfo=None):
264269
""" initialize from given python traceback object and ExceptionInfo """
265270
self._excinfo = excinfo
@@ -289,7 +294,7 @@ def cut(self, path=None, lineno=None, firstlineno=None, excludepath=None):
289294
(excludepath is None or not hasattr(codepath, 'relto') or
290295
not codepath.relto(excludepath)) and
291296
(lineno is None or x.lineno == lineno) and
292-
(firstlineno is None or x.frame.code.firstlineno == firstlineno)):
297+
(firstlineno is None or x.frame.code.firstlineno == firstlineno)):
293298
return Traceback(x._rawentry, self._excinfo)
294299
return self
295300

@@ -315,7 +320,7 @@ def getcrashentry(self):
315320
""" return last non-hidden traceback entry that lead
316321
to the exception of a traceback.
317322
"""
318-
for i in range(-1, -len(self)-1, -1):
323+
for i in range(-1, -len(self) - 1, -1):
319324
entry = self[i]
320325
if not entry.ishidden():
321326
return entry
@@ -330,17 +335,17 @@ def recursionindex(self):
330335
# id for the code.raw is needed to work around
331336
# the strange metaprogramming in the decorator lib from pypi
332337
# which generates code objects that have hash/value equality
333-
#XXX needs a test
338+
# XXX needs a test
334339
key = entry.frame.code.path, id(entry.frame.code.raw), entry.lineno
335-
#print "checking for recursion at", key
340+
# print "checking for recursion at", key
336341
l = cache.setdefault(key, [])
337342
if l:
338343
f = entry.frame
339344
loc = f.f_locals
340345
for otherloc in l:
341346
if f.is_true(f.eval(co_equal,
342-
__recursioncache_locals_1=loc,
343-
__recursioncache_locals_2=otherloc)):
347+
__recursioncache_locals_1=loc,
348+
__recursioncache_locals_2=otherloc)):
344349
return i
345350
l.append(entry.frame.f_locals)
346351
return None
@@ -349,6 +354,7 @@ def recursionindex(self):
349354
co_equal = compile('__recursioncache_locals_1 == __recursioncache_locals_2',
350355
'?', 'eval')
351356

357+
352358
class ExceptionInfo(object):
353359
""" wraps sys.exc_info() objects and offers
354360
help for navigating the traceback.
@@ -405,10 +411,10 @@ def _getreprcrash(self):
405411
exconly = self.exconly(tryshort=True)
406412
entry = self.traceback.getcrashentry()
407413
path, lineno = entry.frame.code.raw.co_filename, entry.lineno
408-
return ReprFileLocation(path, lineno+1, exconly)
414+
return ReprFileLocation(path, lineno + 1, exconly)
409415

410416
def getrepr(self, showlocals=False, style="long",
411-
abspath=False, tbfilter=True, funcargs=False):
417+
abspath=False, tbfilter=True, funcargs=False):
412418
""" return str()able representation of this exception info.
413419
showlocals: show locals per traceback entry
414420
style: long|short|no|native traceback style
@@ -425,7 +431,7 @@ def getrepr(self, showlocals=False, style="long",
425431
)), self._getreprcrash())
426432

427433
fmt = FormattedExcinfo(showlocals=showlocals, style=style,
428-
abspath=abspath, tbfilter=tbfilter, funcargs=funcargs)
434+
abspath=abspath, tbfilter=tbfilter, funcargs=funcargs)
429435
return fmt.repr_excinfo(self)
430436

431437
def __str__(self):
@@ -469,7 +475,7 @@ def __init__(self, showlocals=False, style="long", abspath=True, tbfilter=True,
469475
def _getindent(self, source):
470476
# figure out indent for given source
471477
try:
472-
s = str(source.getstatement(len(source)-1))
478+
s = str(source.getstatement(len(source) - 1))
473479
except KeyboardInterrupt:
474480
raise
475481
except:
@@ -513,7 +519,7 @@ def get_source(self, source, line_index=-1, excinfo=None, short=False):
513519
for line in source.lines[:line_index]:
514520
lines.append(space_prefix + line)
515521
lines.append(self.flow_marker + " " + source.lines[line_index])
516-
for line in source.lines[line_index+1:]:
522+
for line in source.lines[line_index + 1:]:
517523
lines.append(space_prefix + line)
518524
if excinfo is not None:
519525
indent = 4 if short else self._getindent(source)
@@ -546,10 +552,10 @@ def repr_locals(self, locals):
546552
# _repr() function, which is only reprlib.Repr in
547553
# disguise, so is very configurable.
548554
str_repr = self._saferepr(value)
549-
#if len(str_repr) < 70 or not isinstance(value,
555+
# if len(str_repr) < 70 or not isinstance(value,
550556
# (list, tuple, dict)):
551-
lines.append("%-10s = %s" %(name, str_repr))
552-
#else:
557+
lines.append("%-10s = %s" % (name, str_repr))
558+
# else:
553559
# self._line("%-10s =\\" % (name,))
554560
# # XXX
555561
# py.std.pprint.pprint(value, stream=self.excinfowriter)
@@ -575,14 +581,14 @@ def repr_traceback_entry(self, entry, excinfo=None):
575581
s = self.get_source(source, line_index, excinfo, short=short)
576582
lines.extend(s)
577583
if short:
578-
message = "in %s" %(entry.name)
584+
message = "in %s" % (entry.name)
579585
else:
580586
message = excinfo and excinfo.typename or ""
581587
path = self._makepath(entry.path)
582-
filelocrepr = ReprFileLocation(path, entry.lineno+1, message)
588+
filelocrepr = ReprFileLocation(path, entry.lineno + 1, message)
583589
localsrepr = None
584590
if not short:
585-
localsrepr = self.repr_locals(entry.locals)
591+
localsrepr = self.repr_locals(entry.locals)
586592
return ReprEntry(lines, reprargs, localsrepr, filelocrepr, style)
587593
if excinfo:
588594
lines.extend(self.get_exconly(excinfo, indent=4))
@@ -645,7 +651,7 @@ def _truncate_recursive_traceback(self, traceback):
645651
traceback = traceback[:recursionindex + 1]
646652
else:
647653
extraline = None
648-
654+
649655
return traceback, extraline
650656

651657
def repr_excinfo(self, excinfo):
@@ -699,7 +705,7 @@ def __unicode__(self):
699705
return io.getvalue().strip()
700706

701707
def __repr__(self):
702-
return "<%s instance at %0x>" %(self.__class__, id(self))
708+
return "<%s instance at %0x>" % (self.__class__, id(self))
703709

704710

705711
class ExceptionRepr(TerminalRepr):
@@ -743,6 +749,7 @@ def toterminal(self, tw):
743749
self.reprtraceback.toterminal(tw)
744750
super(ReprExceptionInfo, self).toterminal(tw)
745751

752+
746753
class ReprTraceback(TerminalRepr):
747754
entrysep = "_ "
748755

@@ -758,20 +765,22 @@ def toterminal(self, tw):
758765
tw.line("")
759766
entry.toterminal(tw)
760767
if i < len(self.reprentries) - 1:
761-
next_entry = self.reprentries[i+1]
768+
next_entry = self.reprentries[i + 1]
762769
if entry.style == "long" or \
763770
entry.style == "short" and next_entry.style == "long":
764771
tw.sep(self.entrysep)
765772

766773
if self.extraline:
767774
tw.line(self.extraline)
768775

776+
769777
class ReprTracebackNative(ReprTraceback):
770778
def __init__(self, tblines):
771779
self.style = "native"
772780
self.reprentries = [ReprEntryNative(tblines)]
773781
self.extraline = None
774782

783+
775784
class ReprEntryNative(TerminalRepr):
776785
style = "native"
777786

@@ -781,6 +790,7 @@ def __init__(self, tblines):
781790
def toterminal(self, tw):
782791
tw.write("".join(self.lines))
783792

793+
784794
class ReprEntry(TerminalRepr):
785795
localssep = "_ "
786796

@@ -797,15 +807,15 @@ def toterminal(self, tw):
797807
for line in self.lines:
798808
red = line.startswith("E ")
799809
tw.line(line, bold=True, red=red)
800-
#tw.line("")
810+
# tw.line("")
801811
return
802812
if self.reprfuncargs:
803813
self.reprfuncargs.toterminal(tw)
804814
for line in self.lines:
805815
red = line.startswith("E ")
806816
tw.line(line, bold=True, red=red)
807817
if self.reprlocals:
808-
#tw.sep(self.localssep, "Locals")
818+
# tw.sep(self.localssep, "Locals")
809819
tw.line("")
810820
self.reprlocals.toterminal(tw)
811821
if self.reprfileloc:
@@ -818,6 +828,7 @@ def __str__(self):
818828
self.reprlocals,
819829
self.reprfileloc)
820830

831+
821832
class ReprFileLocation(TerminalRepr):
822833
def __init__(self, path, lineno, message):
823834
self.path = str(path)
@@ -834,6 +845,7 @@ def toterminal(self, tw):
834845
tw.write(self.path, bold=True, red=True)
835846
tw.line(":%s: %s" % (self.lineno, msg))
836847

848+
837849
class ReprLocals(TerminalRepr):
838850
def __init__(self, lines):
839851
self.lines = lines
@@ -842,6 +854,7 @@ def toterminal(self, tw):
842854
for line in self.lines:
843855
tw.line(line)
844856

857+
845858
class ReprFuncArgs(TerminalRepr):
846859
def __init__(self, args):
847860
self.args = args
@@ -850,11 +863,11 @@ def toterminal(self, tw):
850863
if self.args:
851864
linesofar = ""
852865
for name, value in self.args:
853-
ns = "%s = %s" %(name, value)
866+
ns = "%s = %s" % (name, value)
854867
if len(ns) + len(linesofar) + 2 > tw.fullwidth:
855868
if linesofar:
856869
tw.line(linesofar)
857-
linesofar = ns
870+
linesofar = ns
858871
else:
859872
if linesofar:
860873
linesofar += ", " + ns

0 commit comments

Comments
 (0)