]> granicus.if.org Git - python/commitdiff
Add import_function method to test.test_support, and modify a number of
authorR. David Murray <rdmurray@bitdance.com>
Mon, 30 Mar 2009 19:04:00 +0000 (19:04 +0000)
committerR. David Murray <rdmurray@bitdance.com>
Mon, 30 Mar 2009 19:04:00 +0000 (19:04 +0000)
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.

20 files changed:
Lib/test/test_aepack.py
Lib/test/test_applesingle.py
Lib/test/test_asynchat.py
Lib/test/test_cd.py
Lib/test/test_cl.py
Lib/test/test_crypt.py
Lib/test/test_fork1.py
Lib/test/test_gl.py
Lib/test/test_grp.py
Lib/test/test_macos.py
Lib/test/test_macostools.py
Lib/test/test_mmap.py
Lib/test/test_posix.py
Lib/test/test_pwd.py
Lib/test/test_scriptpackages.py
Lib/test/test_startfile.py
Lib/test/test_support.py
Lib/test/test_ttk_guionly.py
Lib/test/test_winreg.py
Lib/test/test_winsound.py

index 8a4b035f05cf327ef7a972699863699d43ed337b..5d4ab3e20b0797a37ebb0ab8fd397e1a4f9e02bc 100755 (executable)
@@ -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'),
index e915028dca3e272f240436e88d92410bf328988e..5a8201c3d0e9aa5ed675e4dd4d1fbdb31310e401 100644 (file)
@@ -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
index 5501c2defc35c09469d1da5e3cf5f8e5e3f335f2..14528d8800857fe85b51420fd81db88d86d4deae 100644 (file)
@@ -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'
 
index daad223828290e79ef34c815e0195d7e645566de..edaa82bf4537facfc60b2d7f43627119bfe914c1 100755 (executable)
@@ -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',
index a2728b7df1d5e13eacff8996faa7f4205b06ba41..50102e92679a99f114f054415b58b4cf6b36dcbf 100755 (executable)
@@ -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',
index f6f3a8171edc799a58b5eb9e06d0d99777782276..4db200d4031b740764867b62bffe184dc99ed0ba 100755 (executable)
@@ -1,6 +1,7 @@
 from test import test_support
 import unittest
-import crypt
+
+crypt = test_support.import_module('crypt')
 
 class CryptTestCase(unittest.TestCase):
 
index dfd501665ce31a2929c0b217223a681280e5f76d..93062421209c123c251830d4f28d5502ca68c3fa 100644 (file)
@@ -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):
index 1da55a071a2f4f61f272f9520dd51fbf72a07f89..be7604186375b77fe2742b2450d5bd22cfa30932 100755 (executable)
@@ -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',
index 564c7f006717b2f773dc745c90eb9ad61295eea0..b38b94c5a5c45e9e693b8e628c847f93e0b58957 100755 (executable)
@@ -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):
index a9ff0b21d36faf629f2cb1b774ae4bb7fcabda43..ce5f858dde9fbb573891062fc40bc3a148559d33 100644 (file)
@@ -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):
index 6110ce3dff2113d6ee30933a9e0f1e0fa0d77525..b84ad7202e45b0dd3f907f27e702f4a9685263d5 100644 (file)
@@ -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):
index 31daa8df11d09708ab087a4831140b4fb167b85a..2dd76ad9ff676167e5f84c34cf890b4a51d906cf 100644 (file)
@@ -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):
index 864f96373ad8ed0c6a293dcaf8c96952461de73a..a7255c41c567d31ce5869698e03cc1eab5c9c5d4 100644 (file)
@@ -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)
 
index 255a34c6d4730411b61713a0692600f98e0deedc..de4084e48818844bbcf3cb129e3a12a2b9c5f296 100644 (file)
@@ -1,7 +1,7 @@
 import unittest
 from test import test_support
 
-import pwd
+pwd = test_support.import_module('pwd')
 
 class PwdTest(unittest.TestCase):
 
index ee14be2bb4b1c261a9a3866efd6708c1ca35760e..a3a1857d8502c631fa815838bf3d94aa2164dae5 100644 (file)
@@ -2,7 +2,8 @@
 
 import unittest
 from test import test_support
-import aetools
+
+aetools = test_support.import_module('aetools')
 
 class TestScriptpackages(unittest.TestCase):
 
index c4d12d708e8af223642f8b0116c5ade167ae3f49..23e2708cc1589dab2504c032d36a40db02015baa 100644 (file)
@@ -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):
index 4ad24015c897c6874bb4b0d5bf902b027af7ada5..90bd8e6a0544f666eea62fa069a8e01440108772 100644 (file)
@@ -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
index 831a22221aaedaf0f2ae41e365d8d25cdaf5b5da..aa17c4772ecf5ddb51b0ac14db10feb71d62b859 100644 (file)
@@ -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:
index f2ec2a8c0f89c76517b3b3fefaf5f96776fe732d..1dbccc0027e4be6d732b9190ab411dd8237ef184 100644 (file)
@@ -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 = [
index 1ed43c162d2788cde20d45f5b80c52d4e8add776..cba6ee6d36811805b15df61af5bc4200e48945ba 100644 (file)
@@ -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