[py-svn] commit/pytest: gutworth: escape the % operator in string formatting

Bitbucket commits-noreply at bitbucket.org
Thu May 3 19:49:38 CEST 2012


1 new commit in pytest:


https://bitbucket.org/hpk42/pytest/changeset/7d6e61e16b40/
changeset:   7d6e61e16b40
user:        gutworth
date:        2012-05-03 19:49:30
summary:     escape the % operator in string formatting
affected #:  3 files

diff -r cb46ab12f7948bc1087ede40c3144a37407a3878 -r 7d6e61e16b40e169ce8781bbecbc0da201dcb85e CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 Changese between 2.2.3 and ...
 -----------------------------------
 
+- fix error message for rewritten assertions involving the % operator
 - fix issue 126: correctly match all invalid xml characters for junitxml
   binary escape
 - fix issue with unittest: now @unittest.expectedFailure markers should


diff -r cb46ab12f7948bc1087ede40c3144a37407a3878 -r 7d6e61e16b40e169ce8781bbecbc0da201dcb85e _pytest/assertion/rewrite.py
--- a/_pytest/assertion/rewrite.py
+++ b/_pytest/assertion/rewrite.py
@@ -297,7 +297,7 @@
     ast.Mult : "*",
     ast.Div : "/",
     ast.FloorDiv : "//",
-    ast.Mod : "%",
+    ast.Mod : "%%", # escaped for string formatting
     ast.Eq : "==",
     ast.NotEq : "!=",
     ast.Lt : "<",


diff -r cb46ab12f7948bc1087ede40c3144a37407a3878 -r 7d6e61e16b40e169ce8781bbecbc0da201dcb85e testing/test_assertrewrite.py
--- a/testing/test_assertrewrite.py
+++ b/testing/test_assertrewrite.py
@@ -195,6 +195,10 @@
             y = -1
             assert x + y
         assert getmsg(f) == "assert (1 + -1)"
+        def f():
+            x = range(10)
+            assert not 5 % 4
+        assert getmsg(f) == "assert not (5 % 4)"
 
     def test_call(self):
         def g(a=42, *args, **kwargs):

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