Kaydet (Commit) 3db8a343 authored tarafından R. David Murray's avatar R. David Murray

Change more tests to use import_module for the modules that

should cause tests to be skipped.  Also rename import_function
to the more descriptive get_attribute and add a docstring.
üst dc340eed
......@@ -7,7 +7,11 @@ import sys
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 cannot import _bsddb.
import_module('bsddb')
# When running as a script instead of within the regrtest framework, skip the
# requires test, since it's obvious we want to run them.
......
#!/usr/bin/python
from test import test_support
from test.test_support import TESTFN
from test.test_support import TESTFN, import_module
import unittest
from cStringIO import StringIO
......@@ -8,7 +8,7 @@ import os
import subprocess
import sys
import bz2
bz2 = import_module('bz2')
from bz2 import BZ2File, BZ2Compressor, BZ2Decompressor
has_cmdline_bunzip2 = sys.platform not in ("win32", "os2emx", "riscos")
......
import unittest
from test.test_support import run_unittest
from test.test_support import run_unittest, import_module
#Skip tests if _ctypes module does not exist
import_module('_ctypes')
import ctypes.test
def test_main():
......
......@@ -9,15 +9,16 @@
# Only called, not tested: getmouse(), ungetmouse()
#
import curses, sys, tempfile, os
import curses.panel
import sys, tempfile, os
# Optionally test curses module. This currently requires that the
# 'curses' resource be given on the regrtest command line using the -u
# option. If not available, nothing after this line will be executed.
from test.test_support import requires
from test.test_support import requires, import_module
requires('curses')
curses = import_module('curses')
curses.panel = import_module('curses.panel')
# XXX: if newterm was supported we could use it instead of initscr and not exit
term = os.environ.get('TERM')
......
from test import test_support
import unittest
import dbm
dbm = test_support.import_module('dbm')
class DbmTestCase(unittest.TestCase):
......
......@@ -4,10 +4,10 @@
import os
import time
from test.fork_wait import ForkWait
from test.test_support import run_unittest, reap_children, import_function
from test.test_support import run_unittest, reap_children, get_attribute
#Skip test if fork does not exist.
import_function(os, 'fork')
get_attribute(os, 'fork')
class ForkTest(ForkWait):
......
import gdbm
import unittest
import os
from test.test_support import verbose, TESTFN, run_unittest, unlink
from test.test_support import (verbose, TESTFN, run_unittest, unlink,
import_module)
gdbm = import_module('gdbm')
filename = TESTFN
......
import unittest
from test.test_support import run_unittest
from test.test_support import run_unittest, import_module, get_attribute
import os, struct
try:
import fcntl, termios
except ImportError:
raise unittest.SkipTest("No fcntl or termios module")
if not hasattr(termios,'TIOCGPGRP'):
raise unittest.SkipTest("termios module doesn't have TIOCGPGRP")
fcntl = import_module('fcntl')
termios = import_module('termios')
get_attribute(termios, 'TIOCGPGRP') #Can't run tests without this feature
try:
tty = open("/dev/tty", "r")
......
......@@ -17,20 +17,19 @@ import copy
import socket
import random
import logging
import test_support
_multiprocessing = test_support.import_module('_multiprocessing')
# Work around broken sem_open implementations
try:
import multiprocessing.synchronize
except ImportError, e:
raise unittest.SkipTest(e)
test_support.import_module('multiprocessing.synchronize')
import multiprocessing.dummy
import multiprocessing.connection
import multiprocessing.managers
import multiprocessing.heap
import multiprocessing.pool
import _multiprocessing
from multiprocessing import util
......
from test import test_support
import unittest
import nis
nis = test_support.import_module('nis')
class NisTests(unittest.TestCase):
def test_maps(self):
......
......@@ -3,8 +3,9 @@ test_support.requires('audio')
from test.test_support import findfile
ossaudiodev = test_support.import_module('ossaudiodev')
import errno
import ossaudiodev
import sys
import sunau
import time
......
import unittest
from test import test_support
import resource
import time
resource = test_support.import_module('resource')
# This test is checking a few specific problem spots with the resource module.
class ResourceTest(unittest.TestCase):
......
import unittest
from test.test_support import run_unittest
from test.test_support import run_unittest, import_module
#Skip test of _sqlite3 module not installed
import_module('_sqlite3')
try:
import _sqlite3
except ImportError:
raise unittest.SkipTest('no sqlite available')
from sqlite3.test import (dbapi, types, userfunctions, py25tests,
factory, transactions, hooks, regression,
dump)
......
......@@ -12,7 +12,7 @@ from test import test_support
import os
from os import path
startfile = test_support.import_function(os, 'startfile')
startfile = test_support.get_attribute(os, 'startfile')
class TestCase(unittest.TestCase):
......
......@@ -12,6 +12,7 @@ import platform
import shutil
import warnings
import unittest
import importlib
__all__ = ["Error", "TestFailed", "ResourceDenied", "import_module",
"verbose", "use_resources", "max_memuse", "record_original_stdout",
......@@ -25,7 +26,7 @@ __all__ = ["Error", "TestFailed", "ResourceDenied", "import_module",
"run_with_locale", "set_memlimit", "bigmemtest", "bigaddrspacetest",
"BasicTestRunner", "run_unittest", "run_doctest", "threading_setup",
"threading_cleanup", "reap_children", "cpython_only",
"check_impl_detail"]
"check_impl_detail", "get_attribute"]
class Error(Exception):
"""Base class for regression test exceptions."""
......@@ -49,24 +50,26 @@ def import_module(name, deprecated=False):
warnings.filterwarnings("ignore", ".+ (module|package)",
DeprecationWarning)
try:
module = __import__(name, level=0)
module = importlib.import_module(name)
except ImportError:
raise unittest.SkipTest("No module named " + name)
else:
return module
def import_function(module, name, deprecated=False):
def get_attribute(module, name, deprecated=False):
"""Get an attribute from the module, raising SkipTest if it is
not available."""
with warnings.catch_warnings():
if deprecated:
warnings.filterwarnings("ignore", ".+ (module|package)",
DeprecationWarning)
try:
function = getattr(module, name)
attribute = getattr(module, name)
except AttributeError:
raise unittest.SkipTest("No function named %s in module %s" % (
name, module.__name__))
raise unittest.SkipTest("module %s has no attribute %s" % (
module.__name__, name))
else:
return function
return attribute
verbose = 1 # Flag set to 0 by regrtest.py
......
......@@ -5,7 +5,7 @@ import sys
from test import test_support
from xml.etree import cElementTree as ET
ET = test_support.import_module('xml.etree.cElementTree')
SAMPLE_XML = """
<body>
......
import unittest
from test import test_support
import zlib
import binascii
import random
zlib = test_support.import_module('zlib')
class ChecksumTestCase(unittest.TestCase):
# checksum test cases
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment