Changeset 100

Show
Ignore:
Timestamp:
Tue Sep 19 13:56:15 2006
Author:
jpellerin
Message:

Fixed #91: adapted assert introspection to python 2.5, which reports different line numbers in tracebacks when continuations are used.

Files:

Legend:

Unmodified
Added
Removed
Modified
  • trunk/nose/inspector.py

    r31 r100  
    72 72     source lines in a traceback frame.  
    73 73     """  
      74      
    74 75     lineno = tb.tb_lineno  
    75 76     frame = tb.tb_frame  
     
    77 78     if context > 0:  
    78 79         start = lineno - 1 - context//2  
      80         log.debug("lineno: %s start: %s", lineno, start)  
      81  
      82          
    79 83         try:  
    80 84             lines, dummy = inspect.findsource(frame)  
     
    82 86             lines = index = None  
    83 87         else:  
      88             # python 2.5 compat: if previous line ends in a continuation,  
      89             # decrement start by 1 to match 2.4 behavior                 
    84 90             start = max(start, 1)  
    85 91             start = max(0, min(start, len(lines) - context))  
      92  
      93             all_lines = lines  
    86 94             lines = lines[start:start+context]  
    87 95             index = lineno - 1 - start  
      96             if sys.version_info >= (2, 5) and index > 0:  
      97                 while lines[index-1].strip().endswith('\\'):  
      98                     start -= 1  
      99                     lines = all_lines[start:start+context]  
    88 100     else:  
    89 101         lines = index = None  
      102     # log.debug("Inspecting lines '''%s''' around index %s", lines, index)  
    90 103     return (lines, index)     
    91 104