Move over to using assertRaises as a context manager for importlib tests.

Obviously one shouldn't do whole sale conversions like this, but I was already
going through the test code and I was bored at the airport.
This commit is contained in:
Brett Cannon 2009-08-27 23:49:21 +00:00
parent c5951fc996
commit 2153dc001f
9 changed files with 36 additions and 24 deletions

View file

@ -93,7 +93,8 @@ class SimpleTest(unittest.TestCase):
file.write('+++ bad syntax +++')
loader = _bootstrap._PyPycFileLoader('_temp', mapping['_temp'],
False)
self.assertRaises(SyntaxError, loader.load_module, name)
with self.assertRaises(SyntaxError):
loader.load_module(name)
for attr in attributes:
self.assertEqual(getattr(orig_module, attr), value)
@ -104,7 +105,8 @@ class SimpleTest(unittest.TestCase):
file.write('=')
loader = _bootstrap._PyPycFileLoader('_temp', mapping['_temp'],
False)
self.assertRaises(SyntaxError, loader.load_module, '_temp')
with self.assertRaises(SyntaxError):
loader.load_module('_temp')
self.assertTrue('_temp' not in sys.modules)
@ -166,8 +168,8 @@ class BadBytecodeTest(unittest.TestCase):
bytecode_file.write(imp.get_magic())
bytecode_file.write(source_timestamp)
bytecode_file.write(b'AAAA')
self.assertRaises(ValueError, self.import_, mapping['_temp'],
'_temp')
with self.assertRaises(ValueError):
self.import_(mapping['_temp'], '_temp')
self.assertTrue('_temp' not in sys.modules)