[py-svn] commit/pytest: 2 new changesets

Bitbucket commits-noreply at bitbucket.org
Mon Jun 13 05:41:22 CEST 2011


2 new changesets in pytest:

http://bitbucket.org/hpk42/pytest/changeset/cca282422755/
changeset:   cca282422755
user:        gutworth
date:        2011-06-13 04:57:22
summary:     treat local as a black box
affected #:  1 file (16 bytes)

--- a/_pytest/assertion/newinterpret.py	Sun Jun 12 17:07:49 2011 -0500
+++ b/_pytest/assertion/newinterpret.py	Sun Jun 12 21:57:22 2011 -0500
@@ -152,8 +152,8 @@
             local = self.frame.eval(co)
         except Exception:
             # have to assume it isn't
-            local = False
-        if not self.frame.is_true(local):
+            local = None
+        if local is None or not self.frame.is_true(local):
             return name.id, result
         return explanation, result
 


http://bitbucket.org/hpk42/pytest/changeset/1c35b5d118fa/
changeset:   1c35b5d118fa
user:        gutworth
date:        2011-06-13 05:41:58
summary:     put explanation simplification in format_explanation so everyone can benefit
affected #:  4 files (1.2 KB)

--- a/_pytest/assertion/newinterpret.py	Sun Jun 12 21:57:22 2011 -0500
+++ b/_pytest/assertion/newinterpret.py	Sun Jun 12 22:41:58 2011 -0500
@@ -308,9 +308,6 @@
 
     def visit_Assert(self, assrt):
         test_explanation, test_result = self.visit(assrt.test)
-        if test_explanation.startswith("False\n{False =") and \
-                test_explanation.endswith("\n}"):
-            test_explanation = test_explanation[15:-2]
         explanation = "assert %s" % (test_explanation,)
         if not self.frame.is_true(test_result):
             try:


--- a/_pytest/assertion/oldinterpret.py	Sun Jun 12 21:57:22 2011 -0500
+++ b/_pytest/assertion/oldinterpret.py	Sun Jun 12 22:41:58 2011 -0500
@@ -384,10 +384,6 @@
     def run(self, frame):
         test = Interpretable(self.test)
         test.eval(frame)
-        # simplify 'assert False where False = ...'
-        if (test.explanation.startswith('False\n{False = ') and
-            test.explanation.endswith('\n}')):
-            test.explanation = test.explanation[15:-2]
         # print the result as  'assert <explanation>'
         self.result = test.result
         self.explanation = 'assert ' + test.explanation


--- a/_pytest/assertion/util.py	Sun Jun 12 21:57:22 2011 -0500
+++ b/_pytest/assertion/util.py	Sun Jun 12 22:41:58 2011 -0500
@@ -19,6 +19,28 @@
     for when one explanation needs to span multiple lines, e.g. when
     displaying diffs.
     """
+    # simplify 'assert False where False = ...'
+    where = 0
+    while True:
+        start = where = explanation.find("False\n{False = ", where)
+        if where == -1:
+            break
+        level = 0
+        for i, c in enumerate(explanation[start:]):
+            if c == "{":
+                level += 1
+            elif c == "}":
+                level -= 1
+                if not level:
+                    break
+        else:
+            raise AssertionError("unbalanced braces: %r" % (explanation,))
+        end = start + i
+        where = end
+        if explanation[end - 1] == '\n':
+            explanation = (explanation[:start] + explanation[start+15:end-1] +
+                           explanation[end+1:])
+            where -= 17
     raw_lines = (explanation or '').split('\n')
     # escape newlines not followed by {, } and ~
     lines = [raw_lines[0]]


--- a/testing/test_assertrewrite.py	Sun Jun 12 21:57:22 2011 -0500
+++ b/testing/test_assertrewrite.py	Sun Jun 12 22:41:58 2011 -0500
@@ -164,24 +164,19 @@
         ns = {"g" : g}
         def f():
             assert g()
-        assert getmsg(f, ns) == """assert False
- +  where False = g()"""
+        assert getmsg(f, ns) == """assert g()"""
         def f():
             assert g(1)
-        assert getmsg(f, ns) == """assert False
- +  where False = g(1)"""
+        assert getmsg(f, ns) == """assert g(1)"""
         def f():
             assert g(1, 2)
-        assert getmsg(f, ns) == """assert False
- +  where False = g(1, 2)"""
+        assert getmsg(f, ns) == """assert g(1, 2)"""
         def f():
             assert g(1, g=42)
-        assert getmsg(f, ns) == """assert False
- +  where False = g(1, g=42)"""
+        assert getmsg(f, ns) == """assert g(1, g=42)"""
         def f():
             assert g(1, 3, g=23)
-        assert getmsg(f, ns) == """assert False
- +  where False = g(1, 3, g=23)"""
+        assert getmsg(f, ns) == """assert g(1, 3, g=23)"""
 
     def test_attribute(self):
         class X(object):
@@ -194,8 +189,7 @@
         def f():
             x.a = False
             assert x.a
-        assert getmsg(f, ns) == """assert False
- +  where False = x.a"""
+        assert getmsg(f, ns) == """assert x.a"""
 
     def test_comparisons(self):
         def f():

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

--

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