1 new changeset in pytest:

http://bitbucket.org/hpk42/pytest/changeset/3f58320421ee/
changeset:   3f58320421ee
user:        gutworth
date:        2011-07-20 04:42:00
summary:     escape '%' in specialized comparison explanations (fixes #63)
affected #:  3 files (562 bytes)

--- a/CHANGELOG Thu Jul 14 23:13:32 2011 +0200
+++ b/CHANGELOG Tue Jul 19 21:42:00 2011 -0500
@@ -1,6 +1,7 @@
 Changes between 2.1.0 and 2.1.1.DEV
 ----------------------------------------------
 
+- fix assertion rewriting on inserts involving strings containing '%'
 - fix assertion rewriting on calls with a ** arg
 - don't cache rewritten modules if bytecode generation is disabled
 - fix assertion rewriting in read-only directories


--- a/_pytest/assertion/__init__.py     Thu Jul 14 23:13:32 2011 +0200
+++ b/_pytest/assertion/__init__.py     Tue Jul 19 21:42:00 2011 -0500
@@ -45,7 +45,13 @@
                 config=config, op=op, left=left, right=right)
             for new_expl in hook_result:
                 if new_expl:
-                    return '\n~'.join(new_expl)
+                    res = '\n~'.join(new_expl)
+                    if mode == "rewrite":
+                        # The result will be fed back a python % formatting
+                        # operation, which will fail if there are extraneous
+                        # '%'s in the string. Escape them here.
+                        res = res.replace("%", "%%")
+                    return res
         m = monkeypatch()
         config._cleanup.append(m.undo)
         m.setattr(py.builtin.builtins, 'AssertionError',


--- a/testing/test_assertrewrite.py     Thu Jul 14 23:13:32 2011 +0200
+++ b/testing/test_assertrewrite.py     Tue Jul 19 21:42:00 2011 -0500
@@ -275,6 +275,11 @@
             assert myany(A() < 0)
         assert "<MY42 object>< 0" in getmsg(f)
 
+    def test_formatchar(self):
+        def f():
+            assert "%test" == "test"
+        assert getmsg(f).startswith("assert '%test' == 'test'")
+
 
 class TestRewriteOnImport:

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

Reply via email to