Merged revisions 77871,77910,77913 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r77871 | ezio.melotti | 2010-01-31 13:46:54 +0200 (Sun, 31 Jan 2010) | 1 line

  #7092: silence more -3 and -Wd warnings
........
  r77910 | ezio.melotti | 2010-02-02 10:37:35 +0200 (Tue, 02 Feb 2010) | 1 line

  #7092: silence py3k warnings for bsddb. Patch by Florent Xicluna.
........
  r77913 | ezio.melotti | 2010-02-02 19:34:37 +0200 (Tue, 02 Feb 2010) | 1 line

  #7092: Silence py3k warnings in test_exceptions and test_pep352. Patch by Florent Xicluna.
........
diff --git a/Lib/test/test_bsddb3.py b/Lib/test/test_bsddb3.py
index 5925e15..50efd7e 100644
--- a/Lib/test/test_bsddb3.py
+++ b/Lib/test/test_bsddb3.py
@@ -7,7 +7,13 @@
 import tempfile
 import time
 import unittest
-from test.test_support import requires, verbose, run_unittest, unlink, rmtree
+from test.test_support import (requires, verbose, run_unittest, unlink, rmtree,
+                               import_module)
+
+# Skip test if _bsddb module was not built.
+import_module('_bsddb')
+# Silence Py3k warning
+import_module('bsddb', deprecated=True)
 
 # When running as a script instead of within the regrtest framework, skip the
 # requires test, since it's obvious we want to run them.
diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py
index 800f629..ef06534 100644
--- a/Lib/test/test_cgi.py
+++ b/Lib/test/test_cgi.py
@@ -1,4 +1,4 @@
-from test.test_support import run_unittest
+from test.test_support import run_unittest, check_warnings
 import cgi
 import os
 import sys
@@ -102,11 +102,6 @@
       })
     ]
 
-def norm(list):
-    if type(list) == type([]):
-        list.sort()
-    return list
-
 def first_elts(list):
     return map(lambda x:x[0], list)
 
@@ -141,18 +136,18 @@
             if type(expect) == type({}):
                 # test dict interface
                 self.assertEqual(len(expect), len(fcd))
-                self.assertEqual(norm(expect.keys()), norm(fcd.keys()))
-                self.assertEqual(norm(expect.values()), norm(fcd.values()))
-                self.assertEqual(norm(expect.items()), norm(fcd.items()))
+                self.assertEqual(sorted(expect.keys()), sorted(fcd.keys()))
+                self.assertEqual(sorted(expect.values()), sorted(fcd.values()))
+                self.assertEqual(sorted(expect.items()), sorted(fcd.items()))
                 self.assertEqual(fcd.get("nonexistent field", "default"), "default")
                 self.assertEqual(len(sd), len(fs))
-                self.assertEqual(norm(sd.keys()), norm(fs.keys()))
+                self.assertEqual(sorted(sd.keys()), sorted(fs.keys()))
                 self.assertEqual(fs.getvalue("nonexistent field", "default"), "default")
                 # test individual fields
                 for key in expect.keys():
                     expect_val = expect[key]
                     self.assert_(fcd.has_key(key))
-                    self.assertEqual(norm(fcd[key]), norm(expect[key]))
+                    self.assertEqual(sorted(fcd[key]), sorted(expect[key]))
                     self.assertEqual(fcd.get(key, "default"), fcd[key])
                     self.assert_(fs.has_key(key))
                     if len(expect_val) > 1:
@@ -168,12 +163,12 @@
                         self.assert_(single_value)
                         self.assertEqual(val, expect_val[0])
                         self.assertEqual(fs.getvalue(key), expect_val[0])
-                    self.assertEqual(norm(sd.getlist(key)), norm(expect_val))
+                    self.assertEqual(sorted(sd.getlist(key)), sorted(expect_val))
                     if single_value:
-                        self.assertEqual(norm(sd.values()),
-                               first_elts(norm(expect.values())))
-                        self.assertEqual(norm(sd.items()),
-                               first_second_elts(norm(expect.items())))
+                        self.assertEqual(sorted(sd.values()),
+                                         sorted(first_elts(expect.values())))
+                        self.assertEqual(sorted(sd.items()),
+                                         sorted(first_second_elts(expect.items())))
 
     def test_weird_formcontentdict(self):
         # Test the weird FormContentDict classes
@@ -184,7 +179,7 @@
             self.assertEqual(d[k], v)
         for k, v in d.items():
             self.assertEqual(expect[k], v)
-        self.assertEqual(norm(expect.values()), norm(d.values()))
+        self.assertEqual(sorted(expect.values()), sorted(d.values()))
 
     def test_log(self):
         cgi.log("Testing")
@@ -345,14 +340,16 @@
         self.assertEqual(result, v)
 
     def test_deprecated_parse_qs(self):
