]> granicus.if.org Git - python/commitdiff
fix test_py3kwarns
authorBenjamin Peterson <benjamin@python.org>
Mon, 14 Jul 2008 17:42:17 +0000 (17:42 +0000)
committerBenjamin Peterson <benjamin@python.org>
Mon, 14 Jul 2008 17:42:17 +0000 (17:42 +0000)
The fact that this was failing and went unnoticed so long seems like a good argument for being able to enable and disble py3kwarnings through Python.

38 files changed:
Lib/mimetools.py
Lib/plat-mac/Audio_mac.py
Lib/plat-mac/Carbon/__init__.py
Lib/plat-mac/EasyDialogs.py
Lib/plat-mac/FrameWork.py
Lib/plat-mac/MiniAEFrame.py
Lib/plat-mac/PixMapWrapper.py
Lib/plat-mac/aepack.py
Lib/plat-mac/aetools.py
Lib/plat-mac/aetypes.py
Lib/plat-mac/applesingle.py
Lib/plat-mac/appletrawmain.py
Lib/plat-mac/appletrunner.py
Lib/plat-mac/argvemulator.py
Lib/plat-mac/bgenlocations.py
Lib/plat-mac/buildtools.py
Lib/plat-mac/bundlebuilder.py
Lib/plat-mac/cfmfile.py
Lib/plat-mac/findertools.py
Lib/plat-mac/gensuitemodule.py
Lib/plat-mac/ic.py
Lib/plat-mac/icopen.py
Lib/plat-mac/lib-scriptpackages/CodeWarrior/__init__.py
Lib/plat-mac/lib-scriptpackages/Explorer/__init__.py
Lib/plat-mac/lib-scriptpackages/Finder/__init__.py
Lib/plat-mac/lib-scriptpackages/Netscape/__init__.py
Lib/plat-mac/lib-scriptpackages/StdSuites/__init__.py
Lib/plat-mac/lib-scriptpackages/SystemEvents/__init__.py
Lib/plat-mac/lib-scriptpackages/Terminal/__init__.py
Lib/plat-mac/lib-scriptpackages/_builtinSuites/__init__.py
Lib/plat-mac/macerrors.py
Lib/plat-mac/macostools.py
Lib/plat-mac/macresource.py
Lib/plat-mac/pimp.py
Lib/plat-mac/terminalcommand.py
Lib/plat-mac/videoreader.py
Lib/rfc822.py
Lib/test/test_py3kwarn.py

index 5dd5396203ec65ce4735528565f6c90c78ce1b53..02963b55548de44f582f73364420129666dbce57 100644 (file)
@@ -6,7 +6,8 @@ import rfc822
 import tempfile
 
 from warnings import warnpy3k
-warnpy3k("in 3.x, mimetools has been removed in favor of the email package")
+warnpy3k("in 3.x, mimetools has been removed in favor of the email package",
+         stacklevel=2)
 
 __all__ = ["Message","choose_boundary","encode","decode","copyliteral",
            "copybinary"]
index 3c8a74c20c3f00db915bf433d19871928ec18866..ddf2a1cfd70ae3c7ac6815c392b4c54711bf6589 100644 (file)
@@ -2,7 +2,7 @@ QSIZE = 100000
 error='Audio_mac.error'
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the Play_Audio_mac module is removed.")
+warnpy3k("In 3.x, the Play_Audio_mac module is removed.", stacklevel=2)
 
 class Play_Audio_mac:
 
