Changeset 140
- Timestamp:
- Wed Dec 6 17:33:32 2006
- Files:
-
- trunk/CHANGELOG (modified) (diff)
- trunk/unit_tests/test_inspector.py (modified) (diff)
- trunk/nose/inspector.py (modified) (diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
trunk/CHANGELOG
r134 r140 13 13 when the two plugins are used together. Thanks to David Avraamides for the 14 14 bug report. 15 - Added isolation plugin. Use this plugin to automatically restore sys.modules 16 after each test module or package. Thanks to Michal Kwiatkowski for the 17 feature request. 18 - Fixed bug where -vvvv turned off verbose logging instead of making it even 19 more verbose. Thanks to Ian Bicking for the bug report. 15 20 16 21 0.9.1 -
trunk/unit_tests/test_inspector.py
r24 r140 111 111 et, ev, tb = sys.exc_info() 112 112 out = inspect_traceback(tb) 113 print "'%s'" % out.strip() 113 #print "'%s'" % out.strip() 113 113 self.assertEqual(out.strip(), 114 114 "assert {'setup': 1}['setup']\n" … … 117 117 ">> assert 1 % 2 == 0 or 3 % 2 == 0") 118 118 119 def test_bug_95(self): 120 """Test that inspector can handle multi-line docstrings""" 121 try: 122 """docstring line 1 123 docstring line 2 124 """ 125 a = 2 126 assert a == 4 127 except AssertionError: 128 et, ev, tb = sys.exc_info() 129 out = inspect_traceback(tb) 130 print "'%s'" % out.strip() 131 self.assertEqual(out.strip(), 132 "2 = 2\n" 133 ">> assert 2 == 4") 119 134 120 135 if __name__ == '__main__': 121 136 #import logging 122 137 #logging.basicConfig() 123 #logging.getLogger(' ').setLevel(0)138 #logging.getLogger('nose.inspector').setLevel(10) 123 138 unittest.main() 124 139 -
trunk/nose/inspector.py
r101 r140 33 33 34 34 # figure out the set of lines to grab. 35 working = True 35 36 inspect_lines, mark_line = find_inspectable_lines(lines, exc_line) 36 src = StringIO(textwrap.dedent(''.join(inspect_lines))) 37 while inspect_lines and working: 38 src = StringIO(textwrap.dedent(''.join(inspect_lines))) 37 39 38 # FIXME 39 # if a token error results, try just doing the one line, 40 # stripped of any \ it might have 41 exp = Expander(frame.f_locals, frame.f_globals) 42 try: 43 tokenize.tokenize(src.readline, exp) 44 except tokenize.TokenError: 45 pass 46 47 padded = [] 48 if exp.expanded_source: 49 exp_lines = exp.expanded_source.split('\n') 50 ep = 0 51 for line in exp_lines: 52 if ep == mark_line: 53 padded.append('>> ' + line) 54 else: 55 padded.append(' ' + line) 56 ep += 1 40 exp = Expander(frame.f_locals, frame.f_globals) 41 try: 42 tokenize.tokenize(src.readline, exp) 43 except tokenize.TokenError, e: 44 # this can happen if our inspectable region happens to butt up 45 # against the end of a construct like a docstring with the closing 46 # """ on separate line 47 log.debug("Tokenizer error: %s", e) 48 inspect_lines.pop(0) 49 mark_line -= 1 50 continue 51 52 working = False 53 padded = [] 54 if exp.expanded_source: 55 exp_lines = exp.expanded_source.split('\n') 56 ep = 0 57 for line in exp_lines: 58 if ep == mark_line: 59 padded.append('>> ' + line) 60 else: 61 padded.append(' ' + line) 62 ep += 1 57 63 return '\n'.join(padded) 58 64 … … 100 106 else: 101 107 lines = index = None 102 # log.debug("Inspectinglines '''%s''' around index %s", lines, index)108 log.debug("tbsource lines '''%s''' around index %s", lines, index) 102 108 return (lines, index) 103 109 … … 140 146 else: 141 147 break 148 log.debug("Inspecting lines '''%s''' around %s", toinspect, home_pos) 142 149 return toinspect, home_pos 143 150
