diff options
author | Brett Cannon <bcannon@gmail.com> | 2009-08-27 23:49:21 (GMT) |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2009-08-27 23:49:21 (GMT) |
commit | 2153dc001f5565592b44808d7f0f25815010eb9d (patch) | |
tree | 8801111b4467bd21f5f936d3fd6196d41f77688f /Lib/importlib/test/source | |
parent | c5951fc996ad74a05e83a61cf0345a4a68c01b12 (diff) | |
download | cpython-2153dc001f5565592b44808d7f0f25815010eb9d.zip cpython-2153dc001f5565592b44808d7f0f25815010eb9d.tar.gz cpython-2153dc001f5565592b44808d7f0f25815010eb9d.tar.bz2 |
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.
Diffstat (limited to 'Lib/importlib/test/source')
-rw-r--r-- | Lib/importlib/test/source/test_file_loader.py | 10 | ||||
-rw-r--r-- | Lib/importlib/test/source/test_finder.py | 8 | ||||
-rw-r--r-- | Lib/importlib/test/source/test_source_encoding.py | 3 |
3 files changed, 12 insertions, 9 deletions
diff --git a/Lib/importlib/test/source/test_file_loader.py b/Lib/importlib/test/source/test_file_loader.py index 0384e7d..b18750c 100644 --- a/Lib/importlib/test/source/test_file_loader.py +++ b/Lib/importlib/test/source/test_file_loader.py @@ -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) diff --git a/Lib/importlib/test/source/test_finder.py b/Lib/importlib/test/source/test_finder.py index c495c5a..8f15f62 100644 --- a/Lib/importlib/test/source/test_finder.py +++ b/Lib/importlib/test/source/test_finder.py @@ -97,8 +97,8 @@ class FinderTests(abc.FinderTests): with context as mapping: os.unlink(mapping['pkg.sub.__init__']) pkg_dir = os.path.dirname(mapping['pkg.__init__']) - self.assertRaises(ImportWarning, self.import_, pkg_dir, - 'pkg.sub') + with self.assertRaises(ImportWarning): + self.import_(pkg_dir, 'pkg.sub') # [package over modules] def test_package_over_module(self): @@ -117,8 +117,8 @@ class FinderTests(abc.FinderTests): def test_empty_dir(self): with warnings.catch_warnings(): warnings.simplefilter("error", ImportWarning) - self.assertRaises(ImportWarning, self.run_test, 'pkg', - {'pkg.__init__'}, unlink={'pkg.__init__'}) + with self.assertRaises(ImportWarning): + self.run_test('pkg', {'pkg.__init__'}, unlink={'pkg.__init__'}) def test_main(): diff --git a/Lib/importlib/test/source/test_source_encoding.py b/Lib/importlib/test/source/test_source_encoding.py index 3734712..fde355f 100644 --- a/Lib/importlib/test/source/test_source_encoding.py +++ b/Lib/importlib/test/source/test_source_encoding.py @@ -81,7 +81,8 @@ class EncodingTest(unittest.TestCase): # [BOM conflict] def test_bom_conflict(self): source = codecs.BOM_UTF8 + self.create_source('latin-1') - self.assertRaises(SyntaxError, self.run_test, source) + with self.assertRaises(SyntaxError): + self.run_test(source) class LineEndingTest(unittest.TestCase): |