Commits

holger krekel committed 2366418

help to fix pytest issue99: unify output of
ExceptionInfo.getrepr(style="native") with ...(style="long")

  • Participants
  • Parent commits bb527bc

Comments (0)

Files changed (5)

 Changes between 1.4.5 and 1.4.x
 ==================================================
 
+- help to fix pytest issue99: unify output of 
+  ExceptionInfo.getrepr(style="native") with ...(style="long")
 - fix issue7: source.getstatementrange() now raises proper error
   if no valid statement can be found
 - fix issue8: fix code and tests of svnurl/svnwc to work on subversion 1.7 - 

File py/__init__.py

 
 (c) Holger Krekel and others, 2004-2010
 """
-__version__ = '1.4.6.dev3'
+__version__ = '1.4.6.dev4'
 
 from py import _apipkg
 

File py/_code/code.py

         """
         cache = {}
         for i, entry in enumerate(self):
-            # id for the code.raw is needed to work around 
+            # id for the code.raw is needed to work around
             # the strange metaprogramming in the decorator lib from pypi
             # which generates code objects that have hash/value equality
             #XXX needs a test
             showlocals: show locals per traceback entry
             style: long|short|no|native traceback style
             tbfilter: hide entries (where __tracebackhide__ is true)
+
+            in case of style==native, tbfilter and showlocals is ignored.
         """
         if style == 'native':
-            import traceback
-            return ''.join(traceback.format_exception(
-                self.type,
-                self.value,
-                self.traceback[0]._rawentry,
-                ))
+            return ReprExceptionInfo(ReprTracebackNative(
+                py.std.traceback.format_exception(
+                    self.type,
+                    self.value,
+                    self.traceback[0]._rawentry,
+                )), self._getreprcrash())
 
         fmt = FormattedExcinfo(showlocals=showlocals, style=style,
             abspath=abspath, tbfilter=tbfilter, funcargs=funcargs)
         if self.extraline:
             tw.line(self.extraline)
 
+class ReprTracebackNative(ReprTraceback):
+    def __init__(self, tblines):
+        self.style = "native"
+        self.reprentries = [ReprEntryNative(tblines)]
+        self.extraline = None
+
+class ReprEntryNative(TerminalRepr):
+    def __init__(self, tblines):
+        self.lines = tblines
+
+    def toterminal(self, tw):
+        tw.write("".join(self.lines))
+
 class ReprEntry(TerminalRepr):
     localssep = "_ "
 
         name='py',
         description='library with cross-python path, ini-parsing, io, code, log facilities',
         long_description = open('README.txt').read(),
-        version='1.4.6.dev3',
+        version='1.4.6.dev4',
         url='http://pylib.org',
         license='MIT license',
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],

File testing/code/test_excinfo.py

     def test_traceback_messy_recursion(self):
         #XXX: simplified locally testable version
         decorator = py.test.importorskip('decorator').decorator
-        
+
         def log(f, *k, **kw):
             print('%s %s' % (k, kw))
             f(*k, **kw)
             assert 0
         """)
         repr = excinfo.getrepr(style='native')
-        assert repr.startswith('Traceback (most recent call last):\n  File')
-        assert repr.endswith('\nAssertionError: assert 0\n')
-        assert 'exec (source.compile())' in repr
+        assert "assert 0" in str(repr.reprcrash)
+        s = str(repr)
+        assert s.startswith('Traceback (most recent call last):\n  File')
+        assert s.endswith('\nAssertionError: assert 0')
+        assert 'exec (source.compile())' in s
         # python 2.4 fails to get the source line for the assert
         if py.std.sys.version_info >= (2, 5):
-            assert repr.count('assert 0') == 2
+            assert s.count('assert 0') == 2