index 664dceccea90ca37f6304ff49f4f2e36a57f594f..6739bbdf9c87100024ac00abfc52ecec4ddd84ac 100644 (file)
@@ -4,4 +4,4 @@ warnings.filterwarnings("ignore", "", FutureWarning, ".*Controls")
 warnings.filterwarnings("ignore", "", FutureWarning, ".*MacTextEditor")
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, Carbon is removed.")
+warnpy3k("In 3.x, Carbon is removed.", stacklevel=2)
index f3d7e78cd4832c8ab8527dc557986a2b102e6044..4c64839ed2c8de3e47b3d97141e322cd1d29e2b5 100644 (file)
@@ -19,7 +19,7 @@ Based upon STDWIN dialogs with the same names and functions.
 """
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the EasyDialogs module is removed.")
+warnpy3k("In 3.x, the EasyDialogs module is removed.", stacklevel=2)
 
 from Carbon.Dlg import GetNewDialog, SetDialogItemText, GetDialogItemText, ModalDialog
 from Carbon import Qd
index 75588a6c4f1a02dc2caba17a36fc3875a78bf368..69401ddc35115d25c6e31f9f92cb59b6563320a6 100644 (file)
@@ -3,7 +3,7 @@
 DEBUG=0
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the FrameWork module is removed.")
+warnpy3k("In 3.x, the FrameWork module is removed.", stacklevel=2)
 
 import MacOS
 import traceback
index 7d2d5f598c6d275f1e1fc630d4595cdebfeeaaf1..8d758c33448f6b8133400595e7b43d7bdf5800e7 100644 (file)
@@ -7,7 +7,7 @@ There are two classes:
 """
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the MiniAEFrame module is removed.")
+warnpy3k("In 3.x, the MiniAEFrame module is removed.", stacklevel=2)
 
 import traceback
 import MacOS
index 45cb5f964a5fe771dd554ddbfcd7f0baab13c4a6..5ce304357d9c48822b65d350e438f60bd0292171 100644 (file)
@@ -7,7 +7,7 @@ J. Strout <joe@strout.net>  February 1999"""
 
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the PixMapWrapper module is removed.")
+warnpy3k("In 3.x, the PixMapWrapper module is removed.", stacklevel=2)
 
 from Carbon import Qd
 from Carbon import QuickDraw
index b849c9da733e4ff294e03598924ab185efd4b1b6..3b31b048cbf85ea4d0e5db00fb047136712e4f1c 100644 (file)
@@ -13,7 +13,7 @@ coerce(x, wanted_sample) coerces a python object to another python object
 #
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the aepack module is removed.")
+warnpy3k("In 3.x, the aepack module is removed.", stacklevel=2)
 
 import struct
 import types
index 9618b81d5f95e120ed71c96af498f3200e668fd2..bf27663dfe5d15acc336044a6a06e0d6e006e52a 100644 (file)
@@ -22,7 +22,7 @@ files: the pack stuff from aepack, the objects from aetypes.
 
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the aetools module is removed.")
+warnpy3k("In 3.x, the aetools module is removed.", stacklevel=2)
 
 from types import *
 from Carbon import AE
index c6c9026cf8e4cc5157046d7f4cfb21c54a3ca66a..5e3555e3142e057db43f688675612ebc72b2bc2e 100644 (file)
@@ -1,7 +1,7 @@
 """aetypes - Python objects representing various AE types."""
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the aetypes module is removed.")
+warnpy3k("In 3.x, the aetypes module is removed.", stacklevel=2)
 
 from Carbon.AppleEvents import *
 import struct
index 0e2cf912ef1a295e984600a421da67969b492f0b..f6c605fd70cb81e2e705c3d7175d27b27be38e75 100644 (file)
@@ -2,7 +2,7 @@ r"""Routines to decode AppleSingle files
 """
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the applesingle module is removed.")
+warnpy3k("In 3.x, the applesingle module is removed.", stacklevel=2)
 
 import struct
 import sys
index 7fc51d8fda2f96a6d75bbd9509b11b18b8d1cbae..c863486aa953935f0078707f98e54a5291631c3d 100644 (file)
@@ -6,7 +6,7 @@
 #
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the appletrawmain module is removed.")
+warnpy3k("In 3.x, the appletrawmain module is removed.", stacklevel=2)
 
 import argvemulator
 import os
index b47fa424ecf0c8dbad2b8fb6b78dd3deaeb6fb53..a2373aa856040dc2a8f3014b73b5316794bea8ac 100755 (executable)
@@ -4,7 +4,7 @@
 # we are not running in a framework build.
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, appletrunner is removed.")
+warnpy3k("In 3.x, appletrunner is removed.", stacklevel=2)
 
 import os
 import sys
index 1bc5da6d147aecfeb7a297f2fc051073ceb6a69c..3dfc9f83189908e3540337c079cbce1eb600f89d 100644 (file)
@@ -3,7 +3,7 @@ want unix-style arguments.
 """
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the argvemulator module is removed.")
+warnpy3k("In 3.x, the argvemulator module is removed.", stacklevel=2)
 
 import sys
 import traceback
