# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview
# User holger krekel <hol...@merlinux.eu>
# Date 1280400939 -7200
# Node ID 6fa2ed846f692ecceb8ef5b5b4292f65ba4bd0e0
# Parent  fa64ba4988bfdb0cf57f0332d1ff66cab04b374d
fixes issue113 - assertion represenation issue

--- a/testing/code/test_source.py
+++ b/testing/code/test_source.py
@@ -176,6 +176,13 @@ class TestSourceParsingAndCompiling:
             #x = s.deindent()
             assert str(s) == ass
 
+    def test_getstatementrange_triple_quoted(self):
+        #print str(self.source)
+        source = Source("""'''
+        '''""")
+        s = source.getstatement(1)
+        assert eval(str(s))
+
     def test_getstatementrange_within_constructs(self):
         source = Source("""\
             try:

--- a/testing/plugin/test_pytest_assertion.py
+++ b/testing/plugin/test_pytest_assertion.py
@@ -9,6 +9,17 @@ def test_functional(testdir):
     result = testdir.runpytest("--no-assert")
     assert "3 == 4" not in result.stdout.str()
 
+def test_triple_quoted_string_issue113(testdir):
+    testdir.makepyfile("""
+        def test_hello():
+            assert "" == '''
+    '''""")
+    result = testdir.runpytest("--fulltrace")
+    result.stdout.fnmatch_lines([
+        "*1 failed*",
+    ])
+    assert 'SyntaxError' not in result.stdout.str()
+
 def test_traceback_failure(testdir):
     p1 = testdir.makepyfile("""
         def g():

--- a/py/_code/source.py
+++ b/py/_code/source.py
@@ -125,16 +125,13 @@ class Source(object):
             try:
                 compile_command(trysource)
             except (SyntaxError, OverflowError, ValueError):
-                pass
-            else:
-                break   # got a valid or incomplete statement
+                continue
 
-        # 2. find the end of the statement
-        for end in range(lineno+1, len(self)+1):
-            trysource = self[start:end]
-            if trysource.isparseable():
-                break
-
+            # 2. find the end of the statement
+            for end in range(lineno+1, len(self)+1):
+                trysource = self[start:end]
+                if trysource.isparseable():
+                    return start, end
         return start, end
 
     def getblockend(self, lineno):

--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,8 @@
 Changes between 1.3.2 and 1.3.3a1
 ==================================================
 
+- fix issue113: assertion representation problem with triple-quoted strings 
+  (and possibly other cases)
 - make conftest loading detect that a conftest file with the same 
   content was already loaded, avoids surprises in nested directory structures
   that can be produced e.g. by Hudson. It alleviates the need to use
_______________________________________________
py-svn mailing list
py-svn@codespeak.net
http://codespeak.net/mailman/listinfo/py-svn

Reply via email to