diff options
author | Florent Xicluna <florent.xicluna@gmail.com> | 2010-03-17 19:05:04 +0000 |
---|---|---|
committer | Florent Xicluna <florent.xicluna@gmail.com> | 2010-03-17 19:05:04 +0000 |
commit | e777e858a0f5247e86a6255b3d9c2fa0dc765d3f (patch) | |
tree | 3d4d7c15b43b1f61ad5601bec9d63207ceb8c0e2 /Lib/test/test_coding.py | |
parent | d978a157eb2a1124937486d102a28b6a324562a5 (diff) | |
download | cpython-e777e858a0f5247e86a6255b3d9c2fa0dc765d3f.tar.gz |
Cleanup in test_import and test_coding.
Diffstat (limited to 'Lib/test/test_coding.py')
-rw-r--r-- | Lib/test/test_coding.py | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/Lib/test/test_coding.py b/Lib/test/test_coding.py index 7ac3af04d8..7f5ddb1934 100644 --- a/Lib/test/test_coding.py +++ b/Lib/test/test_coding.py @@ -16,22 +16,19 @@ class CodingTest(unittest.TestCase): path = os.path.dirname(__file__) filename = os.path.join(path, module_name + '.py') - fp = open(filename) - text = fp.read() - fp.close() + with open(filename) as fp: + text = fp.read() self.assertRaises(SyntaxError, compile, text, filename, 'exec') def test_error_from_string(self): # See http://bugs.python.org/issue6289 input = u"# coding: ascii\n\N{SNOWMAN}".encode('utf-8') - try: + with self.assertRaises(SyntaxError) as c: compile(input, "<string>", "exec") - except SyntaxError as e: - expected = "'ascii' codec can't decode byte 0xe2 in position 16: " \ - "ordinal not in range(128)" - self.assertTrue(str(e).startswith(expected)) - else: - self.fail("didn't raise") + expected = "'ascii' codec can't decode byte 0xe2 in position 16: " \ + "ordinal not in range(128)" + self.assertTrue(c.exception.args[0].startswith(expected)) + def test_main(): test.test_support.run_unittest(CodingTest) |