index 7643e4bae85d6852a2db0dfd192908561197340f..38f41592f890ce06bad1822e5e9f254fc43551a9 100644 (file)
@@ -8,7 +8,7 @@
 import os
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the bgenlocations module is removed.")
+warnpy3k("In 3.x, the bgenlocations module is removed.", stacklevel=2)
 
 Error = "bgenlocations.Error"
 #
index 0081e65a8f177721f761abc95d6b64da4cb4b091..3480226203da05aafaf1a6c255c0aa99269142cc 100644 (file)
@@ -1,8 +1,8 @@
 """tools for BuildApplet and BuildApplication"""
 
 import warnings
-warnings.warn("the buildtools module is deprecated and is removed in 3.0",
-              DeprecationWarning, 2)
+warnings.warnpy3k("the buildtools module is deprecated and is removed in 3.0",
+              stacklevel=2)
 
 import sys
 import os
index 46c17df6c8f538cc9150db4ae70692826a3668f4..f0c7fc2b192decab3752e8dde1faac5d0c3b282a 100755 (executable)
@@ -29,7 +29,7 @@ __all__ = ["BundleBuilder", "BundleBuilderError", "AppBuilder", "buildapp"]
 
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the bundlebuilder module is removed.")
+warnpy3k("In 3.x, the bundlebuilder module is removed.", stacklevel=2)
 
 import sys
 import os, errno, shutil
index 309af8754a3a4153e627a2a67fd4b7832ba2d7c3..ddbd46829707d8785f12990f21bcfec6fc9c9dfb 100644 (file)
@@ -6,8 +6,8 @@ __version__ = "0.8b3"
 __author__ = "jvr"
 
 import warnings
-warnings.warn("the cfmfile module is deprecated and is removed in 3,0",
-              DeprecationWarning, 2)
+warnings.warnpy3k("the cfmfile module is deprecated and is removed in 3,0",
+              stacklevel=2)
 
 import Carbon.File
 import struct
index 038ee09b785c508ebe64787bb7269623d96dfa3f..56e798010c46535bff89c504c976e4afe4c577d2 100644 (file)
@@ -16,7 +16,7 @@ Mostly written by erik@letterror.com
 """
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the findertools module is removed.")
+warnpy3k("In 3.x, the findertools module is removed.", stacklevel=2)
 
 import Finder
 from Carbon import AppleEvents
index c92d1ebe9dd61ea1a0f13b946c5e599a3c1ffdcd..28ebea6a4aa32163f328e53777e74aeb5f8824ae 100644 (file)
@@ -7,7 +7,7 @@ Reading and understanding this code is left as an exercise to the reader.
 """
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the gensuitemodule module is removed.")
+warnpy3k("In 3.x, the gensuitemodule module is removed.", stacklevel=2)
 
 import MacOS
 import EasyDialogs
index beb8226026c409a26beaa84f7b1d73c82d9edb49..8337f2d72dffaabf5954176ba09d272d91322a1e 100644 (file)
@@ -1,7 +1,7 @@
 """IC wrapper module, based on Internet Config 1.3"""
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the ic module is removed.")
+warnpy3k("In 3.x, the ic module is removed.", stacklevel=2)
 
 import icglue
 import string
index 7b8e8f372e727e839c8885fb755c0d6ca8c60309..941dbb64008a150dfaa74b5c4af8f449ba0d38a4 100644 (file)
@@ -38,7 +38,7 @@ effect.
 """
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the icopen module is removed.")
+warnpy3k("In 3.x, the icopen module is removed.", stacklevel=2)
 
 import __builtin__
 
index 89583d3c17d803a5f4d0dc56eef8e1dcbc95905e..38e33502d56b174c75ca661f0bdc5e51bde1a6ca 100644 (file)
@@ -3,7 +3,7 @@ Package generated from /Volumes/Sap/Applications (Mac OS 9)/Metrowerks CodeWarri
 """
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the CodeWarrior package is removed.")
+warnpy3k("In 3.x, the CodeWarrior package is removed.", stacklevel=2)
 
 import aetools
 Error = aetools.Error
