Silence a py3k warning claiming to affect Lib/calendar.py
[python.git] / Lib / test / test_coding.py
blob7ac3af04d831b55cf5ed9a62f915315194134e95
2 import test.test_support, unittest
3 import os
5 class CodingTest(unittest.TestCase):
6 def test_bad_coding(self):
7 module_name = 'bad_coding'
8 self.verify_bad_module(module_name)
10 def test_bad_coding2(self):
11 module_name = 'bad_coding2'
12 self.verify_bad_module(module_name)
14 def verify_bad_module(self, module_name):
15 self.assertRaises(SyntaxError, __import__, 'test.' + module_name)
17 path = os.path.dirname(__file__)
18 filename = os.path.join(path, module_name + '.py')
19 fp = open(filename)
20 text = fp.read()
21 fp.close()
22 self.assertRaises(SyntaxError, compile, text, filename, 'exec')
24 def test_error_from_string(self):
25 # See http://bugs.python.org/issue6289
26 input = u"# coding: ascii\n\N{SNOWMAN}".encode('utf-8')
27 try:
28 compile(input, "<string>", "exec")
29 except SyntaxError as e:
30 expected = "'ascii' codec can't decode byte 0xe2 in position 16: " \
31 "ordinal not in range(128)"
32 self.assertTrue(str(e).startswith(expected))
33 else:
34 self.fail("didn't raise")
36 def test_main():
37 test.test_support.run_unittest(CodingTest)
39 if __name__ == "__main__":
40 test_main()