diff options
author | R. David Murray <rdmurray@bitdance.com> | 2009-03-30 19:04:00 (GMT) |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2009-03-30 19:04:00 (GMT) |
commit | 59beec326a4721154a952027cb34c3e2e4612e28 (patch) | |
tree | fd6ff5a872e8b8624a6aad51423f4a0a5ec6eaad /Lib | |
parent | bb8cb0e192c1da800fee1d08b13534ca3db4d53a (diff) | |
download | cpython-59beec326a4721154a952027cb34c3e2e4612e28.zip cpython-59beec326a4721154a952027cb34c3e2e4612e28.tar.gz cpython-59beec326a4721154a952027cb34c3e2e4612e28.tar.bz2 |
Add import_function method to test.test_support, and modify a number of
tests that expect to be skipped if imports fail or functions don't
exist to use import_function and import_module. The ultimate goal is
to change regrtest to not skip automatically on ImportError. Checking
in now to make sure the buldbots don't show any errors on platforms
I can't direct test on.
Diffstat (limited to 'Lib')
-rwxr-xr-x | Lib/test/test_aepack.py | 5 | ||||
-rw-r--r-- | Lib/test/test_applesingle.py | 8 | ||||
-rw-r--r-- | Lib/test/test_asynchat.py | 6 | ||||
-rwxr-xr-x | Lib/test/test_cd.py | 5 | ||||
-rwxr-xr-x | Lib/test/test_cl.py | 5 | ||||
-rwxr-xr-x | Lib/test/test_crypt.py | 3 | ||||
-rw-r--r-- | Lib/test/test_fork1.py | 10 | ||||
-rwxr-xr-x | Lib/test/test_gl.py | 6 | ||||
-rwxr-xr-x | Lib/test/test_grp.py | 3 | ||||
-rw-r--r-- | Lib/test/test_macos.py | 6 | ||||
-rw-r--r-- | Lib/test/test_macostools.py | 8 | ||||
-rw-r--r-- | Lib/test/test_mmap.py | 5 | ||||
-rw-r--r-- | Lib/test/test_posix.py | 7 | ||||
-rw-r--r-- | Lib/test/test_pwd.py | 2 | ||||
-rw-r--r-- | Lib/test/test_scriptpackages.py | 3 | ||||
-rw-r--r-- | Lib/test/test_startfile.py | 6 | ||||
-rw-r--r-- | Lib/test/test_support.py | 14 | ||||
-rw-r--r-- | Lib/test/test_ttk_guionly.py | 6 | ||||
-rw-r--r-- | Lib/test/test_winreg.py | 7 | ||||
-rw-r--r-- | Lib/test/test_winsound.py | 4 |
20 files changed, 78 insertions, 41 deletions
diff --git a/Lib/test/test_aepack.py b/Lib/test/test_aepack.py index 8a4b035..5d4ab3e 100755 --- a/Lib/test/test_aepack.py +++ b/Lib/test/test_aepack.py @@ -1,11 +1,12 @@ # Copyright (C) 2003 Python Software Foundation import unittest -import aepack -import aetypes import os from test import test_support +aetypes = test_support.import_module('aetypes') +aepack = test_support.import_module('aepack') + class TestAepack(unittest.TestCase): OBJECTS = [ aetypes.Enum('enum'), diff --git a/Lib/test/test_applesingle.py b/Lib/test/test_applesingle.py index e915028..5a8201c 100644 --- a/Lib/test/test_applesingle.py +++ b/Lib/test/test_applesingle.py @@ -1,13 +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 + +MacOS = test_support.import_module('MacOS') +# The following should exist if MacOS does. +import macostools import applesingle +import Carbon.File AS_MAGIC=0x00051600 AS_VERSION=0x00020000 diff --git a/Lib/test/test_asynchat.py b/Lib/test/test_asynchat.py index 5501c2d..14528d8 100644 --- a/Lib/test/test_asynchat.py +++ b/Lib/test/test_asynchat.py @@ -1,11 +1,13 @@ -# test asynchat -- requires threading +# test asynchat -import thread # If this fails, we can't test this module import asyncore, asynchat, socket, threading, time import unittest import sys from test import test_support +# Skip tests if thread module does not exist. +test_support.import_module('thread') + HOST = test_support.HOST SERVER_QUIT = 'QUIT\n' diff --git a/Lib/test/test_cd.py b/Lib/test/test_cd.py index daad223..edaa82b 100755 --- a/Lib/test/test_cd.py +++ b/Lib/test/test_cd.py @@ -2,8 +2,9 @@ """Whimpy test script for the cd module Roger E. Masse """ -import cd -from test.test_support import verbose +from test.test_support import verbose, import_module + +cd = import_module('cd') cdattrs = ['BLOCKSIZE', 'CDROM', 'DATASIZE', 'ERROR', 'NODISC', 'PAUSED', 'PLAYING', 'READY', 'STILL', '__doc__', '__name__', 'atime', 'audio', 'catalog', 'control', 'createparser', 'error', diff --git a/Lib/test/test_cl.py b/Lib/test/test_cl.py index a2728b7..50102e9 100755 --- a/Lib/test/test_cl.py +++ b/Lib/test/test_cl.py @@ -2,8 +2,9 @@ """Whimpy test script for the cl module Roger E. Masse """ -import cl -from test.test_support import verbose +from test.test_support import verbose, import_module + +cl = import_module('cl') clattrs = ['ADDED_ALGORITHM_ERROR', 'ALAW', 'ALGORITHM_ID', 'ALGORITHM_VERSION', 'AUDIO', 'AWARE_ERROR', 'AWARE_MPEG_AUDIO', diff --git a/Lib/test/test_crypt.py b/Lib/test/test_crypt.py index f6f3a81..4db200d 100755 --- a/Lib/test/test_crypt.py +++ b/Lib/test/test_crypt.py @@ -1,6 +1,7 @@ from test import test_support import unittest -import crypt + +crypt = test_support.import_module('crypt') class CryptTestCase(unittest.TestCase): diff --git a/Lib/test/test_fork1.py b/Lib/test/test_fork1.py index dfd5016..9306242 100644 --- a/Lib/test/test_fork1.py +++ b/Lib/test/test_fork1.py @@ -3,14 +3,12 @@ import os import time -import unittest from test.fork_wait import ForkWait -from test.test_support import run_unittest, reap_children +from test.test_support import run_unittest, reap_children, import_function + +#Skip test if fork does not exist. +import_function(os, 'fork') -try: - os.fork -except AttributeError: - raise unittest.SkipTest, "os.fork not defined -- skipping test_fork1" class ForkTest(ForkWait): def wait_impl(self, cpid): diff --git a/Lib/test/test_gl.py b/Lib/test/test_gl.py index 1da55a0..be76041 100755 --- a/Lib/test/test_gl.py +++ b/Lib/test/test_gl.py @@ -3,8 +3,10 @@ taken mostly from the documentation. Roger E. Masse """ -from test.test_support import verbose -import gl, GL, time +from test.test_support import verbose, import_module +import time +gl = import_module('gl') +GL = import_module('GL') glattrs = ['RGBcolor', 'RGBcursor', 'RGBmode', 'RGBrange', 'RGBwritemask', '__doc__', '__name__', 'addtopup', 'altgetmatrix', 'arc', 'arcf', diff --git a/Lib/test/test_grp.py b/Lib/test/test_grp.py index 564c7f0..b38b94c 100755 --- a/Lib/test/test_grp.py +++ b/Lib/test/test_grp.py @@ -1,9 +1,10 @@ """Test script for the grp module.""" -import grp import unittest from test import test_support +grp = test_support.import_module('grp') + class GroupDatabaseTestCase(unittest.TestCase): def check_value(self, value): diff --git a/Lib/test/test_macos.py b/Lib/test/test_macos.py index a9ff0b2..ce5f858 100644 --- a/Lib/test/test_macos.py +++ b/Lib/test/test_macos.py @@ -1,10 +1,12 @@ import unittest -import MacOS -import Carbon.File from test import test_support import os import subprocess +MacOS = test_support.import_module('MacOS') +#The following should exist if MacOS exists. +import Carbon.File + TESTFN2 = test_support.TESTFN + '2' class TestMacOS(unittest.TestCase): diff --git a/Lib/test/test_macostools.py b/Lib/test/test_macostools.py index 6110ce3..b84ad72 100644 --- a/Lib/test/test_macostools.py +++ b/Lib/test/test_macostools.py @@ -1,13 +1,15 @@ # Copyright (C) 2003 Python Software Foundation import unittest -import macostools -import Carbon.File -import MacOS import os import sys from test import test_support +MacOS = test_support.import_module('MacOS') +#The following modules should exist if MacOS exists. +import Carbon.File +import macostools + TESTFN2 = test_support.TESTFN + '2' class TestMacostools(unittest.TestCase): diff --git a/Lib/test/test_mmap.py b/Lib/test/test_mmap.py index 31daa8d..2dd76ad 100644 --- a/Lib/test/test_mmap.py +++ b/Lib/test/test_mmap.py @@ -1,8 +1,9 @@ -from test.test_support import TESTFN, run_unittest -import mmap +from test.test_support import TESTFN, run_unittest, import_module import unittest import os, re +mmap = import_module('mmap') + PAGESIZE = mmap.PAGESIZE class MmapTests(unittest.TestCase): diff --git a/Lib/test/test_posix.py b/Lib/test/test_posix.py index 864f963..a7255c4 100644 --- a/Lib/test/test_posix.py +++ b/Lib/test/test_posix.py @@ -2,10 +2,6 @@ from test import test_support -try: - import posix -except ImportError: - raise unittest.SkipTest, "posix is not available" import time import os @@ -13,6 +9,9 @@ import pwd import shutil import unittest import warnings + +posix = test_support.import_module('posix') + warnings.filterwarnings('ignore', '.* potential security risk .*', RuntimeWarning) diff --git a/Lib/test/test_pwd.py b/Lib/test/test_pwd.py index 255a34c..de4084e 100644 --- a/Lib/test/test_pwd.py +++ b/Lib/test/test_pwd.py @@ -1,7 +1,7 @@ import unittest from test import test_support -import pwd +pwd = test_support.import_module('pwd') class PwdTest(unittest.TestCase): diff --git a/Lib/test/test_scriptpackages.py b/Lib/test/test_scriptpackages.py index ee14be2..a3a1857 100644 --- a/Lib/test/test_scriptpackages.py +++ b/Lib/test/test_scriptpackages.py @@ -2,7 +2,8 @@ import unittest from test import test_support -import aetools + +aetools = test_support.import_module('aetools') class TestScriptpackages(unittest.TestCase): diff --git a/Lib/test/test_startfile.py b/Lib/test/test_startfile.py index c4d12d7..23e2708 100644 --- a/Lib/test/test_startfile.py +++ b/Lib/test/test_startfile.py @@ -9,9 +9,11 @@ import unittest from test import test_support +import os +from os import path + +startfile = test_support.import_function(os, 'startfile') -# use this form so that the test is skipped when startfile is not available: -from os import startfile, path class TestCase(unittest.TestCase): def test_nonexisting(self): diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index 4ad2401..90bd8e6 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -55,6 +55,20 @@ def import_module(name, deprecated=False): else: return module +def import_function(module, name, deprecated=False): + with warnings.catch_warnings(): + if deprecated: + warnings.filterwarnings("ignore", ".+ (module|package)", + DeprecationWarning) + try: + function = getattr(module, name) + except AttributeError: + raise unittest.SkipTest("No function named %s in module %s" % ( + name, module.__name__)) + else: + return function + + verbose = 1 # Flag set to 0 by regrtest.py use_resources = None # Flag set to [] by regrtest.py max_memuse = 0 # Disable bigmem tests (they will still be run with diff --git a/Lib/test/test_ttk_guionly.py b/Lib/test/test_ttk_guionly.py index 831a222..aa17c47 100644 --- a/Lib/test/test_ttk_guionly.py +++ b/Lib/test/test_ttk_guionly.py @@ -1,10 +1,12 @@ import os import sys -import ttk import unittest -from _tkinter import TclError from test import test_support +ttk = test_support.import_module('ttk') +#If ttk exists _tkinter must exist. +from _tkinter import TclError + try: ttk.Button() except TclError, msg: diff --git a/Lib/test/test_winreg.py b/Lib/test/test_winreg.py index f2ec2a8..1dbccc0 100644 --- a/Lib/test/test_winreg.py +++ b/Lib/test/test_winreg.py @@ -1,12 +1,15 @@ # Test the windows specific win32reg module. # Only win32reg functions not hit here: FlushKey, LoadKey and SaveKey -from _winreg import * import os, sys import unittest - from test import test_support +#Do this first so test will be skipped if module doesn't exist +test_support.import_module('_winreg') +#Now import everything +from _winreg import * + test_key_name = "SOFTWARE\\Python Registry Test Key - Delete Me" test_data = [ diff --git a/Lib/test/test_winsound.py b/Lib/test/test_winsound.py index 1ed43c1..cba6ee6 100644 --- a/Lib/test/test_winsound.py +++ b/Lib/test/test_winsound.py @@ -2,10 +2,12 @@ import unittest from test import test_support -import winsound, time +import time import os import subprocess +winsound = test_support.import_module('winsound') + class BeepTest(unittest.TestCase): # As with PlaySoundTest, incorporate the _have_soundcard() check |