index 8e9438a45bdafb853ba2854855703956b7eaeab1..967bc0e5a9236e5a610801670f7e6be98dfa2b09 100644 (file)
@@ -3,7 +3,7 @@ Package generated from /Applications/Internet Explorer.app
 """
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the Explorer module is removed.")
+warnpy3k("In 3.x, the Explorer module is removed.", stacklevel=2)
 
 import aetools
 Error = aetools.Error
index 8c9b02691c44d96fdbfc558847e5192c3474bbfd..84d178d8f276fde43d790b0cc2eab5c650d3ed88 100644 (file)
@@ -3,7 +3,7 @@ Package generated from /System/Library/CoreServices/Finder.app
 """
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the Finder package is removed.")
+warnpy3k("In 3.x, the Finder package is removed.", stacklevel=2)
 
 import aetools
 Error = aetools.Error
index 7f0dfe24cefd104572710c4402634afa3caa22cd..802f18a3b4f259226030e80adfdcaef71c3ffc18 100644 (file)
@@ -3,7 +3,7 @@ Package generated from /Volumes/Sap/Applications (Mac OS 9)/Netscape Communicato
 """
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the Netscape package is removed.")
+warnpy3k("In 3.x, the Netscape package is removed.", stacklevel=2)
 
 import aetools
 Error = aetools.Error
index 15e03ec5d5eff0b086b8e4e7f547fcc4141e6258..b96055d6962bc70f88d5809e412782e0ddf8ff74 100644 (file)
@@ -4,7 +4,7 @@ Resource aeut resid 0 Standard Event Suites for English
 """
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the StdSuites package is removed.")
+warnpy3k("In 3.x, the StdSuites package is removed.", stacklevel=2)
 
 import aetools
 Error = aetools.Error
index 8029224fdca878e67bd6a1db817bf97a5b9d8c2c..80ce28ee6c29bbe1294145f141a86d164efe5a1e 100644 (file)
@@ -3,7 +3,7 @@ Package generated from /System/Library/CoreServices/System Events.app
 """
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the SystemEvents package is removed.")
+warnpy3k("In 3.x, the SystemEvents package is removed.", stacklevel=2)
 
 import aetools
 Error = aetools.Error
index 5aa8a1e7888dd1e9af9028942fdf98593f787580..00330b9ac9b7479668e680d0a629e5f22cd063df 100644 (file)
@@ -3,7 +3,7 @@ Package generated from /Applications/Utilities/Terminal.app
 """
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the Terminal module is removed.")
+warnpy3k("In 3.x, the Terminal module is removed.", stacklevel=2)
 
 import aetools
 Error = aetools.Error
index 5061204103c13c8fec92ac44058706c3460905ab..b675b985030cc43277796c8bd3b8ae120685a3b2 100644 (file)
@@ -6,7 +6,7 @@ in the Standard suite.
 """
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the _builtinSuites module is removed.")
+warnpy3k("In 3.x, the _builtinSuites module is removed.", stacklevel=2)
 
 import aetools
 import builtin_Suite
index 9629a0f05cd673f784fb171c2ccdb1d05ebe9b8e..de1c1e2424f0d7fa0931d0bb2db6cb306f578f82 100644 (file)
@@ -1,7 +1,7 @@
 # -coding=latin1-
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the macerrors module is removed.")
+warnpy3k("In 3.x, the macerrors module is removed.", stacklevel=2)
 
 svTempDisable   =   -32768  #svTempDisable
 svDisabled  =   -32640  #Reserve range -32640 to -32768 for Apple temp disables.
index 643ba67c08758be87eab284d9703c7afd9438fa5..d7724fa271b58d2a3cd897d67895142e77bbe407 100644 (file)
@@ -5,7 +5,7 @@ copy(src, dst) - Full copy of 'src' to 'dst'
 """
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the macostools module is removed.")
+warnpy3k("In 3.x, the macostools module is removed.", stacklevel=2)
 
 from Carbon import Res
 from Carbon import File, Files
index 0a66d76ae7720a3a39083fbdbb0067286310e83e..f02453ba1d779052a44c458d0a168a91d698671a 100644 (file)
@@ -1,7 +1,7 @@
 """macresource - Locate and open the resources needed for a script."""
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the macresource module is removed.")
+warnpy3k("In 3.x, the macresource module is removed.", stacklevel=2)
 
 from Carbon import Res
 import os
