home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 1.5)
-
- import sys
- import os
- import string
- import tempfile
- import traceback
- rmdir
- del mkdir
- del rmdir
- TestFailed
-
- def mkhier(root, descr):
- mkdir(root)
- for name, contents in descr:
- comps = string.split(name)
- fullname = root
- for c in comps:
- fullname = os.path.join(fullname, c)
-
- if contents is None:
- mkdir(fullname)
- elif verbose:
- print 'write', fullname
-
- f = open(fullname, 'w')
- f.write(contents)
- if contents and contents[-1] != '\n':
- f.write('\n')
-
- f.close()
-
-
-
- def mkdir(x):
- if verbose:
- print 'mkdir', x
-
- os.mkdir(x)
-
-
- def cleanout(root):
- names = os.listdir(root)
- for name in names:
- fullname = os.path.join(root, name)
-
- rmdir(root)
-
-
- def rmdir(x):
- if verbose:
- print 'rmdir', x
-
- os.rmdir(x)
-
-
- def runtest(hier, code):
- root = tempfile.mktemp()
- mkhier(root, hier)
- savepath = sys.path[:]
- codefile = tempfile.mktemp()
- f = open(codefile, 'w')
- f.write(code)
- f.close()
-
- try:
- sys.path.insert(0, root)
- if verbose:
- print 'sys.path =', sys.path
-
-
- try:
- execfile(codefile, globals(), { })
- except:
- traceback.print_exc(file = sys.stdout)
-
- finally:
- sys.path[:] = savepath
-
- try:
- cleanout(root)
- except (os.error, IOError):
- pass
-
- os.remove(codefile)
-
-
- tests = [
- ('t1', [
- ('t1', None),
- ('t1 __init__.py', '')], 'import t1'),
- ('t2', [
- ('t2', None),
- ('t2 __init__.py', "'doc for t2'; print __name__, 'loading'"),
- ('t2 sub', None),
- ('t2 sub __init__.py', ''),
- ('t2 sub subsub', None),
- ('t2 sub subsub __init__.py', "print __name__, 'loading'; spam = 1")], '\nimport t2\nprint t2.__doc__\nimport t2.sub\nimport t2.sub.subsub\nprint t2.__name__, t2.sub.__name__, t2.sub.subsub.__name__\nimport t2\nfrom t2 import *\nprint dir()\nfrom t2 import sub\nfrom t2.sub import subsub\nfrom t2.sub.subsub import spam\nprint sub.__name__, subsub.__name__\nprint sub.subsub.__name__\nprint dir()\nimport t2.sub\nimport t2.sub.subsub\nprint t2.__name__, t2.sub.__name__, t2.sub.subsub.__name__\nfrom t2 import *\nprint dir()\n'),
- ('t3', [
- ('t3', None),
- ('t3 __init__.py', "print __name__, 'loading'"),
- ('t3 sub', None),
- ('t3 sub __init__.py', ''),
- ('t3 sub subsub', None),
- ('t3 sub subsub __init__.py', "print __name__, 'loading'; spam = 1")], '\nimport t3.sub.subsub\nprint t3.__name__, t3.sub.__name__, t3.sub.subsub.__name__\nreload(t3)\nreload(t3.sub)\nreload(t3.sub.subsub)\n'),
- ('t4', [
- ('t4.py', "print 'THIS SHOULD NOT BE PRINTED (t4.py)'"),
- ('t4', None),
- ('t4 __init__.py', "print __name__, 'loading'"),
- ('t4 sub.py', "print 'THIS SHOULD NOT BE PRINTED (sub.py)'"),
- ('t4 sub', None),
- ('t4 sub __init__.py', ''),
- ('t4 sub subsub.py', "print 'THIS SHOULD NOT BE PRINTED (subsub.py)'"),
- ('t4 sub subsub', None),
- ('t4 sub subsub __init__.py', "print __name__, 'loading'; spam = 1")], '\nfrom t4.sub.subsub import *\nprint "t4.sub.subsub.spam =", spam\n'),
- ('t5', [
- ('t5', None),
- ('t5 __init__.py', 'import t5.foo'),
- ('t5 string.py', "print __name__, 'loading'; spam = 1"),
- ('t5 foo.py', "print __name__, 'loading'; import string; print string.spam")], '\nimport t5\nfrom t5 import *\nprint dir()\nimport t5\nprint dir(t5)\nprint dir(t5.foo)\nprint dir(t5.string)\n'),
- ('t6', [
- ('t6', None),
- ('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'")], '\nimport t6\nprint dir(t6)\nfrom t6 import *\nprint dir(t6)\nprint dir()\n')]
- 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)]
- args = []
- for name, hier, code in tests:
- print 'running test', name
- runtest(hier, code)
-
- import sys
- import imp
-
- try:
- import sys.imp as sys
- except ImportError:
- pass
-
- raise TestFailed, "No ImportError exception on 'import sys.imp'"
-