1997-09-07 02:42:57 +08:00
|
|
|
# Test packages (dotted-name import)
|
|
|
|
|
2001-02-09 19:51:27 +08:00
|
|
|
import sys, os, tempfile, traceback
|
2007-08-16 22:35:24 +08:00
|
|
|
from os import mkdir, rmdir # Can't test if these fail
|
1997-09-07 02:42:57 +08:00
|
|
|
del mkdir, rmdir
|
2002-07-24 03:04:11 +08:00
|
|
|
from test.test_support import verify, verbose, TestFailed
|
1997-09-07 02:42:57 +08:00
|
|
|
|
|
|
|
# Helpers to create and destroy hierarchies.
|
|
|
|
|
|
|
|
def mkhier(root, descr):
|
2002-08-10 00:38:32 +08:00
|
|
|
if not os.path.isdir(root):
|
|
|
|
mkdir(root)
|
1997-09-07 02:42:57 +08:00
|
|
|
for name, contents in descr:
|
2001-02-09 19:51:27 +08:00
|
|
|
comps = name.split()
|
1998-03-27 03:42:58 +08:00
|
|
|
fullname = root
|
|
|
|
for c in comps:
|
|
|
|
fullname = os.path.join(fullname, c)
|
|
|
|
if contents is None:
|
|
|
|
mkdir(fullname)
|
|
|
|
else:
|
2007-02-09 13:37:30 +08:00
|
|
|
if verbose: print("write", fullname)
|
1998-03-27 03:42:58 +08:00
|
|
|
f = open(fullname, "w")
|
|
|
|
f.write(contents)
|
|
|
|
if contents and contents[-1] != '\n':
|
|
|
|
f.write('\n')
|
|
|
|
f.close()
|
1997-09-07 02:42:57 +08:00
|
|
|
|
|
|
|
def mkdir(x):
|
2007-02-09 13:37:30 +08:00
|
|
|
if verbose: print("mkdir", x)
|
1997-09-07 02:42:57 +08:00
|
|
|
os.mkdir(x)
|
|
|
|
|
|
|
|
def cleanout(root):
|
|
|
|
names = os.listdir(root)
|
|
|
|
for name in names:
|
1998-03-27 03:42:58 +08:00
|
|
|
fullname = os.path.join(root, name)
|
|
|
|
if os.path.isdir(fullname) and not os.path.islink(fullname):
|
|
|
|
cleanout(fullname)
|
|
|
|
else:
|
|
|
|
os.remove(fullname)
|
1997-09-07 02:42:57 +08:00
|
|
|
rmdir(root)
|
|
|
|
|
|
|
|
def rmdir(x):
|
2007-02-09 13:37:30 +08:00
|
|
|
if verbose: print("rmdir", x)
|
1997-09-07 02:42:57 +08:00
|
|
|
os.rmdir(x)
|
|
|
|
|
2000-09-01 14:53:52 +08:00
|
|
|
def fixdir(lst):
|
|
|
|
try:
|
|
|
|
lst.remove('__builtins__')
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
return lst
|
|
|
|
|
1997-09-07 02:42:57 +08:00
|
|
|
# Helper to run a test
|
|
|
|
|
|
|
|
def runtest(hier, code):
|
2002-08-10 00:38:32 +08:00
|
|
|
root = tempfile.mkdtemp()
|
1997-09-07 02:42:57 +08:00
|
|
|
mkhier(root, hier)
|
|
|
|
savepath = sys.path[:]
|
2002-08-14 23:41:26 +08:00
|
|
|
fd, fname = tempfile.mkstemp(text=True)
|
2002-08-14 09:05:57 +08:00
|
|
|
os.write(fd, code)
|
|
|
|
os.close(fd)
|
1997-09-07 02:42:57 +08:00
|
|
|
try:
|
1998-03-27 03:42:58 +08:00
|
|
|
sys.path.insert(0, root)
|
2007-02-09 13:37:30 +08:00
|
|
|
if verbose: print("sys.path =", sys.path)
|
1998-03-27 03:42:58 +08:00
|
|
|
try:
|
2007-08-12 08:43:29 +08:00
|
|
|
exec(open(fname).read(), globals(), {})
|
1998-03-27 03:42:58 +08:00
|
|
|
except:
|
|
|
|
traceback.print_exc(file=sys.stdout)
|
1997-09-07 02:42:57 +08:00
|
|
|
finally:
|
1998-03-27 03:42:58 +08:00
|
|
|
sys.path[:] = savepath
|
2002-08-14 09:05:57 +08:00
|
|
|
os.unlink(fname)
|
1998-03-27 03:42:58 +08:00
|
|
|
try:
|
|
|
|
cleanout(root)
|
|
|
|
except (os.error, IOError):
|
|
|
|
pass
|
1997-09-07 02:42:57 +08:00
|
|
|
|
|
|
|
# Test descriptions
|
|
|
|
|
|
|
|
tests = [
|
2007-08-16 22:35:24 +08:00
|
|
|
("t1", [("t1", None), ("t1 __init__.py", "")], "import t1"),
|
2000-10-24 01:22:08 +08:00
|
|
|
|
1997-09-07 02:42:57 +08:00
|
|
|
("t2", [
|
|
|
|
("t2", None),
|
2007-08-16 22:35:24 +08:00
|
|
|
("t2 __init__.py", "'doc for t2'; print(__name__, 'loading')"),
|
1997-09-07 02:42:57 +08:00
|
|
|
("t2 sub", None),
|
2007-08-16 22:35:24 +08:00
|
|
|
("t2 sub __init__.py", ""),
|
1997-09-07 02:42:57 +08:00
|
|
|
("t2 sub subsub", None),
|
2007-08-16 22:35:24 +08:00
|
|
|
("t2 sub subsub __init__.py", "print(__name__, 'loading'); spam = 1"),
|
1997-09-07 02:42:57 +08:00
|
|
|
],
|
|
|
|
"""
|
|
|
|
import t2
|
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
* Fix some docstrings and one Print -> print.
* Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}.
These were the ones that generated code with a print statement.
In most remaining failing tests there's an issue with the soft space.
2007-02-10 05:28:07 +08:00
|
|
|
print(t2.__doc__)
|
1997-09-07 02:42:57 +08:00
|
|
|
import t2.sub
|
|
|
|
import t2.sub.subsub
|
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
* Fix some docstrings and one Print -> print.
* Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}.
These were the ones that generated code with a print statement.
In most remaining failing tests there's an issue with the soft space.
2007-02-10 05:28:07 +08:00
|
|
|
print(t2.__name__, t2.sub.__name__, t2.sub.subsub.__name__)
|
1997-09-07 02:42:57 +08:00
|
|
|
import t2
|
|
|
|
from t2 import *
|
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
* Fix some docstrings and one Print -> print.
* Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}.
These were the ones that generated code with a print statement.
In most remaining failing tests there's an issue with the soft space.
2007-02-10 05:28:07 +08:00
|
|
|
print(dir())
|
1997-09-07 02:42:57 +08:00
|
|
|
from t2 import sub
|
|
|
|
from t2.sub import subsub
|
|
|
|
from t2.sub.subsub import spam
|
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
* Fix some docstrings and one Print -> print.
* Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}.
These were the ones that generated code with a print statement.
In most remaining failing tests there's an issue with the soft space.
2007-02-10 05:28:07 +08:00
|
|
|
print(sub.__name__, subsub.__name__)
|
|
|
|
print(sub.subsub.__name__)
|
|
|
|
print(dir())
|
1997-09-07 02:42:57 +08:00
|
|
|
import t2.sub
|
|
|
|
import t2.sub.subsub
|
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
* Fix some docstrings and one Print -> print.
* Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}.
These were the ones that generated code with a print statement.
In most remaining failing tests there's an issue with the soft space.
2007-02-10 05:28:07 +08:00
|
|
|
print(t2.__name__, t2.sub.__name__, t2.sub.subsub.__name__)
|
1997-09-07 02:42:57 +08:00
|
|
|
from t2 import *
|
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
* Fix some docstrings and one Print -> print.
* Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}.
These were the ones that generated code with a print statement.
In most remaining failing tests there's an issue with the soft space.
2007-02-10 05:28:07 +08:00
|
|
|
print(dir())
|
1997-09-07 02:42:57 +08:00
|
|
|
"""),
|
2000-10-24 01:22:08 +08:00
|
|
|
|
1997-09-07 02:42:57 +08:00
|
|
|
("t3", [
|
|
|
|
("t3", None),
|
2007-08-16 22:35:24 +08:00
|
|
|
("t3 __init__.py", "print(__name__, 'loading')"),
|
1997-09-07 02:42:57 +08:00
|
|
|
("t3 sub", None),
|
2007-08-16 22:35:24 +08:00
|
|
|
("t3 sub __init__.py", ""),
|
1997-09-07 02:42:57 +08:00
|
|
|
("t3 sub subsub", None),
|
2007-08-16 22:35:24 +08:00
|
|
|
("t3 sub subsub __init__.py", "print(__name__, 'loading'); spam = 1"),
|
1997-09-07 02:42:57 +08:00
|
|
|
],
|
|
|
|
"""
|
|
|
|
import t3.sub.subsub
|
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
* Fix some docstrings and one Print -> print.
* Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}.
These were the ones that generated code with a print statement.
In most remaining failing tests there's an issue with the soft space.
2007-02-10 05:28:07 +08:00
|
|
|
print(t3.__name__, t3.sub.__name__, t3.sub.subsub.__name__)
|
1997-09-07 02:42:57 +08:00
|
|
|
"""),
|
2000-10-24 01:22:08 +08:00
|
|
|
|
1997-09-07 02:42:57 +08:00
|
|
|
("t4", [
|
2007-08-16 22:35:24 +08:00
|
|
|
("t4.py", "print('THIS SHOULD NOT BE PRINTED (t4.py)')"),
|
1997-09-07 02:42:57 +08:00
|
|
|
("t4", None),
|
2007-08-16 22:35:24 +08:00
|
|
|
("t4 __init__.py", "print(__name__, 'loading')"),
|
|
|
|
("t4 sub.py", "print('THIS SHOULD NOT BE PRINTED (sub.py)')"),
|
1997-09-07 02:42:57 +08:00
|
|
|
("t4 sub", None),
|
2007-08-16 22:35:24 +08:00
|
|
|
("t4 sub __init__.py", ""),
|
|
|
|
("t4 sub subsub.py", "print('THIS SHOULD NOT BE PRINTED (subsub.py)')"),
|
1997-09-07 02:42:57 +08:00
|
|
|
("t4 sub subsub", None),
|
2007-08-16 22:35:24 +08:00
|
|
|
("t4 sub subsub __init__.py", "print(__name__, 'loading'); spam = 1"),
|
1997-09-07 02:42:57 +08:00
|
|
|
],
|
|
|
|
"""
|
|
|
|
from t4.sub.subsub import *
|
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
* Fix some docstrings and one Print -> print.
* Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}.
These were the ones that generated code with a print statement.
In most remaining failing tests there's an issue with the soft space.
2007-02-10 05:28:07 +08:00
|
|
|
print("t4.sub.subsub.spam =", spam)
|
1997-09-07 02:42:57 +08:00
|
|
|
"""),
|
|
|
|
|
|
|
|
("t5", [
|
|
|
|
("t5", None),
|
2007-08-16 22:35:24 +08:00
|
|
|
("t5 __init__.py", "import t5.foo"),
|
|
|
|
("t5 string.py", "print(__name__, 'loading'); spam = 1"),
|
|
|
|
("t5 foo.py",
|
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
* Fix some docstrings and one Print -> print.
* Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}.
These were the ones that generated code with a print statement.
In most remaining failing tests there's an issue with the soft space.
2007-02-10 05:28:07 +08:00
|
|
|
"print(__name__, 'loading'); from . import string; print(string.spam)"),
|
1997-09-07 02:42:57 +08:00
|
|
|
],
|
|
|
|
"""
|
1997-09-07 14:12:11 +08:00
|
|
|
import t5
|
1997-09-07 02:42:57 +08:00
|
|
|
from t5 import *
|
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
* Fix some docstrings and one Print -> print.
* Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}.
These were the ones that generated code with a print statement.
In most remaining failing tests there's an issue with the soft space.
2007-02-10 05:28:07 +08:00
|
|
|
print(dir())
|
1997-09-07 02:42:57 +08:00
|
|
|
import t5
|
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
* Fix some docstrings and one Print -> print.
* Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}.
These were the ones that generated code with a print statement.
In most remaining failing tests there's an issue with the soft space.
2007-02-10 05:28:07 +08:00
|
|
|
print(fixdir(dir(t5)))
|
|
|
|
print(fixdir(dir(t5.foo)))
|
|
|
|
print(fixdir(dir(t5.string)))
|
1997-09-09 00:06:20 +08:00
|
|
|
"""),
|
|
|
|
|
|
|
|
("t6", [
|
|
|
|
("t6", None),
|
2007-08-16 22:35:24 +08:00
|
|
|
("t6 __init__.py", "__all__ = ['spam', 'ham', 'eggs']"),
|
|
|
|
("t6 spam.py", "print(__name__, 'loading')"),
|
|
|
|
("t6 ham.py", "print(__name__, 'loading')"),
|
|
|
|
("t6 eggs.py", "print(__name__, 'loading')"),
|
1997-09-09 00:06:20 +08:00
|
|
|
],
|
|
|
|
"""
|
|
|
|
import t6
|
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
* Fix some docstrings and one Print -> print.
* Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}.
These were the ones that generated code with a print statement.
In most remaining failing tests there's an issue with the soft space.
2007-02-10 05:28:07 +08:00
|
|
|
print(fixdir(dir(t6)))
|
1997-09-09 00:06:20 +08:00
|
|
|
from t6 import *
|
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
* Fix some docstrings and one Print -> print.
* Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}.
These were the ones that generated code with a print statement.
In most remaining failing tests there's an issue with the soft space.
2007-02-10 05:28:07 +08:00
|
|
|
print(fixdir(dir(t6)))
|
|
|
|
print(dir())
|
2000-08-18 06:55:00 +08:00
|
|
|
"""),
|
2000-10-24 01:22:08 +08:00
|
|
|
|
2000-08-18 06:55:00 +08:00
|
|
|
("t7", [
|
2007-08-16 22:35:24 +08:00
|
|
|
("t7.py", "print('Importing t7.py')"),
|
2000-08-18 06:55:00 +08:00
|
|
|
("t7", None),
|
2007-08-16 22:35:24 +08:00
|
|
|
("t7 __init__.py", "print(__name__, 'loading')"),
|
|
|
|
("t7 sub.py", "print('THIS SHOULD NOT BE PRINTED (sub.py)')"),
|
2000-08-18 06:55:00 +08:00
|
|
|
("t7 sub", None),
|
2007-08-16 22:35:24 +08:00
|
|
|
("t7 sub __init__.py", ""),
|
|
|
|
("t7 sub subsub.py", "print('THIS SHOULD NOT BE PRINTED (subsub.py)')"),
|
2000-08-18 06:55:00 +08:00
|
|
|
("t7 sub subsub", None),
|
2007-08-16 22:35:24 +08:00
|
|
|
("t7 sub subsub __init__.py", "print(__name__, 'loading'); spam = 1"),
|
2000-08-18 06:55:00 +08:00
|
|
|
],
|
|
|
|
"""
|
|
|
|
t7, sub, subsub = None, None, None
|
|
|
|
import t7 as tas
|
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
* Fix some docstrings and one Print -> print.
* Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}.
These were the ones that generated code with a print statement.
In most remaining failing tests there's an issue with the soft space.
2007-02-10 05:28:07 +08:00
|
|
|
print(fixdir(dir(tas)))
|
2001-01-18 03:11:13 +08:00
|
|
|
verify(not t7)
|
2000-08-18 06:55:00 +08:00
|
|
|
from t7 import sub as subpar
|
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
* Fix some docstrings and one Print -> print.
* Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}.
These were the ones that generated code with a print statement.
In most remaining failing tests there's an issue with the soft space.
2007-02-10 05:28:07 +08:00
|
|
|
print(fixdir(dir(subpar)))
|
2001-01-18 03:11:13 +08:00
|
|
|
verify(not t7 and not sub)
|
2000-08-18 06:55:00 +08:00
|
|
|
from t7.sub import subsub as subsubsub
|
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
* Fix some docstrings and one Print -> print.
* Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}.
These were the ones that generated code with a print statement.
In most remaining failing tests there's an issue with the soft space.
2007-02-10 05:28:07 +08:00
|
|
|
print(fixdir(dir(subsubsub)))
|
2001-01-18 03:11:13 +08:00
|
|
|
verify(not t7 and not sub and not subsub)
|
2000-08-18 06:55:00 +08:00
|
|
|
from t7.sub.subsub import spam as ham
|
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
* Fix some docstrings and one Print -> print.
* Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}.
These were the ones that generated code with a print statement.
In most remaining failing tests there's an issue with the soft space.
2007-02-10 05:28:07 +08:00
|
|
|
print("t7.sub.subsub.spam =", ham)
|
2001-01-18 03:11:13 +08:00
|
|
|
verify(not t7 and not sub and not subsub)
|
1997-09-07 02:42:57 +08:00
|
|
|
"""),
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
nontests = [
|
|
|
|
("x5", [], ("import a" + ".a"*400)),
|
|
|
|
("x6", [], ("import a" + ".a"*499)),
|
|
|
|
("x7", [], ("import a" + ".a"*500)),
|
|
|
|
("x8", [], ("import a" + ".a"*1100)),
|
|
|
|
("x9", [], ("import " + "a"*400)),
|
|
|
|
("x10", [], ("import " + "a"*500)),
|
|
|
|
("x11", [], ("import " + "a"*998)),
|
|
|
|
("x12", [], ("import " + "a"*999)),
|
|
|
|
("x13", [], ("import " + "a"*999)),
|
|
|
|
("x14", [], ("import " + "a"*2000)),
|
|
|
|
]
|
|
|
|
|
|
|
|
"""XXX Things to test
|
|
|
|
|
|
|
|
import package without __init__
|
|
|
|
import package with __init__
|
|
|
|
__init__ importing submodule
|
|
|
|
__init__ importing global module
|
|
|
|
__init__ defining variables
|
|
|
|
submodule importing other submodule
|
|
|
|
submodule importing global module
|
|
|
|
submodule import submodule via global name
|
|
|
|
from package import submodule
|
|
|
|
from package import subpackage
|
|
|
|
from package import variable (defined in __init__)
|
|
|
|
from package import * (defined in __init__)
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Run the tests
|
|
|
|
|
1997-09-07 14:12:11 +08:00
|
|
|
args = []
|
|
|
|
if __name__ == '__main__':
|
|
|
|
args = sys.argv[1:]
|
|
|
|
if args and args[0] == '-q':
|
1998-03-27 03:42:58 +08:00
|
|
|
verbose = 0
|
|
|
|
del args[0]
|
1997-09-07 14:12:11 +08:00
|
|
|
|
1997-09-07 02:42:57 +08:00
|
|
|
for name, hier, code in tests:
|
1997-09-07 14:12:11 +08:00
|
|
|
if args and name not in args:
|
2007-02-09 13:37:30 +08:00
|
|
|
print("skipping test", name)
|
1998-03-27 03:42:58 +08:00
|
|
|
continue
|
2007-02-09 13:37:30 +08:00
|
|
|
print("running test", name)
|
1997-09-07 02:42:57 +08:00
|
|
|
runtest(hier, code)
|
1998-05-19 23:09:42 +08:00
|
|
|
|
|
|
|
# Test
|
|
|
|
import sys
|
|
|
|
import imp
|
|
|
|
try:
|
|
|
|
import sys.imp
|
|
|
|
except ImportError:
|
|
|
|
# This is what we expect
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
raise TestFailed, "No ImportError exception on 'import sys.imp'"
|