1 from test_support
import TESTFN
, TestFailed
7 # Brief digression to test that import is case-sensitive: if we got this
8 # far, we know for sure that "random" exists.
14 raise TestFailed("import of RAnDoM should have failed (case mismatch)")
16 # Another brief digression to test the accuracy of manifest float constants.
17 import double_const
# don't blink -- that *was* the test
19 def test_with_extension(ext
): # ext normally ".py"; perhaps ".pyw"
21 pyo
= TESTFN
+ os
.extsep
+ "pyo"
22 if sys
.platform
.startswith('java'):
23 pyc
= TESTFN
+ "$py.class"
25 pyc
= TESTFN
+ os
.extsep
+ "pyc"
28 print >> f
, "# This tests Python's ability to import a", ext
, "file."
29 a
= random
.randrange(1000)
30 b
= random
.randrange(1000)
37 mod
= __import__(TESTFN
)
38 except ImportError, err
:
39 raise ValueError("import from %s failed: %s" % (ext
, err
))
41 if mod
.a
!= a
or mod
.b
!= b
:
44 raise ValueError("module loaded (%s) but contents invalid" % mod
)
51 except ImportError, err
:
52 raise ValueError("import from .pyc/.pyo failed: %s" % err
)
62 del sys
.modules
[TESTFN
]
64 sys
.path
.insert(0, os
.curdir
)
66 test_with_extension(os
.extsep
+ "py")
67 if sys
.platform
.startswith("win"):
68 for ext
in ".PY", ".Py", ".pY", ".pyw", ".PYW", ".pYw":
69 test_with_extension(ext
)