summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_import.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_import.py')
-rw-r--r--Lib/test/test_import.py23
1 files changed, 11 insertions, 12 deletions
diff --git a/Lib/test/test_import.py b/Lib/test/test_import.py
index 05eecdb..c3fa2f0 100644
--- a/Lib/test/test_import.py
+++ b/Lib/test/test_import.py
@@ -7,6 +7,7 @@ import sys
import py_compile
import warnings
import marshal
+import imp
from test.test_support import (unlink, TESTFN, unload, run_unittest,
check_warnings, TestFailed, EnvironmentVarGuard)
@@ -56,11 +57,10 @@ class ImportTest(unittest.TestCase):
f.close()
try:
- try:
- mod = __import__(TESTFN)
- except ImportError, err:
- self.fail("import from %s failed: %s" % (ext, err))
-
+ mod = __import__(TESTFN)
+ except ImportError, err:
+ self.fail("import from %s failed: %s" % (ext, err))
+ else:
self.assertEquals(mod.a, a,
"module loaded (%s) but contents invalid" % mod)
self.assertEquals(mod.b, b,
@@ -69,10 +69,9 @@ class ImportTest(unittest.TestCase):
os.unlink(source)
try:
- try:
- reload(mod)
- except ImportError, err:
- self.fail("import from .pyc/.pyo failed: %s" % err)
+ imp.reload(mod)
+ except ImportError, err:
+ self.fail("import from .pyc/.pyo failed: %s" % err)
finally:
try:
os.unlink(pyc)
@@ -121,7 +120,7 @@ class ImportTest(unittest.TestCase):
def testImpModule(self):
# Verify that the imp module can correctly load and find .py files
- import imp, os
+
# XXX (ncoghlan): It would be nice to use test_support.CleanImport
# here, but that breaks because the os module registers some
# handlers in copy_reg on import. Since CleanImport doesn't
@@ -172,7 +171,7 @@ class ImportTest(unittest.TestCase):
def test_failing_import_sticks(self):
source = TESTFN + os.extsep + "py"
f = open(source, "w")
- print >> f, "a = 1/0"
+ print >> f, "a = 1 // 0"
f.close()
# New in 2.4, we shouldn't be able to import that no matter how often
@@ -218,7 +217,7 @@ class ImportTest(unittest.TestCase):
print >> f, "b = 20//0"
f.close()
- self.assertRaises(ZeroDivisionError, reload, mod)
+ self.assertRaises(ZeroDivisionError, imp.reload, mod)
# But we still expect the module to be in sys.modules.
mod = sys.modules.get(TESTFN)