Commit 9a7b9edc authored by Barry Warsaw's avatar Barry Warsaw

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.
parent 20a15202
......@@ -173,10 +173,8 @@ if __name__ == "__main__":
# execute the regression test to stdout, if called as a script:
import os
called_in_dir, called_as = os.path.split(sys.argv[0])
called_in_dir = os.path.abspath(called_in_dir)
called_as, py = os.path.splitext(called_as)
sys.path.append(os.path.join(called_in_dir, 'test'))
if '-q' in sys.argv:
import test_support
from test import test_support
test_support.verbose = 0
__import__('test_' + called_as.lower())
__import__('test.test_' + called_as.lower())
......@@ -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()
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
......
import unittest
from test_support import TestFailed, have_unicode
from test.test_support import TestFailed, have_unicode
class C:
def __cmp__(self, other):
......
......@@ -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()
"""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'
......
from test_support import verify, verbose
from test.test_support import verify, verbose
import sys
import warnings
......
......@@ -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']
......
# 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
......
# 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')
......
# 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)'
......
"""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
......
from test_support import TestFailed
from test.test_support import TestFailed
import bisect
import sys
......
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
......
# 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
......@@ -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',
......
import ConfigParser
import StringIO
from test_support import TestFailed, verify
from test.test_support import TestFailed, verify
def basic(src):
......
from test_support import verify, verbose
from test.test_support import verify, verbose
import cgi
import os
import sys
......
......@@ -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',
......
"Test the functionality of Python classes implementing operators."
from test_support import TestFailed
from test.test_support import TestFailed
testmeths = [
......
......@@ -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()
import sys
from test_support import *
class Empty:
def __repr__(self):
return '<Empty>'
......
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
......
from test_support import TestFailed, have_unicode
from test.test_support import TestFailed, have_unicode
class base_set:
......
......@@ -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:
......
# 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
......
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):
......
......@@ -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
......
# Test the frozen module defined in frozen.c.
from test_support import TestFailed
from test.test_support import TestFailed
import sys, os
try:
......
from test_support import verbose, TestFailed, verify
from test.test_support import verbose, TestFailed, verify
import types
class F:
......
......@@ -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))
......@@ -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:
......
......@@ -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',
......
"""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
......
# 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'
......
from test_support import verify
from test.test_support import verify
import sys, os
import gzip, tempfile
......
from test_support import verify,verbose
from test.test_support import verify,verbose
import httplib
import StringIO
......
# 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)
......
# Python test set -- part 2, opcodes
from test.test_support import *
from test.test_support import TestFailed
print '2. Opcodes'
......
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):
......
......@@ -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'
......
......@@ -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'
......
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
......
"""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):
......
......@@ -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,
......
from test.test_support import *
from test.test_support import TestFailed, verbose
t = (1, 2, 3)
l = [4, 5, 6]
......
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