1 from test
.test_support
import TESTFN
, TestFailed
8 # Brief digression to test that import is case-sensitive: if we got this
9 # far, we know for sure that "random" exists.
15 raise TestFailed("import of RAnDoM should have failed (case mismatch)")
17 # Another brief digression to test the accuracy of manifest float constants.
18 import double_const
# don't blink -- that *was* the test
20 def test_with_extension(ext
): # ext normally ".py"; perhaps ".pyw"
22 pyo
= TESTFN
+ os
.extsep
+ "pyo"
23 if sys
.platform
.startswith('java'):
24 pyc
= TESTFN
+ "$py.class"
26 pyc
= TESTFN
+ os
.extsep
+ "pyc"
29 print >> f
, "# This tests Python's ability to import a", ext
, "file."
30 a
= random
.randrange(1000)
31 b
= random
.randrange(1000)
38 mod
= __import__(TESTFN
)
39 except ImportError, err
:
40 raise ValueError("import from %s failed: %s" % (ext
, err
))
42 if mod
.a
!= a
or mod
.b
!= b
:
45 raise ValueError("module loaded (%s) but contents invalid" % mod
)
52 except ImportError, err
:
53 raise ValueError("import from .pyc/.pyo failed: %s" % err
)
63 del sys
.modules
[TESTFN
]
65 sys
.path
.insert(0, os
.curdir
)
67 test_with_extension(os
.extsep
+ "py")
68 if sys
.platform
.startswith("win"):
69 for ext
in ".PY", ".Py", ".pY", ".pyw", ".PYW", ".pYw":
70 test_with_extension(ext
)
74 # Verify that the imp module can correctly load and find .py files
76 x
= imp
.find_module("os")
77 os
= imp
.load_module("os", *x
)
79 def test_module_with_large_stack(module
):
80 # create module w/list of 65000 elements to test bug #561858
81 filename
= module
+ '.py'
83 # create a file with a list of 65000 elements
84 f
= open(filename
, 'w+')
86 for i
in range(65000):
91 # compile & remove .py file, we only need .pyc (or .pyo)
92 f
= open(filename
, 'r')
93 py_compile
.compile(filename
)
97 # need to be able to load from current dir
101 exec 'import ' + module
105 for ext
in '.pyc', '.pyo':
107 if os
.path
.exists(fname
):
110 test_module_with_large_stack('longlist')