31
31
32
32
33
33
class Code (object ):
34
- """ wrapper around Python code objects """
34
+ """wrapper around Python code objects"""
35
35
36
36
def __init__ (self , rawcode ):
37
37
if not hasattr (rawcode , "co_filename" ):
@@ -54,8 +54,8 @@ def __ne__(self, other):
54
54
55
55
@property
56
56
def path (self ):
57
- """ return a path object pointing to source code (note that it
58
- might not point to an actually existing file). """
57
+ """return a path object pointing to source code (note that it
58
+ might not point to an actually existing file)."""
59
59
try :
60
60
p = py .path .local (self .raw .co_filename )
61
61
# maybe don't try this checking
@@ -70,26 +70,24 @@ def path(self):
70
70
71
71
@property
72
72
def fullsource (self ):
73
- """ return a _pytest._code.Source object for the full source file of the code
74
- """
73
+ """return a _pytest._code.Source object for the full source file of the code"""
75
74
from _pytest ._code import source
76
75
77
76
full , _ = source .findsource (self .raw )
78
77
return full
79
78
80
79
def source (self ):
81
- """ return a _pytest._code.Source object for the code object's source only
82
- """
80
+ """return a _pytest._code.Source object for the code object's source only"""
83
81
# return source only for that part of code
84
82
import _pytest ._code
85
83
86
84
return _pytest ._code .Source (self .raw )
87
85
88
86
def getargs (self , var = False ):
89
- """ return a tuple with the argument names for the code object
87
+ """return a tuple with the argument names for the code object
90
88
91
- if 'var' is set True also return the names of the variable and
92
- keyword arguments when present
89
+ if 'var' is set True also return the names of the variable and
90
+ keyword arguments when present
93
91
"""
94
92
# handfull shortcut for getting args
95
93
raw = self .raw
@@ -113,46 +111,45 @@ def __init__(self, frame):
113
111
114
112
@property
115
113
def statement (self ):
116
- """ statement this frame is at """
114
+ """statement this frame is at"""
117
115
import _pytest ._code
118
116
119
117
if self .code .fullsource is None :
120
118
return _pytest ._code .Source ("" )
121
119
return self .code .fullsource .getstatement (self .lineno )
122
120
123
121
def eval (self , code , ** vars ):
124
- """ evaluate 'code' in the frame
122
+ """evaluate 'code' in the frame
125
123
126
- 'vars' are optional additional local variables
124
+ 'vars' are optional additional local variables
127
125
128
- returns the result of the evaluation
126
+ returns the result of the evaluation
129
127
"""
130
128
f_locals = self .f_locals .copy ()
131
129
f_locals .update (vars )
132
130
return eval (code , self .f_globals , f_locals )
133
131
134
132
def exec_ (self , code , ** vars ):
135
- """ exec 'code' in the frame
133
+ """exec 'code' in the frame
136
134
137
- 'vars' are optiona; additional local variables
135
+ 'vars' are optiona; additional local variables
138
136
"""
139
137
f_locals = self .f_locals .copy ()
140
138
f_locals .update (vars )
141
139
six .exec_ (code , self .f_globals , f_locals )
142
140
143
141
def repr (self , object ):
144
- """ return a 'safe' (non-recursive, one-line) string repr for 'object'
145
- """
142
+ """return a 'safe' (non-recursive, one-line) string repr for 'object'"""
146
143
return saferepr (object )
147
144
148
145
def is_true (self , object ):
149
146
return object
150
147
151
148
def getargs (self , var = False ):
152
- """ return a list of tuples (name, value) for all arguments
149
+ """return a list of tuples (name, value) for all arguments
153
150
154
- if 'var' is set True also include the variable and keyword
155
- arguments when present
151
+ if 'var' is set True also include the variable and keyword
152
+ arguments when present
156
153
"""
157
154
retval = []
158
155
for arg in self .code .getargs (var ):
@@ -164,7 +161,7 @@ def getargs(self, var=False):
164
161
165
162
166
163
class TracebackEntry (object ):
167
- """ a single entry in a traceback """
164
+ """a single entry in a traceback"""
168
165
169
166
_repr_style = None
170
167
exprinfo = None
@@ -193,13 +190,13 @@ def __repr__(self):
193
190
194
191
@property
195
192
def statement (self ):
196
- """ _pytest._code.Source object for the current statement """
193
+ """_pytest._code.Source object for the current statement"""
197
194
source = self .frame .code .fullsource
198
195
return source .getstatement (self .lineno )
199
196
200
197
@property
201
198
def path (self ):
202
- """ path to the source code """
199
+ """path to the source code"""
203
200
return self .frame .code .path
204
201
205
202
def getlocals (self ):
@@ -212,7 +209,7 @@ def getfirstlinesource(self):
212
209
return max (self .frame .code .firstlineno , 0 )
213
210
214
211
def getsource (self , astcache = None ):
215
- """ return failing source code. """
212
+ """return failing source code."""
216
213
# we use the passed in astcache to not reparse asttrees
217
214
# within exception info printing
218
215
from _pytest ._code .source import getstatementrange_ast
@@ -240,13 +237,13 @@ def getsource(self, astcache=None):
240
237
source = property (getsource )
241
238
242
239
def ishidden (self ):
243
- """ return True if the current frame has a var __tracebackhide__
244
- resolving to True.
240
+ """return True if the current frame has a var __tracebackhide__
241
+ resolving to True.
245
242
246
- If __tracebackhide__ is a callable, it gets called with the
247
- ExceptionInfo instance and can decide whether to hide the traceback.
243
+ If __tracebackhide__ is a callable, it gets called with the
244
+ ExceptionInfo instance and can decide whether to hide the traceback.
248
245
249
- mostly for internal use
246
+ mostly for internal use
250
247
"""
251
248
f = self .frame
252
249
tbh = f .f_locals .get (
@@ -277,14 +274,14 @@ def name(self):
277
274
278
275
279
276
class Traceback (list ):
280
- """ Traceback objects encapsulate and offer higher level
281
- access to Traceback entries.
277
+ """Traceback objects encapsulate and offer higher level
278
+ access to Traceback entries.
282
279
"""
283
280
284
281
Entry = TracebackEntry
285
282
286
283
def __init__ (self , tb , excinfo = None ):
287
- """ initialize from given python traceback object and ExceptionInfo """
284
+ """initialize from given python traceback object and ExceptionInfo"""
288
285
self ._excinfo = excinfo
289
286
if hasattr (tb , "tb_next" ):
290
287
@@ -298,14 +295,14 @@ def f(cur):
298
295
list .__init__ (self , tb )
299
296
300
297
def cut (self , path = None , lineno = None , firstlineno = None , excludepath = None ):
301
- """ return a Traceback instance wrapping part of this Traceback
298
+ """return a Traceback instance wrapping part of this Traceback
302
299
303
- by provding any combination of path, lineno and firstlineno, the
304
- first frame to start the to-be-returned traceback is determined
300
+ by provding any combination of path, lineno and firstlineno, the
301
+ first frame to start the to-be-returned traceback is determined
305
302
306
- this allows cutting the first part of a Traceback instance e.g.
307
- for formatting reasons (removing some uninteresting bits that deal
308
- with handling of the exception/traceback)
303
+ this allows cutting the first part of a Traceback instance e.g.
304
+ for formatting reasons (removing some uninteresting bits that deal
305
+ with handling of the exception/traceback)
309
306
"""
310
307
for x in self :
311
308
code = x .frame .code
@@ -330,19 +327,19 @@ def __getitem__(self, key):
330
327
return val
331
328
332
329
def filter (self , fn = lambda x : not x .ishidden ()):
333
- """ return a Traceback instance with certain items removed
330
+ """return a Traceback instance with certain items removed
334
331
335
- fn is a function that gets a single argument, a TracebackEntry
336
- instance, and should return True when the item should be added
337
- to the Traceback, False when not
332
+ fn is a function that gets a single argument, a TracebackEntry
333
+ instance, and should return True when the item should be added
334
+ to the Traceback, False when not
338
335
339
- by default this removes all the TracebackEntries which are hidden
340
- (see ishidden() above)
336
+ by default this removes all the TracebackEntries which are hidden
337
+ (see ishidden() above)
341
338
"""
342
339
return Traceback (filter (fn , self ), self ._excinfo )
343
340
344
341
def getcrashentry (self ):
345
- """ return last non-hidden traceback entry that lead
342
+ """return last non-hidden traceback entry that lead
346
343
to the exception of a traceback.
347
344
"""
348
345
for i in range (- 1 , - len (self ) - 1 , - 1 ):
@@ -352,8 +349,8 @@ def getcrashentry(self):
352
349
return self [- 1 ]
353
350
354
351
def recursionindex (self ):
355
- """ return the index of the frame/TracebackEntry where recursion
356
- originates if appropriate, None if no recursion occurred
352
+ """return the index of the frame/TracebackEntry where recursion
353
+ originates if appropriate, None if no recursion occurred
357
354
"""
358
355
cache = {}
359
356
for i , entry in enumerate (self ):
@@ -387,8 +384,8 @@ def recursionindex(self):
387
384
388
385
@attr .s (repr = False )
389
386
class ExceptionInfo (object ):
390
- """ wraps sys.exc_info() objects and offers
391
- help for navigating the traceback.
387
+ """wraps sys.exc_info() objects and offers
388
+ help for navigating the traceback.
392
389
"""
393
390
394
391
_assert_start_repr = (
@@ -426,8 +423,7 @@ def from_current(cls, exprinfo=None):
426
423
427
424
@classmethod
428
425
def for_later (cls ):
429
- """return an unfilled ExceptionInfo
430
- """
426
+ """return an unfilled ExceptionInfo"""
431
427
return cls (None )
432
428
433
429
@property
@@ -467,12 +463,12 @@ def __repr__(self):
467
463
return "<ExceptionInfo %s tblen=%d>" % (self .typename , len (self .traceback ))
468
464
469
465
def exconly (self , tryshort = False ):
470
- """ return the exception as a string
466
+ """return the exception as a string
471
467
472
- when 'tryshort' resolves to True, and the exception is a
473
- _pytest._code._AssertionError, only the actual exception part of
474
- the exception representation is returned (so 'AssertionError: ' is
475
- removed from the beginning)
468
+ when 'tryshort' resolves to True, and the exception is a
469
+ _pytest._code._AssertionError, only the actual exception part of
470
+ the exception representation is returned (so 'AssertionError: ' is
471
+ removed from the beginning)
476
472
"""
477
473
lines = format_exception_only (self .type , self .value )
478
474
text = "" .join (lines )
@@ -483,7 +479,7 @@ def exconly(self, tryshort=False):
483
479
return text
484
480
485
481
def errisinstance (self , exc ):
486
- """ return True if the exception is an instance of exc """
482
+ """return True if the exception is an instance of exc"""
487
483
return isinstance (self .value , exc )
488
484
489
485
def _getreprcrash (self ):
@@ -578,7 +574,7 @@ def match(self, regexp):
578
574
579
575
@attr .s
580
576
class FormattedExcinfo (object ):
581
- """ presenting information about failing Functions and Generators. """
577
+ """presenting information about failing Functions and Generators."""
582
578
583
579
# for traceback entries
584
580
flow_marker = ">"
@@ -625,7 +621,7 @@ def repr_args(self, entry):
625
621
return ReprFuncArgs (args )
626
622
627
623
def get_source (self , source , line_index = - 1 , excinfo = None , short = False ):
628
- """ return formatted and marked up source lines. """
624
+ """return formatted and marked up source lines."""
629
625
import _pytest ._code
630
626
631
627
lines = []
@@ -1024,7 +1020,7 @@ def toterminal(self, tw):
1024
1020
1025
1021
1026
1022
def getrawcode (obj , trycall = True ):
1027
- """ return code object for given function. """
1023
+ """return code object for given function."""
1028
1024
try :
1029
1025
return obj .__code__
1030
1026
except AttributeError :
@@ -1045,7 +1041,6 @@ def getrawcode(obj, trycall=True):
1045
1041
def is_recursion_error (excinfo ):
1046
1042
return excinfo .errisinstance (RecursionError ) # noqa
1047
1043
1048
-
1049
1044
else :
1050
1045
1051
1046
def is_recursion_error (excinfo ):
0 commit comments