Use assertRaises and add a specific warning filter.

This commit is contained in:
Florent Xicluna 2010-03-21 11:58:11 +00:00
parent aa89f8d04c
commit b88fbf4fef
1 changed files with 4 additions and 9 deletions

View File

@ -227,15 +227,9 @@ class ImportHooksTestCase(ImportHooksBaseTestCase):
def testBlocker(self): def testBlocker(self):
mname = "exceptions" # an arbitrary harmless builtin module mname = "exceptions" # an arbitrary harmless builtin module
if mname in sys.modules: test_support.unload(mname)
del sys.modules[mname]
sys.meta_path.append(ImportBlocker(mname)) sys.meta_path.append(ImportBlocker(mname))
try: self.assertRaises(ImportError, __import__, mname)
__import__(mname)
except ImportError:
pass
else:
self.fail("'%s' was not supposed to be importable" % mname)
def testImpWrapper(self): def testImpWrapper(self):
i = ImpWrapper() i = ImpWrapper()
@ -247,7 +241,8 @@ class ImportHooksTestCase(ImportHooksBaseTestCase):
for n in sys.modules.keys(): for n in sys.modules.keys():
if n.startswith(parent): if n.startswith(parent):
del sys.modules[n] del sys.modules[n]
with test_support.check_warnings(): with test_support.check_warnings(("The compiler package is deprecated "
"and removed", DeprecationWarning)):
for mname in mnames: for mname in mnames:
m = __import__(mname, globals(), locals(), ["__dummy__"]) m = __import__(mname, globals(), locals(), ["__dummy__"])
m.__loader__ # to make sure we actually handled the import m.__loader__ # to make sure we actually handled the import