# HG changeset patch -- Bitbucket.org
# Project py
# URL http://bitbucket.org/hpk42/py/overview
# User holger krekel <hol...@merlinux.eu>
# Date 1290535574 -3600
# Node ID 85a43322235d4d67a4e1d41226847fa977544291
# Parent  acc532fe1fcaa6effcc820afa7b8a80502cd00e8
improve assertion heuristics - the starting line needs to contain "assert " now

--- a/setup.py
+++ b/setup.py
@@ -9,7 +9,7 @@ def main():
         name='py',
         description='library with cross-python path, ini-parsing, io, code, 
log facilities',
         long_description = open('README.txt').read(),
-        version='1.4.0a2',
+        version='1.4.0a3',
         url='http://pylib.org',
         license='MIT license',
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],

--- a/testing/code/test_assertion.py
+++ b/testing/code/test_assertion.py
@@ -251,3 +251,15 @@ def test_assert_customizable_reprcompare
         e = exvalue()
         s = str(e)
         assert "hello" in s
+
+def test_assert_long_source():
+    result = None
+    try:
+        assert result == [
+            (None, ['somet text', 'more text']),
+        ]
+    except AssertionError:
+        e = exvalue()
+        s = str(e)
+        assert 're-run' not in s
+        assert 'somet text' in s

--- a/py/_code/assertion.py
+++ b/py/_code/assertion.py
@@ -63,8 +63,10 @@ class AssertionError(BuiltinAssertionErr
         else:
             f = py.code.Frame(sys._getframe(1))
             try:
-                source = f.statement
-                source = str(source.deindent()).strip()
+                source = f.code.fullsource
+                if source is not None:
+                    source = source.getstatement(f.lineno, assertion=True)
+                    source = str(source.deindent()).strip()
             except py.error.ENOENT:
                 source = None
                 # this can also occur during reinterpretation, when the

--- a/py/_code/source.py
+++ b/py/_code/source.py
@@ -98,14 +98,14 @@ class Source(object):
         newsource.lines = [(indent+line) for line in self.lines]
         return newsource
 
-    def getstatement(self, lineno):
+    def getstatement(self, lineno, assertion=False):
         """ return Source statement which contains the
             given linenumber (counted from 0).
         """
-        start, end = self.getstatementrange(lineno)
+        start, end = self.getstatementrange(lineno, assertion)
         return self[start:end]
 
-    def getstatementrange(self, lineno):
+    def getstatementrange(self, lineno, assertion=False):
         """ return (start, end) tuple which spans the minimal
             statement region which containing the given lineno.
         """
@@ -117,6 +117,10 @@ class Source(object):
         # 1. find the start of the statement
         from codeop import compile_command
         for start in range(lineno, -1, -1):
+            if assertion:
+                if "assert " not in self.lines[start]:
+                    continue
+                
             trylines = self.lines[start:lineno+1]
             # quick hack to indent the source and get it as a string in one go
             trylines.insert(0, 'def xxx():')

--- a/py/__init__.py
+++ b/py/__init__.py
@@ -8,7 +8,7 @@ dictionary or an import path.
 
 (c) Holger Krekel and others, 2004-2010
 """
-__version__ = '2.0.0.dev8'
+__version__ = '1.4.0a3'
 
 from py import _apipkg
_______________________________________________
py-svn mailing list
py-svn@codespeak.net
http://codespeak.net/mailman/listinfo/py-svn

Reply via email to