diff options
author | Barry Warsaw <barry@python.org> | 2002-07-30 23:27:12 (GMT) |
---|---|---|
committer | Barry Warsaw <barry@python.org> | 2002-07-30 23:27:12 (GMT) |
commit | 408b6d34de2b1a6ba690557def435adce9314184 (patch) | |
tree | 9d4e40110765646f7033a740641ef67750d17b91 /Lib/test | |
parent | 1bc894b1333ff0fd0d8b175f6748798e5fd08aed (diff) | |
download | cpython-408b6d34de2b1a6ba690557def435adce9314184.zip cpython-408b6d34de2b1a6ba690557def435adce9314184.tar.gz cpython-408b6d34de2b1a6ba690557def435adce9314184.tar.bz2 |
Complete the absolute import patch for the test suite. All relative
imports of test modules now import from the test package. Other
related oddities are also fixed (like DeprecationWarning filters that
weren't specifying the full import part, etc.). Also did a general
code cleanup to remove all "from test.test_support import *"'s. Other
from...import *'s weren't changed.
Diffstat (limited to 'Lib/test')
45 files changed, 77 insertions, 56 deletions
diff --git a/Lib/test/autotest.py b/Lib/test/autotest.py index 57f371b..41c2088 100644 --- a/Lib/test/autotest.py +++ b/Lib/test/autotest.py @@ -2,5 +2,5 @@ # It can be especially handy if you're in an interactive shell, e.g., # from test import autotest. -import regrtest +from test import regrtest regrtest.main() diff --git a/Lib/test/double_const.py b/Lib/test/double_const.py index 5ea6de0..16c33a1 100644 --- a/Lib/test/double_const.py +++ b/Lib/test/double_const.py @@ -1,4 +1,4 @@ -from test_support import TestFailed +from test.test_support import TestFailed # A test for SF bug 422177: manifest float constants varied way too much in # precision depending on whether Python was loading a module for the first diff --git a/Lib/test/pickletester.py b/Lib/test/pickletester.py index 2576e8f..870a8d6 100644 --- a/Lib/test/pickletester.py +++ b/Lib/test/pickletester.py @@ -1,5 +1,5 @@ import unittest -from test_support import TestFailed, have_unicode +from test.test_support import TestFailed, have_unicode class C: def __cmp__(self, other): diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index 4d71e21..1fa5d50 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -244,8 +244,8 @@ def main(tests=None, testdir=None, verbose=0, quiet=0, generate=0, print "All", print count(len(good), "test"), "OK." if verbose: - print "CAUTION: stdout isn't compared in verbose mode: a test" - print "that passes in verbose mode may fail without it." + print "CAUTION: stdout isn't compared in verbose mode:" + print "a test that passes in verbose mode may fail without it." if bad: print count(len(bad), "test"), "failed:" printlist(bad) @@ -338,7 +338,13 @@ def runtest(test, generate, verbose, quiet, testdir = None): if cfp: sys.stdout = cfp print test # Output file starts with test name - the_module = __import__(test, globals(), locals(), []) + if test.startswith('test.'): + abstest = test + else: + # Always import it from the test package + abstest = 'test.' + test + the_package = __import__(abstest, globals(), locals(), []) + the_module = getattr(the_package, test) # Most tests run to completion simply as a side-effect of # being imported. For the benefit of tests that can't run # that way (like test_threaded_import), explicitly invoke @@ -784,4 +790,18 @@ class _ExpectedSkips: return self.expected if __name__ == '__main__': + # Remove regrtest.py's own directory from the module search path. This + # prevents relative imports from working, and relative imports will screw + # up the testing framework. E.g. if both test.test_support and + # test_support are imported, they will not contain the same globals, and + # much of the testing framework relies on the globals in the + # test.test_support module. + mydir = os.path.abspath(os.path.normpath(os.path.dirname(sys.argv[0]))) + i = pathlen = len(sys.path) + while i >= 0: + i -= 1 + if os.path.abspath(os.path.normpath(sys.path[i])) == mydir: + del sys.path[i] + if len(sys.path) == pathlen: + print 'Could not find %r in sys.path to remove it' % mydir main() diff --git a/Lib/test/string_tests.py b/Lib/test/string_tests.py index b645354..47d7510 100644 --- a/Lib/test/string_tests.py +++ b/Lib/test/string_tests.py @@ -1,7 +1,7 @@ """Common tests shared by test_string and test_userstring""" import string -from test_support import verify, verbose, TestFailed, have_unicode +from test.test_support import verify, verbose, TestFailed, have_unicode transtable = '\000\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037 !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`xyzdefghijklmnopqrstuvwxyz{|}~\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377' diff --git a/Lib/test/test___all__.py b/Lib/test/test___all__.py index 01c918c..0a988fa 100644 --- a/Lib/test/test___all__.py +++ b/Lib/test/test___all__.py @@ -1,4 +1,4 @@ -from test_support import verify, verbose +from test.test_support import verify, verbose import sys import warnings diff --git a/Lib/test/test_al.py b/Lib/test/test_al.py index d11c7e5..66955ba 100755 --- a/Lib/test/test_al.py +++ b/Lib/test/test_al.py @@ -3,7 +3,7 @@ Roger E. Masse """ import al -from test_support import verbose +from test.test_support import verbose alattrs = ['__doc__', '__name__', 'getdefault', 'getminmax', 'getname', 'getparams', 'newconfig', 'openport', 'queryparams', 'setparams'] diff --git a/Lib/test/test_atexit.py b/Lib/test/test_atexit.py index 9b93b68..c9d72a7 100644 --- a/Lib/test/test_atexit.py +++ b/Lib/test/test_atexit.py @@ -1,5 +1,5 @@ # Test the atexit module. -from test_support import TESTFN, vereq +from test.test_support import TESTFN, vereq import atexit from os import popen, unlink import sys diff --git a/Lib/test/test_b1.py b/Lib/test/test_b1.py index cd828b1..37e7cdf 100644 --- a/Lib/test/test_b1.py +++ b/Lib/test/test_b1.py @@ -1,6 +1,6 @@ # Python test set -- part 4a, built-in functions a-m -from test_support import * +from test.test_support import TestFailed, fcmp, have_unicode, TESTFN, unlink print '__import__' __import__('sys') diff --git a/Lib/test/test_b2.py b/Lib/test/test_b2.py index a8bc22a..b59d3ab 100644 --- a/Lib/test/test_b2.py +++ b/Lib/test/test_b2.py @@ -1,6 +1,6 @@ # Python test set -- part 4b, built-in functions n-z -from test_support import * +from test.test_support import TestFailed, fcmp, TESTFN, unlink, vereq print 'oct' if oct(100) != '0144': raise TestFailed, 'oct(100)' diff --git a/Lib/test/test_binascii.py b/Lib/test/test_binascii.py index 2c59160..f1f8b33 100755 --- a/Lib/test/test_binascii.py +++ b/Lib/test/test_binascii.py @@ -1,6 +1,6 @@ """Test the binascii C module.""" -from test_support import verify, verbose, have_unicode +from test.test_support import verify, verbose, have_unicode import binascii # Show module doc string diff --git a/Lib/test/test_bisect.py b/Lib/test/test_bisect.py index 1292915..a226537 100644 --- a/Lib/test/test_bisect.py +++ b/Lib/test/test_bisect.py @@ -1,4 +1,4 @@ -from test_support import TestFailed +from test.test_support import TestFailed import bisect import sys diff --git a/Lib/test/test_bufio.py b/Lib/test/test_bufio.py index 12359c4..611cd69 100644 --- a/Lib/test/test_bufio.py +++ b/Lib/test/test_bufio.py @@ -1,4 +1,4 @@ -from test_support import verify, TestFailed, TESTFN +from test.test_support import verify, TestFailed, TESTFN # Simple test to ensure that optimizations in fileobject.c deliver # the expected results. For best testing, run this under a debug-build diff --git a/Lib/test/test_builtin.py b/Lib/test/test_builtin.py index 33fef8d..79a395c 100644 --- a/Lib/test/test_builtin.py +++ b/Lib/test/test_builtin.py @@ -1,13 +1,13 @@ # Python test set -- part 4, built-in functions -from test_support import * +from test.test_support import unload print '4. Built-in functions' print 'test_b1' unload('test_b1') -import test_b1 +from test import test_b1 print 'test_b2' unload('test_b2') -import test_b2 +from test import test_b2 diff --git a/Lib/test/test_cd.py b/Lib/test/test_cd.py index 9a45a7d..9a65a7d 100755 --- a/Lib/test/test_cd.py +++ b/Lib/test/test_cd.py @@ -3,7 +3,7 @@ Roger E. Masse """ import cd -from test_support import verbose +from test.test_support import verbose cdattrs = ['BLOCKSIZE', 'CDROM', 'DATASIZE', 'ERROR', 'NODISC', 'PAUSED', 'PLAYING', 'READY', 'STILL', '__doc__', '__name__', 'atime', 'audio', 'catalog', 'control', 'createparser', 'error', diff --git a/Lib/test/test_cfgparser.py b/Lib/test/test_cfgparser.py index 6a6fecb..fae8a17 100644 --- a/Lib/test/test_cfgparser.py +++ b/Lib/test/test_cfgparser.py @@ -1,7 +1,7 @@ import ConfigParser import StringIO -from test_support import TestFailed, verify +from test.test_support import TestFailed, verify def basic(src): diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py index b1f5758..980e3b6 100644 --- a/Lib/test/test_cgi.py +++ b/Lib/test/test_cgi.py @@ -1,4 +1,4 @@ -from test_support import verify, verbose +from test.test_support import verify, verbose import cgi import os import sys diff --git a/Lib/test/test_cl.py b/Lib/test/test_cl.py index 26c5146..d3efe9f 100755 --- a/Lib/test/test_cl.py +++ b/Lib/test/test_cl.py @@ -3,7 +3,7 @@ Roger E. Masse """ import cl -from test_support import verbose +from test.test_support import verbose clattrs = ['ADDED_ALGORITHM_ERROR', 'ALAW', 'ALGORITHM_ID', 'ALGORITHM_VERSION', 'AUDIO', 'AWARE_ERROR', 'AWARE_MPEG_AUDIO', diff --git a/Lib/test/test_class.py b/Lib/test/test_class.py index 5240b3a..e90a790 100644 --- a/Lib/test/test_class.py +++ b/Lib/test/test_class.py @@ -1,6 +1,6 @@ "Test the functionality of Python classes implementing operators." -from test_support import TestFailed +from test.test_support import TestFailed testmeths = [ diff --git a/Lib/test/test_coercion.py b/Lib/test/test_coercion.py index afade35..be5b744 100644 --- a/Lib/test/test_coercion.py +++ b/Lib/test/test_coercion.py @@ -113,6 +113,6 @@ def do_prefix_binops(): warnings.filterwarnings("ignore", r'complex divmod\(\), // and % are deprecated', DeprecationWarning, - r'test_coercion$') + r'test.test_coercion$') do_infix_binops() do_prefix_binops() diff --git a/Lib/test/test_compare.py b/Lib/test/test_compare.py index 8100aec..6899926 100644 --- a/Lib/test/test_compare.py +++ b/Lib/test/test_compare.py @@ -1,7 +1,5 @@ import sys -from test_support import * - class Empty: def __repr__(self): return '<Empty>' diff --git a/Lib/test/test_complex.py b/Lib/test/test_complex.py index ff7bb14..8a02f7f 100644 --- a/Lib/test/test_complex.py +++ b/Lib/test/test_complex.py @@ -1,4 +1,4 @@ -from test_support import TestFailed, vereq +from test.test_support import TestFailed, vereq from random import random # These tests ensure that complex math does the right thing; tests of diff --git a/Lib/test/test_contains.py b/Lib/test/test_contains.py index 1a9a965..9abed15 100644 --- a/Lib/test/test_contains.py +++ b/Lib/test/test_contains.py @@ -1,4 +1,4 @@ -from test_support import TestFailed, have_unicode +from test.test_support import TestFailed, have_unicode class base_set: diff --git a/Lib/test/test_doctest2.py b/Lib/test/test_doctest2.py index 31bf6e8..3593d41 100644 --- a/Lib/test/test_doctest2.py +++ b/Lib/test/test_doctest2.py @@ -93,7 +93,7 @@ class C(object): clsm = classmethod(clsm) def test_main(): - import test_doctest2 + from test import test_doctest2 EXPECTED = 19 f, t = test_support.run_doctest(test_doctest2) if t != EXPECTED: diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index c2fbec6..24ae9e3 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -1,6 +1,6 @@ # Python test set -- part 5, built-in exceptions -from test_support import * +from test.test_support import TestFailed, TESTFN, unlink from types import ClassType import warnings import sys, traceback diff --git a/Lib/test/test_extcall.py b/Lib/test/test_extcall.py index 1e80387..30439a4 100644 --- a/Lib/test/test_extcall.py +++ b/Lib/test/test_extcall.py @@ -1,4 +1,4 @@ -from test_support import verify, verbose, TestFailed, sortdict +from test.test_support import verify, verbose, TestFailed, sortdict from UserList import UserList def f(*a, **k): diff --git a/Lib/test/test_file.py b/Lib/test/test_file.py index 261db2c..1eb8418 100644 --- a/Lib/test/test_file.py +++ b/Lib/test/test_file.py @@ -2,7 +2,7 @@ import sys import os from array import array -from test_support import verify, TESTFN, TestFailed +from test.test_support import verify, TESTFN, TestFailed from UserList import UserList # verify writelines with instance sequence diff --git a/Lib/test/test_frozen.py b/Lib/test/test_frozen.py index 3aa91ab..120a85f 100644 --- a/Lib/test/test_frozen.py +++ b/Lib/test/test_frozen.py @@ -1,6 +1,6 @@ # Test the frozen module defined in frozen.c. -from test_support import TestFailed +from test.test_support import TestFailed import sys, os try: diff --git a/Lib/test/test_funcattrs.py b/Lib/test/test_funcattrs.py index 293b911..3dc888c 100644 --- a/Lib/test/test_funcattrs.py +++ b/Lib/test/test_funcattrs.py @@ -1,4 +1,4 @@ -from test_support import verbose, TestFailed, verify +from test.test_support import verbose, TestFailed, verify import types class F: diff --git a/Lib/test/test_future.py b/Lib/test/test_future.py index 62bc857..12813d4 100644 --- a/Lib/test/test_future.py +++ b/Lib/test/test_future.py @@ -12,36 +12,36 @@ def check_error_location(msg): # The first two tests should work unload('test_future1') -import test_future1 +from test import test_future1 unload('test_future2') -import test_future2 +from test import test_future2 unload('test_future3') -import test_future3 +from test import test_future3 # The remaining tests should fail try: - import badsyntax_future3 + from test import badsyntax_future3 except SyntaxError, msg: check_error_location(str(msg)) try: - import badsyntax_future4 + from test import badsyntax_future4 except SyntaxError, msg: check_error_location(str(msg)) try: - import badsyntax_future5 + from test import badsyntax_future5 except SyntaxError, msg: check_error_location(str(msg)) try: - import badsyntax_future6 + from test import badsyntax_future6 except SyntaxError, msg: check_error_location(str(msg)) try: - import badsyntax_future7 + from test import badsyntax_future7 except SyntaxError, msg: check_error_location(str(msg)) diff --git a/Lib/test/test_getargs.py b/Lib/test/test_getargs.py index ff0d36c..4ce34bc 100644 --- a/Lib/test/test_getargs.py +++ b/Lib/test/test_getargs.py @@ -14,7 +14,7 @@ single case that failed between 2.1 and 2.2a2. # XXX If the encoding succeeds using the current default encoding, # this test will fail because it does not test the right part of the # PyArg_ParseTuple() implementation. -from test_support import have_unicode +from test.test_support import have_unicode import marshal if have_unicode: diff --git a/Lib/test/test_gl.py b/Lib/test/test_gl.py index 61eaa83..c9cce77 100755 --- a/Lib/test/test_gl.py +++ b/Lib/test/test_gl.py @@ -3,7 +3,7 @@ taken mostly from the documentation. Roger E. Masse """ -from test_support import verbose, TestSkipped +from test.test_support import verbose, TestSkipped import gl, GL, time glattrs = ['RGBcolor', 'RGBcursor', 'RGBmode', 'RGBrange', 'RGBwritemask', diff --git a/Lib/test/test_global.py b/Lib/test/test_global.py index fb10533..4cc953c 100644 --- a/Lib/test/test_global.py +++ b/Lib/test/test_global.py @@ -1,6 +1,6 @@ """Verify that warnings are issued for global statements following use.""" -from test_support import check_syntax +from test.test_support import check_syntax import warnings diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py index bb843fb..c77e19e 100644 --- a/Lib/test/test_grammar.py +++ b/Lib/test/test_grammar.py @@ -1,7 +1,7 @@ # Python test set -- part 1, grammar. # This just tests whether the parser accepts them all. -from test_support import * +from test.test_support import TestFailed, verify, check_syntax import sys print '1. Parser' diff --git a/Lib/test/test_gzip.py b/Lib/test/test_gzip.py index d42dee6..9156d9e 100644 --- a/Lib/test/test_gzip.py +++ b/Lib/test/test_gzip.py @@ -1,4 +1,4 @@ -from test_support import verify +from test.test_support import verify import sys, os import gzip, tempfile diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index f70abec..4d8dbc8 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -1,4 +1,4 @@ -from test_support import verify,verbose +from test.test_support import verify,verbose import httplib import StringIO diff --git a/Lib/test/test_math.py b/Lib/test/test_math.py index 5101381..2d9b55b 100644 --- a/Lib/test/test_math.py +++ b/Lib/test/test_math.py @@ -1,7 +1,7 @@ # Python test set -- math module # XXXX Should not do tests around zero only -from test.test_support import * +from test.test_support import TestFailed, verbose seps='1e-05' eps = eval(seps) diff --git a/Lib/test/test_opcodes.py b/Lib/test/test_opcodes.py index 515df6c..c192963 100644 --- a/Lib/test/test_opcodes.py +++ b/Lib/test/test_opcodes.py @@ -1,6 +1,6 @@ # Python test set -- part 2, opcodes -from test.test_support import * +from test.test_support import TestFailed print '2. Opcodes' diff --git a/Lib/test/test_pickle.py b/Lib/test/test_pickle.py index 935a763..87c73c2 100644 --- a/Lib/test/test_pickle.py +++ b/Lib/test/test_pickle.py @@ -1,7 +1,7 @@ import pickle import unittest from cStringIO import StringIO -from pickletester import AbstractPickleTests, AbstractPickleModuleTests +from test.pickletester import AbstractPickleTests, AbstractPickleModuleTests from test import test_support class PickleTests(AbstractPickleTests, AbstractPickleModuleTests): diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index 5475416..a20c82f 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -267,7 +267,7 @@ try: except RuntimeError, v: print v -from re_tests import * +from test.re_tests import * if verbose: print 'Running re_tests test suite' diff --git a/Lib/test/test_sre.py b/Lib/test/test_sre.py index 4f2aae8..284212c 100644 --- a/Lib/test/test_sre.py +++ b/Lib/test/test_sre.py @@ -298,7 +298,7 @@ test("sre.match('(x)*', 50000*'x').span()", (0, 50000), RuntimeError) test("sre.match(r'(x)*y', 50000*'x'+'y').span()", (0, 50001), RuntimeError) test("sre.match(r'(x)*?y', 50000*'x'+'y').span()", (0, 50001), RuntimeError) -from re_tests import * +from test.re_tests import * if verbose: print 'Running re_tests test suite' diff --git a/Lib/test/test_strop.py b/Lib/test/test_strop.py index 4f5ba00..2ac7986 100644 --- a/Lib/test/test_strop.py +++ b/Lib/test/test_strop.py @@ -1,7 +1,7 @@ import warnings warnings.filterwarnings("ignore", "strop functions are obsolete;", DeprecationWarning, - r'test_strop|unittest') + r'test.test_strop|unittest') import strop import unittest from test import test_support diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index 4a45617..948c645 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -1,5 +1,8 @@ """Supporting definitions for the Python regression test.""" +if __name__ != 'test.test_support': + raise ImportError, 'test_support must be imported from the test package' + import sys class Error(Exception): diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index 4422118..a0b3150 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -22,7 +22,7 @@ class TracebackCases(unittest.TestCase): def syntax_error_without_caret(self): # XXX why doesn't compile raise the same traceback? - import badsyntax_nocaret + import test.badsyntax_nocaret def test_caret(self): err = self.get_exception_format(self.syntax_error_with_caret, diff --git a/Lib/test/test_unpack.py b/Lib/test/test_unpack.py index fb22564..a8fd09c 100644 --- a/Lib/test/test_unpack.py +++ b/Lib/test/test_unpack.py @@ -1,4 +1,4 @@ -from test.test_support import * +from test.test_support import TestFailed, verbose t = (1, 2, 3) l = [4, 5, 6] |