--- /home/jeff/test_winreg.py 2008-03-18 23:50:46.000000000 -0400 +++ Lib/test/test_winreg.py 2008-03-19 00:01:39.000000000 -0400 @@ -1,12 +1,14 @@ # Test the windows specific win32reg module. # Only win32reg functions not hit here: FlushKey, LoadKey and SaveKey -import _winreg import os, sys import unittest from test import test_support -from exceptions import WindowsError + +_winreg = test_support.optional_import('_winreg') +WindowsError = test_support.optional_import('exceptions.WindowsError', + fromlist=['exceptions']) test_key_name = "SOFTWARE\\Python Registry Test Key - Delete Me" --- bar 2008-03-18 23:32:47.000000000 -0400 +++ Lib/test/test_sunaudiodev.py 2008-03-18 23:33:10.000000000 -0400 @@ -1,7 +1,8 @@ -import sunaudiodev from test import test_support import os +sunaudiodev = test_support.optional_import('sunaudiodev') + try: audiodev = os.environ["AUDIODEV"] except KeyError: Index: Lib/test/test_cl.py =================================================================== --- Lib/test/test_cl.py (revision 61589) +++ Lib/test/test_cl.py (working copy) @@ -2,9 +2,10 @@ """Whimpy test script for the cl module Roger E. Masse """ -import cl -from test.test_support import verbose +from test.test_support import verbose, optional_import +cl = optional_import('cl') + clattrs = ['ADDED_ALGORITHM_ERROR', 'ALAW', 'ALGORITHM_ID', 'ALGORITHM_VERSION', 'AUDIO', 'AWARE_ERROR', 'AWARE_MPEG_AUDIO', 'AWARE_MULTIRATE', 'AWCMP_CONST_QUAL', 'AWCMP_FIXED_RATE', Index: Lib/test/regrtest.py =================================================================== --- Lib/test/regrtest.py (revision 61589) +++ Lib/test/regrtest.py (working copy) @@ -568,7 +568,7 @@ print test, "skipped --", msg sys.stdout.flush() return -2 - except (ImportError, test_support.TestSkipped), msg: + except (test_support.OptionalImportFailed, test_support.TestSkipped), msg: if not quiet: print test, "skipped --", msg sys.stdout.flush() Index: Lib/test/test_gl.py =================================================================== --- Lib/test/test_gl.py (revision 61589) +++ Lib/test/test_gl.py (working copy) @@ -3,9 +3,12 @@ taken mostly from the documentation. Roger E. Masse """ -from test.test_support import verbose, TestSkipped -import gl, GL, time +from test.test_support import verbose, TestSkipped, optional_import +import time +gl = optional_import('gl') +GL = optional_import('GL') + glattrs = ['RGBcolor', 'RGBcursor', 'RGBmode', 'RGBrange', 'RGBwritemask', '__doc__', '__name__', 'addtopup', 'altgetmatrix', 'arc', 'arcf', 'arcfi', 'arcfs', 'arci', 'arcs', 'attachcursor', 'backbuffer', Index: Lib/test/test_macostools.py =================================================================== --- Lib/test/test_macostools.py (revision 61589) +++ Lib/test/test_macostools.py (working copy) @@ -1,13 +1,14 @@ # Copyright (C) 2003 Python Software Foundation import unittest -import macostools -import Carbon.File -import MacOS import os import sys from test import test_support +macostools = test_support.optional_import('macostools') +Carbon = test_support.optional_import('Carbon') +MacOS = test_support.optional_import('MacOS') + TESTFN2 = test_support.TESTFN + '2' class TestMacostools(unittest.TestCase): Index: Lib/test/test_winsound.py =================================================================== --- Lib/test/test_winsound.py (revision 61589) +++ Lib/test/test_winsound.py (working copy) @@ -2,11 +2,13 @@ import unittest from test import test_support -import winsound, time +import time import os import subprocess +winsound = test_support.optional_import('winsound') + class BeepTest(unittest.TestCase): # As with PlaySoundTest, incorporate the _have_soundcard() check # into our test methods. If there's no audio device present, Index: Lib/test/test_bsddb185.py =================================================================== --- Lib/test/test_bsddb185.py (revision 61589) +++ Lib/test/test_bsddb185.py (working copy) @@ -4,15 +4,16 @@ testing suite. """ -from test.test_support import run_unittest, findfile +from test.test_support import run_unittest, findfile, optional_import import unittest -import bsddb185 import anydbm import whichdb import os import tempfile import shutil +bsddb185 = optional_import('bsddb185') + class Bsddb185Tests(unittest.TestCase): def test_open_existing_hash(self): Index: Lib/test/test_applesingle.py =================================================================== --- Lib/test/test_applesingle.py (revision 61589) +++ Lib/test/test_applesingle.py (working copy) @@ -1,14 +1,15 @@ # Copyright (C) 2003 Python Software Foundation import unittest -import macostools -import Carbon.File -import MacOS import os from test import test_support import struct -import applesingle +macostools = test_support.optional_import('macostools') +Carbon = test_support.optional_import('Carbon') +MacOS = test_support.optional_import('MacOS') +applesingle = test_support.optional_import('applesingle') + AS_MAGIC=0x00051600 AS_VERSION=0x00020000 dataforkdata = 'hello\r\0world\n' Index: Lib/test/test_dbm.py =================================================================== --- Lib/test/test_dbm.py (revision 61589) +++ Lib/test/test_dbm.py (working copy) @@ -2,9 +2,9 @@ import unittest import os import random -import dbm -from dbm import error +dbm = test_support.optional_import('dbm') + class DbmTestCase(unittest.TestCase): def setUp(self): Index: Lib/test/test_imgfile.py =================================================================== --- Lib/test/test_imgfile.py (revision 61589) +++ Lib/test/test_imgfile.py (working copy) @@ -4,11 +4,13 @@ Roger E. Masse """ -from test.test_support import verbose, unlink, findfile +from test.test_support import verbose, unlink, findfile, optional_import -import imgfile, uu +import uu +imgfile = optional_import('imgfile') + def testimage(name): """Run through the imgfile's battery of possible methods on the image passed in name. Index: Lib/test/test_aepack.py =================================================================== --- Lib/test/test_aepack.py (revision 61589) +++ Lib/test/test_aepack.py (working copy) @@ -1,11 +1,11 @@ # Copyright (C) 2003 Python Software Foundation import unittest -import aepack -import aetypes import os from test import test_support +aepack = test_support.optional_import('aepack') + class TestAepack(unittest.TestCase): OBJECTS = [ aetypes.Enum('enum'), Index: Lib/test/test_cd.py =================================================================== --- Lib/test/test_cd.py (revision 61589) +++ Lib/test/test_cd.py (working copy) @@ -2,9 +2,10 @@ """Whimpy test script for the cd module Roger E. Masse """ -import cd -from test.test_support import verbose +from test.test_support import verbose, optional_import +cd = optional_import('cd') + cdattrs = ['BLOCKSIZE', 'CDROM', 'DATASIZE', 'ERROR', 'NODISC', 'PAUSED', 'PLAYING', 'READY', 'STILL', '__doc__', '__name__', 'atime', 'audio', 'catalog', 'control', 'createparser', 'error', 'ident', 'index', 'msftoframe', 'open', 'pnum', 'ptime'] Index: Lib/test/test_al.py =================================================================== --- Lib/test/test_al.py (revision 61589) +++ Lib/test/test_al.py (working copy) @@ -2,9 +2,10 @@ """Whimpy test script for the al module Roger E. Masse """ -import al -from test.test_support import verbose +from test.test_support import verbose, optional_import +al = optional_import('al') + alattrs = ['__doc__', '__name__', 'getdefault', 'getminmax', 'getname', 'getparams', 'newconfig', 'openport', 'queryparams', 'setparams'] Index: Lib/test/test_scriptpackages.py =================================================================== --- Lib/test/test_scriptpackages.py (revision 61589) +++ Lib/test/test_scriptpackages.py (working copy) @@ -2,8 +2,9 @@ import unittest from test import test_support -import aetools +aetools = test_support.optional_import('aetools') + class TestScriptpackages(unittest.TestCase): def _test_scriptpackage(self, package, testobject=1): Index: Lib/test/test_imageop.py =================================================================== --- Lib/test/test_imageop.py (revision 61589) +++ Lib/test/test_imageop.py (working copy) @@ -5,12 +5,14 @@ Roger E. Masse """ -from test.test_support import verbose, unlink +from test.test_support import verbose, unlink, optional_import -import imageop, uu, os, imgfile +import imageop, uu, os import warnings +imgfile = optional_import('imgfile') + def test_main(): # Create binary test files Index: Lib/test/test_startfile.py =================================================================== --- Lib/test/test_startfile.py (revision 61589) +++ Lib/test/test_startfile.py (working copy) @@ -11,8 +11,10 @@ from test import test_support # use this form so that the test is skipped when startfile is not available: -from os import startfile, path +from os import path +startfile = test_support.optional_import('os.startfile', fromlist=['os']) + class TestCase(unittest.TestCase): def test_nonexisting(self): self.assertRaises(OSError, startfile, "nonexisting.vbs")