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