[Pytest-commit] commit/py: 2 new changesets

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Thu Aug 14 22:32:48 CEST 2014


2 new commits in py:

https://bitbucket.org/hpk42/py/commits/e5a98a808315/
Changeset:   e5a98a808315
User:        flub
Date:        2014-08-12 00:19:35
Summary:     Correct source extraction for else statements

If the else statement has more then the else on it the source lines
extraction would get it wrong and exclude the else line.  This
corrects the heuristic to include the else line if it contains
other code.

This is to fix issue 560 from py.test.
Affected #:  3 files

diff -r 591f6bfa83c0f26d503a57f60c3275d33a4208f0 -r e5a98a808315979d034a299066f41adbf6ac4052 py/_code/source.py
--- a/py/_code/source.py
+++ b/py/_code/source.py
@@ -377,8 +377,10 @@
         end = len(source.lines)
     while end:
         line = source.lines[end-1].lstrip()
-        if (not line or line.startswith("#") or line.startswith("else:") or
-            line.startswith("finally:")):
+        if (not line
+                or line.startswith("#")
+                or line.replace(" ", "") == "else:"
+                or line.replace(" ", "") == "finally:"):
             end -= 1
         else:
             break

diff -r 591f6bfa83c0f26d503a57f60c3275d33a4208f0 -r e5a98a808315979d034a299066f41adbf6ac4052 testing/code/test_code.py
--- a/testing/code/test_code.py
+++ b/testing/code/test_code.py
@@ -132,3 +132,28 @@
     fr4 = py.code.Frame(f4('a', 'b', c='d'))
     assert fr4.getargs(var=True) == [('x', 'a'), ('y', ('b',)),
                                      ('z', {'c': 'd'})]
+
+
+class TestExceptionInfo:
+
+    def test_bad_getsource(self):
+        try:
+            if False: pass
+            else: assert False
+        except AssertionError:
+            exci = py.code.ExceptionInfo()
+        assert exci.getrepr()
+
+
+class TestTracebackEntry:
+
+    def test_getsource(self):
+        try:
+            if False: pass
+            else: assert False
+        except AssertionError:
+            exci = py.code.ExceptionInfo()
+        entry = exci.traceback[0]
+        source = entry.getsource()
+        assert len(source) == 4
+        assert 'else: assert False' in source[3]

diff -r 591f6bfa83c0f26d503a57f60c3275d33a4208f0 -r e5a98a808315979d034a299066f41adbf6ac4052 testing/code/test_source.py
--- a/testing/code/test_source.py
+++ b/testing/code/test_source.py
@@ -489,6 +489,14 @@
     source = getstatement(0, "raise ValueError\n#hello")
     assert str(source) == "raise ValueError"
 
+def test_single_line_else():
+    source = getstatement(1, "if False: 2\nelse: 3")
+    assert str(source) == "else: 3"
+
+def test_single_line_finally():
+    source = getstatement(1, "try: 1\nfinally: 3")
+    assert str(source) == "finally: 3"
+
 def XXXtest_multiline():
     source = getstatement(0, """\
 raise ValueError(


https://bitbucket.org/hpk42/py/commits/5b72dc874706/
Changeset:   5b72dc874706
User:        flub
Date:        2014-08-12 00:44:45
Summary:     Mention fix in changelog and bump version
Affected #:  2 files

diff -r e5a98a808315979d034a299066f41adbf6ac4052 -r 5b72dc87470629b28be486be252b54a4fd3bcf13 CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,10 @@
+1.4.24
+==================================================
+
+- Fix retrieving source when an else: line has an other statement on
+  the same line.
+
+
 1.4.23
 ==================================================
 

diff -r e5a98a808315979d034a299066f41adbf6ac4052 -r 5b72dc87470629b28be486be252b54a4fd3bcf13 setup.py
--- a/setup.py
+++ b/setup.py
@@ -7,7 +7,7 @@
         name='py',
         description='library with cross-python path, ini-parsing, io, code, log facilities',
         long_description = open('README.txt').read(),
-        version='1.4.23',
+        version='1.4.24.dev1',
         url='http://pylib.readthedocs.org/',
         license='MIT license',
         platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],

Repository URL: https://bitbucket.org/hpk42/py/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.


More information about the pytest-commit mailing list