Commit 59beec32 authored by R. David Murray's avatar R. David Murray

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.
parent bb8cb0e1
# 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'),
......
# 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
......
# 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'
......
......@@ -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',
......
......@@ -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',
......
from test import test_support
import unittest
import crypt
crypt = test_support.import_module('crypt')
class CryptTestCase(unittest.TestCase):
......
......@@ -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):
......
......@@ -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',
......
"""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):
......
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):
......
# 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):
......
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):
......
......@@ -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)
......
import unittest
from test import test_support
import pwd
pwd = test_support.import_module('pwd')
class PwdTest(unittest.TestCase):
......
......@@ -2,7 +2,8 @@
import unittest
from test import test_support
import aetools
aetools = test_support.import_module('aetools')
class TestScriptpackages(unittest.TestCase):
......
......@@ -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):
......
......@@ -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
......
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:
......
# 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 = [
......
......@@ -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
......
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