-        # this func is moved to urlparse, this is just a sanity check
-        self.assertEqual({'a': ['A1'], 'B': ['B3'], 'b': ['B2']},
-                         cgi.parse_qs('a=A1&b=B2&B=B3'))
+        with check_warnings():
+            # this func is moved to urlparse, this is just a sanity check
+            self.assertEqual({'a': ['A1'], 'B': ['B3'], 'b': ['B2']},
+                             cgi.parse_qs('a=A1&b=B2&B=B3'))
 
     def test_deprecated_parse_qsl(self):
-        # this func is moved to urlparse, this is just a sanity check
-        self.assertEqual([('a', 'A1'), ('b', 'B2'), ('B', 'B3')],
-                         cgi.parse_qsl('a=A1&b=B2&B=B3'))
+        with check_warnings():
+            # this func is moved to urlparse, this is just a sanity check
+            self.assertEqual([('a', 'A1'), ('b', 'B2'), ('B', 'B3')],
+                             cgi.parse_qsl('a=A1&b=B2&B=B3'))
 
     def test_parse_header(self):
         self.assertEqual(
diff --git a/Lib/test/test_coercion.py b/Lib/test/test_coercion.py
index a70f82d..a36c041 100644
--- a/Lib/test/test_coercion.py
+++ b/Lib/test/test_coercion.py
@@ -223,8 +223,10 @@
             infix_results[key] = res
 
 
-
-process_infix_results()
+with warnings.catch_warnings():
+    warnings.filterwarnings("ignore", "classic int division",
+                            DeprecationWarning)
+    process_infix_results()
 # now infix_results has two lists of results for every pairing.
 
 prefix_binops = [ 'divmod' ]
@@ -337,11 +339,12 @@
             raise exc
 
 def test_main():
-    warnings.filterwarnings("ignore",
-                            r'complex divmod\(\), // and % are deprecated',
-                            DeprecationWarning,
-                            r'test.test_coercion$')
-    run_unittest(CoercionTest)
+    with warnings.catch_warnings():
+        warnings.filterwarnings("ignore", "complex divmod.., // and % "
+                                "are deprecated", DeprecationWarning)
+        warnings.filterwarnings("ignore", "classic (int|long) division",
+                                DeprecationWarning)
+        run_unittest(CoercionTest)
 
 if __name__ == "__main__":
     test_main()
diff --git a/Lib/test/test_distutils.py b/Lib/test/test_distutils.py
index fcd792d..bf5a80d 100644
--- a/Lib/test/test_distutils.py
+++ b/Lib/test/test_distutils.py
@@ -7,10 +7,15 @@
 
 import distutils.tests
 import test.test_support
+import warnings
 
 
 def test_main():
-    test.test_support.run_unittest(distutils.tests.test_suite())
+    with warnings.catch_warnings():
+        warnings.filterwarnings("ignore",
+                                "distutils.sysconfig.\w+ is deprecated",
+                                DeprecationWarning)
+        test.test_support.run_unittest(distutils.tests.test_suite())
 
 
 if __name__ == "__main__":
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py
index 85b21a8..43de4de 100644
--- a/Lib/test/test_exceptions.py
+++ b/Lib/test/test_exceptions.py
@@ -7,7 +7,7 @@
 import warnings
 
 from test.test_support import TESTFN, unlink, run_unittest, captured_output
-from test.test_pep352 import ignore_message_warning
+from test.test_pep352 import ignore_deprecation_warnings
 
 # XXX This is not really enough, each *operation* should be tested!
 
@@ -17,6 +17,7 @@
         # Reloading the built-in exceptions module failed prior to Py2.2, while it
         # should act the same as reloading built-in sys.
         try:
+            from imp import reload
             import exceptions
             reload(exceptions)
         except ImportError, e:
@@ -108,11 +109,11 @@
         self.assertRaises(ValueError, chr, 10000)
 
         self.raise_catch(ZeroDivisionError, "ZeroDivisionError")
-        try: x = 1/0
+        try: x = 1 // 0
         except ZeroDivisionError: pass
 
         self.raise_catch(Exception, "Exception")
-        try: x = 1/0
+        try: x = 1 // 0
         except Exception, e: pass
 
     def testSyntaxErrorMessage(self):
@@ -197,6 +198,7 @@
             self.failUnlessEqual(WindowsError(1001, "message").errno, 22)
             self.failUnlessEqual(WindowsError(1001, "message").winerror, 1001)
 
+    @ignore_deprecation_warnings
     def testAttributes(self):
         # test that exception attributes are happy
 
@@ -274,34 +276,32 @@
         except NameError:
             pass
 
-        with warnings.catch_warnings():
-            ignore_message_warning()
-            for exc, args, expected in exceptionList:
-                try:
-                    raise exc(*args)
-                except BaseException, e:
-                    if type(e) is not exc:
-                        raise
-                    # Verify module name
-                    self.assertEquals(type(e).__module__, 'exceptions')
-                    # Verify no ref leaks in Exc_str()
-                    s = str(e)
-                    for checkArgName in expected:
-                        self.assertEquals(repr(getattr(e, checkArgName)),
-                                          repr(expected[checkArgName]),
-                                          'exception "%s", attribute "%s"' %
-                                           (repr(e), checkArgName))
+        for exc, args, expected in exceptionList:
+            try:
+                raise exc(*args)
+            except BaseException, e:
+                if type(e) is not exc:
+                    raise
+                # Verify module name
+                self.assertEquals(type(e).__module__, 'exceptions')
+                # Verify no ref leaks in Exc_str()
+                s = str(e)
+                for checkArgName in expected:
+                    self.assertEquals(repr(getattr(e, checkArgName)),
+                                      repr(expected[checkArgName]),
+                                      'exception "%s", attribute "%s"' %
+                                       (repr(e), checkArgName))
 
-                    # test for pickling support
-                    for p in pickle, cPickle:
-                        for protocol in range(p.HIGHEST_PROTOCOL + 1):
-                            new = p.loads(p.dumps(e, protocol))
-                            for checkArgName in expected:
-                                got = repr(getattr(new, checkArgName))
-                                want = repr(expected[checkArgName])
-                                self.assertEquals(got, want,
-                                                  'pickled "%r", attribute "%s"' %
-                                                  (e, checkArgName))
+                # test for pickling support
+                for p in pickle, cPickle:
+                    for protocol in range(p.HIGHEST_PROTOCOL + 1):
+                        new = p.loads(p.dumps(e, protocol))
+                        for checkArgName in expected:
+                            got = repr(getattr(new, checkArgName))
+                            want = repr(expected[checkArgName])
+                            self.assertEquals(got, want,
+                                              'pickled "%r", attribute "%s"' %
+                                              (e, checkArgName))
 
 
     def testDeprecatedMessageAttribute(self):
@@ -329,6 +329,7 @@
         del exc.message
         self.assertRaises(AttributeError, getattr, exc, "message")
 
+    @ignore_deprecation_warnings
     def testPickleMessageAttribute(self):
         # Pickling with message attribute must work, as well.
         e = Exception("foo")
@@ -336,18 +337,18 @@
         f.message = "bar"
         for p in pickle, cPickle:
             ep = p.loads(p.dumps(e))
-            with warnings.catch_warnings():
-                ignore_message_warning()
-                self.assertEqual(ep.message, "foo")
+            self.assertEqual(ep.message, "foo")
             fp = p.loads(p.dumps(f))
             self.assertEqual(fp.message, "bar")
 
+    @ignore_deprecation_warnings
     def testSlicing(self):
         # Test that you can slice an exception directly instead of requiring
         # going through the 'args' attribute.
         args = (1, 2, 3)
         exc = BaseException(*args)
         self.failUnlessEqual(exc[:], args)
+        self.assertEqual(exc.args[:], args)
 
     def testKeywordArgs(self):
         # test that builtin exception don't take keyword args,
diff --git a/Lib/test/test_pep352.py b/Lib/test/test_pep352.py
index 313c607..666d6c9 100644
--- a/Lib/test/test_pep352.py
+++ b/Lib/test/test_pep352.py
@@ -4,14 +4,27 @@
 import warnings
 from test.test_support import run_unittest
 import os
+import sys
 from platform import system as platform_system
 
-def ignore_message_warning():
-    """Ignore the DeprecationWarning for BaseException.message."""
-    warnings.resetwarnings()
-    warnings.filterwarnings("ignore", "BaseException.message",
-                            DeprecationWarning)
+DEPRECATION_WARNINGS = ["BaseException.message has been deprecated"]
 
+if sys.py3kwarning:
+    DEPRECATION_WARNINGS.extend(
+        ["exceptions must derive from BaseException",
+         "catching classes that don't inherit from BaseException is not allowed",
+         "__get(item|slice)__ not supported for exception classes"])
+
+# Silence Py3k and other deprecation warnings
+def ignore_deprecation_warnings(func):
+    """Ignore the known DeprecationWarnings."""
+    def wrapper(*args, **kw):
+        with warnings.catch_warnings():
+            warnings.resetwarnings()
+            for text in DEPRECATION_WARNINGS:
+                warnings.filterwarnings("ignore", text, DeprecationWarning)
+            return func(*args, **kw)
+    return wrapper
 
 class ExceptionClassTests(unittest.TestCase):
 
@@ -21,13 +34,11 @@
     def test_builtins_new_style(self):
         self.failUnless(issubclass(Exception, object))
 
+    @ignore_deprecation_warnings
     def verify_instance_interface(self, ins):
-        with warnings.catch_warnings():
-            ignore_message_warning()
-            for attr in ("args", "message", "__str__", "__repr__",
-                            "__getitem__"):
-                self.failUnless(hasattr(ins, attr),
-                        "%s missing %s attribute" %
+        for attr in ("args", "message", "__str__", "__repr__", "__getitem__"):
+            self.assertTrue(hasattr(ins, attr),
+                            "%s missing %s attribute" %
                             (ins.__class__.__name__, attr))
 
     def test_inheritance(self):
@@ -91,43 +102,39 @@
             self.failUnlessEqual(given, expected, "%s: %s != %s" % (test_name,
                 given, expected))
 
+    @ignore_deprecation_warnings
     def test_interface_single_arg(self):
         # Make sure interface works properly when given a single argument
         arg = "spam"
         exc = Exception(arg)
-        with warnings.catch_warnings():
-            ignore_message_warning()
-            results = ([len(exc.args), 1], [exc.args[0], arg],
-                    [exc.message, arg],
-                    [str(exc), str(arg)], [unicode(exc), unicode(arg)],
-                [repr(exc), exc.__class__.__name__ + repr(exc.args)], [exc[0],
-                arg])
-            self.interface_test_driver(results)
+        results = ([len(exc.args), 1], [exc.args[0], arg], [exc.message, arg],
+                   [str(exc), str(arg)], [unicode(exc), unicode(arg)],
+                   [repr(exc), exc.__class__.__name__ + repr(exc.args)],
+                   [exc[0], arg])
+        self.interface_test_driver(results)
 
+    @ignore_deprecation_warnings
     def test_interface_multi_arg(self):
         # Make sure interface correct when multiple arguments given
         arg_count = 3
         args = tuple(range(arg_count))
         exc = Exception(*args)
-        with warnings.catch_warnings():
-            ignore_message_warning()
-            results = ([len(exc.args), arg_count], [exc.args, args],
-                    [exc.message, ''], [str(exc), str(args)],
-                    [unicode(exc), unicode(args)],
-                    [repr(exc), exc.__class__.__name__ + repr(exc.args)],
-                    [exc[-1], args[-1]])
-            self.interface_test_driver(results)
+        results = ([len(exc.args), arg_count], [exc.args, args],
+                   [exc.message, ''], [str(exc), str(args)],
+                   [unicode(exc), unicode(args)],
+                   [repr(exc), exc.__class__.__name__ + repr(exc.args)],
+                   [exc[-1], args[-1]])
+        self.interface_test_driver(results)
 
+    @ignore_deprecation_warnings
     def test_interface_no_arg(self):
         # Make sure that with no args that interface is correct
         exc = Exception()
-        with warnings.catch_warnings():
-            ignore_message_warning()
-            results = ([len(exc.args), 0], [exc.args, tuple()],
-                    [exc.message, ''],
-                    [str(exc), ''], [unicode(exc), u''],
-                    [repr(exc), exc.__class__.__name__ + '()'], [True, True])
-            self.interface_test_driver(results)
+        results = ([len(exc.args), 0], [exc.args, tuple()],
+                   [exc.message, ''],
+                   [str(exc), ''], [unicode(exc), u''],
+                   [repr(exc), exc.__class__.__name__ + '()'], [True, True])
+        self.interface_test_driver(results)
 
 
     def test_message_deprecation(self):
@@ -179,6 +186,7 @@
             self.fail("TypeError expected when catching %s as specified in a "
                         "tuple" % type(object_))
 
+    @ignore_deprecation_warnings
     def test_raise_classic(self):
         # Raising a classic class is okay (for now).
         class ClassicClass:
@@ -194,7 +202,7 @@
         except ClassicClass:
             pass
         except:
-            self.fail("unable to raise class class instance")
+            self.fail("unable to raise classic class instance")
 
     def test_raise_new_style_non_exception(self):
         # You cannot raise a new-style class that does not inherit from
diff --git a/Lib/test/test_userstring.py b/Lib/test/test_userstring.py
index 4bb0c45..ee7a1f4 100755
--- a/Lib/test/test_userstring.py
+++ b/Lib/test/test_userstring.py
@@ -136,7 +136,10 @@
 
 def test_main():
     with warnings.catch_warnings():
-        warnings.filterwarnings("ignore", ".*MutableString",
+        warnings.filterwarnings("ignore", ".*MutableString has been removed",
+                                DeprecationWarning)
+        warnings.filterwarnings("ignore",
+                                ".*__(get|set|del)slice__ has been removed",
                                 DeprecationWarning)
         test_support.run_unittest(UserStringTest, MutableStringTest)