1 new changeset in py:

http://bitbucket.org/hpk42/py/changeset/71dfb239aa60/
changeset:   r2003:71dfb239aa60
user:        flub
date:        2011-02-03 16:38:15
summary:     Don't hide values of builtins (issue8)

When a statement gets reinterpreted the current implementation goes
out of it's way to to not show the result of the call but rather the
call itself.  This means things like "len(l) == 42" will be shown as
"len([0, ...]) == 42" instead of the more desirable "666 == 42".  So
this patch reverts that behaviour to show the actual results of
builtins again.
affected #:  3 files (807 bytes)

--- a/CHANGELOG Thu Feb 03 15:16:18 2011 +0100
+++ b/CHANGELOG Thu Feb 03 15:38:15 2011 +0000
@@ -18,6 +18,8 @@
 
 - fix (pytest-) issue20 path.samefile(relpath) works as expected now
 
+- fix (pytest-) issue8 len(long_list) now shows the lenght of the list
+
 Changes between 1.3.4 and 1.4.0
 ==================================================
 


--- a/py/_code/_assertionnew.py Thu Feb 03 15:16:18 2011 +0100
+++ b/py/_code/_assertionnew.py Thu Feb 03 15:38:15 2011 +0000
@@ -267,20 +267,9 @@
             result = self.frame.eval(co, **ns)
         except Exception:
             raise Failure(explanation)
-        # Only show result explanation if it's not a builtin call or returns a
-        # bool.
-        if not isinstance(call.func, ast.Name) or \
-                not self._is_builtin_name(call.func):
-            source = "isinstance(__exprinfo_value, bool)"
-            co = self._compile(source)
-            try:
-                is_bool = self.frame.eval(co, __exprinfo_value=result)
-            except Exception:
-                is_bool = False
-            if not is_bool:
-                pattern = "%s\n{%s = %s\n}"
-                rep = self.frame.repr(result)
-                explanation = pattern % (rep, rep, explanation)
+        pattern = "%s\n{%s = %s\n}"
+        rep = self.frame.repr(result)
+        explanation = pattern % (rep, rep, explanation)
         return explanation, result
 
     def _is_builtin_name(self, name):


--- a/testing/code/test_assertion.py    Thu Feb 03 15:16:18 2011 +0100
+++ b/testing/code/test_assertion.py    Thu Feb 03 15:38:15 2011 +0000
@@ -105,6 +105,16 @@
         s = str(e)
         assert s.startswith("assert 1 == 2")
 
+def test_len():
+    l = list(xrange(42))
+    try:
+        assert len(l) == 100
+    except AssertionError:
+        e = exvalue()
+        s = str(e)
+        assert s.startswith("assert 42 == 100")
+        assert "where 42 = len([" in s
+
 def test_assert_non_string_message():
     class A:
         def __str__(self):

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.
_______________________________________________
py-svn mailing list
py-svn@codespeak.net
http://codespeak.net/mailman/listinfo/py-svn

Reply via email to