Null commit with -f option to force an uprev and put HEADs firmly on the trunk.
[python/dscho.git] / Lib / test / test_import.py
blob5419b5af7f7bae0afdc41c6ba6b8d1a73e772f1f
1 from test_support import TESTFN, TestFailed
3 import os
4 import random
5 import sys
7 # Brief digression to test that import is case-sensitive: if we got this
8 # far, we know for sure that "random" exists.
9 try:
10 import RAnDoM
11 except ImportError:
12 pass
13 else:
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 sys.path.insert(0, os.curdir)
21 source = TESTFN + ".py"
22 pyc = TESTFN + ".pyc"
23 pyo = TESTFN + ".pyo"
25 f = open(source, "w")
26 print >> f, "# This will test Python's ability to import a .py file"
27 a = random.randrange(1000)
28 b = random.randrange(1000)
29 print >> f, "a =", a
30 print >> f, "b =", b
31 f.close()
33 try:
34 try:
35 mod = __import__(TESTFN)
36 except ImportError, err:
37 raise ValueError, "import from .py failed: %s" % err
39 if mod.a != a or mod.b != b:
40 print a, "!=", mod.a
41 print b, "!=", mod.b
42 raise ValueError, "module loaded (%s) but contents invalid" % mod
43 finally:
44 os.unlink(source)
46 try:
47 try:
48 reload(mod)
49 except ImportError, err:
50 raise ValueError, "import from .pyc/.pyo failed: %s" % err
51 finally:
52 try:
53 os.unlink(pyc)
54 except os.error:
55 pass
56 try:
57 os.unlink(pyo)
58 except os.error:
59 pass
61 del sys.path[0]