# 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())
# 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):
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)
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
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
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
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
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 = [
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:
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):
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:
# 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))
# 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:
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):
except RuntimeError, v:
print v
-from re_tests import *
+from test.re_tests import *
if verbose:
print 'Running re_tests test suite'
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):
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]