index b3138bd278814e1b66a74b879d3305a22b6ed019..5fc16f0c6547ffbb34d32f22288e8263029dc496 100644 (file)
@@ -14,7 +14,7 @@ intention is that the end user will use this through a GUI.
 """
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the pimp module is removed.")
+warnpy3k("In 3.x, the pimp module is removed.", stacklevel=2)
 
 import sys
 import os
index 238781a247ea71b62f63630b0c68d93f71fdd9da..ef8cb6c4101a43868107d0ee28600fc8229f98b0 100644 (file)
@@ -15,7 +15,7 @@ with a decent input/output window.
 #
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the terminalcommand module is removed.")
+warnpy3k("In 3.x, the terminalcommand module is removed.", stacklevel=2)
 
 import time
 import os
index 43027d4cc3a666fadbb5305cd51b6a1d846ad4e4..fbb37e12e752f3402aa8d1d98783c13c58b74eb3 100644 (file)
@@ -7,7 +7,7 @@
 #
 
 from warnings import warnpy3k
-warnpy3k("In 3.x, the videoreader module is removed.")
+warnpy3k("In 3.x, the videoreader module is removed.", stacklevel=2)
 
 
 import sys
index 4382a51b70d30ebdd4130db99cfeccc0114edc32..64cd702cd0c6b7cef1d9e4adf215a69bfd823a3f 100644 (file)
@@ -74,7 +74,8 @@ There are also some utility functions here.
 import time
 
 from warnings import warnpy3k
-warnpy3k("in 3.x, rfc822 has been removed in favor of the email package")
+warnpy3k("in 3.x, rfc822 has been removed in favor of the email package",
+         stacklevel=2)
 
 __all__ = ["Message","AddressList","parsedate","parsedate_tz","mktime_tz"]
 
index 0d0157208825d60f76d9c3a9b9a952a7842cfb32..0ddc979634694326100300aa2eeb659cd80fff13 100644 (file)
@@ -4,6 +4,8 @@ from test.test_support import (catch_warning, CleanImport,
                                TestSkipped, run_unittest)
 import warnings
 
+from contextlib import nested
+
 if not sys.py3kwarning:
     raise TestSkipped('%s must be run with the -3 flag' % __name__)
 
@@ -193,7 +195,7 @@ class TestStdlibRemovals(unittest.TestCase):
                                       'Explorer', 'Finder', 'Netscape',
                                       'StdSuites', 'SystemEvents', 'Terminal',
                                       'cfmfile', 'bundlebuilder', 'buildtools',
-                                      'ColorPicker'),
+                                      'ColorPicker', 'Audio_mac'),
                            'sunos5' : ('sunaudiodev', 'SUNAUDIODEV'),
                           }
     optional_modules = ('bsddb185', 'Canvas', 'dl', 'linuxaudiodev', 'imageop',
@@ -202,23 +204,22 @@ class TestStdlibRemovals(unittest.TestCase):
     def check_removal(self, module_name, optional=False):
         """Make sure the specified module, when imported, raises a
         DeprecationWarning and specifies itself in the message."""
-        with CleanImport(module_name):
-            with catch_warning(record=False):
-                warnings.filterwarnings("error", ".+ removed",
-                                        DeprecationWarning)
-                try:
-                    __import__(module_name, level=0)
-                except DeprecationWarning as exc:
-                    self.assert_(module_name in exc.args[0],
-                                 "%s warning didn't contain module name"
-                                 % module_name)
-                except ImportError:
-                    if not optional:
-                        self.fail("Non-optional module {0} raised an "
-                                  "ImportError.".format(module_name))
-                else:
-                    self.fail("DeprecationWarning not raised for {0}"
-                                .format(module_name))
+        with nested(CleanImport(module_name), catch_warning(record=False)):
+            warnings.filterwarnings("error", ".+ removed",
+                                    DeprecationWarning, __name__)
+            try:
+                __import__(module_name, level=0)
+            except DeprecationWarning as exc:
+                self.assert_(module_name in exc.args[0],
+                             "%s warning didn't contain module name"
+                             % module_name)
+            except ImportError:
+                if not optional:
+                    self.fail("Non-optional module {0} raised an "
+                              "ImportError.".format(module_name))
+            else:
+                self.fail("DeprecationWarning not raised for {0}"
+                            .format(module_name))
 
     def test_platform_independent_removals(self):
         # Make sure that the modules that are available on all platforms raise