[pypy-svn] pypy default: Actually run the warnings tests, they fail and I'm not sure why.

alex_gaynor commits-noreply at bitbucket.org
Tue Jan 18 19:48:54 CET 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r40897:5064c29f8012
Date: 2011-01-18 12:48 -0600
http://bitbucket.org/pypy/pypy/changeset/5064c29f8012/

Log:	Actually run the warnings tests, they fail and I'm not sure why.

diff --git a/pypy/objspace/std/test/test_newformat.py b/pypy/objspace/std/test/test_newformat.py
--- a/pypy/objspace/std/test/test_newformat.py
+++ b/pypy/objspace/std/test/test_newformat.py
@@ -102,6 +102,8 @@
         raises(ValueError, format, self.s(""), "\x234")
 
     def test_oldstyle_custom_format(self):
+        import warnings
+
         class C:
             def __init__(self, x=100):
                 self._x = x
@@ -134,23 +136,16 @@
         assert self.s("{0:d}").format(G("data")) == self.s("G(data)")
         assert self.s("{0!s}").format(G("data")) == self.s("string is data")
 
-        # XXX: run thests tests, self.space isn't available at app-level
-#        warnings = []
-#        def my_warn(msg, warning_cls):
-#            warnings.append((msg, warning_cls))
-#        prev_warning = self.space.warn
-#        space.warn = prev_warning
-#        expected_warning = [
-#            ("object.__format__ with a non-empty format string is deprecated", PendingDeprecationWarning)
-#        ]
-
-        assert self.s("{0:^10}").format(E("data")) == self.s(" E(data)  ")
-#        assert warnings == expected_warning
-        assert self.s("{0:^10s}").format(E("data")) == self.s(" E(data)  ")
-#        assert warnings == expected_warning * 2
-        assert self.s("{0:>15s}").format(G("data")) == self.s(" string is data")
-#        assert warnings == expected_warning * 3
-#        self.space.warn = prev_warn
+        expected_warning = [
+            ("object.__format__ with a non-empty format string is deprecated", PendingDeprecationWarning),
+        ]
+        with warnings.catch_warnings(record=True) as log:
+            assert self.s("{0:^10}").format(E("data")) == self.s(" E(data)  ")
+            assert log == expected_warning * 1
+            assert self.s("{0:^10s}").format(E("data")) == self.s(" E(data)  ")
+            assert log == expected_warning * 2
+            assert self.s("{0:>15s}").format(G("data")) == self.s(" string is data")
+            assert log == expected_warning * 3
 
 
 class AppTestUnicodeFormat(BaseStringFormatTests):


More information about the Pypy-commit mailing list