Benjamin Peterson | 90f5ba5 | 2010-03-11 22:53:45 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python3 |
Skip Montanaro | 8c91337 | 2002-08-15 01:28:54 +0000 | [diff] [blame] | 2 | """test script for a few new invalid token catches""" |
| 3 | |
Skip Montanaro | 8c91337 | 2002-08-15 01:28:54 +0000 | [diff] [blame] | 4 | import unittest |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 5 | from test import support |
Skip Montanaro | 8c91337 | 2002-08-15 01:28:54 +0000 | [diff] [blame] | 6 | |
| 7 | class EOFTestCase(unittest.TestCase): |
| 8 | def test_EOFC(self): |
Alexandre Vassalotti | 8ae3e05 | 2008-05-16 00:41:41 +0000 | [diff] [blame] | 9 | expect = "EOL while scanning string literal (<string>, line 1)" |
Skip Montanaro | 8c91337 | 2002-08-15 01:28:54 +0000 | [diff] [blame] | 10 | try: |
| 11 | eval("""'this is a test\ |
| 12 | """) |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 13 | except SyntaxError as msg: |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 14 | self.assertEqual(str(msg), expect) |
Skip Montanaro | 8c91337 | 2002-08-15 01:28:54 +0000 | [diff] [blame] | 15 | else: |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 16 | raise support.TestFailed |
Skip Montanaro | 8c91337 | 2002-08-15 01:28:54 +0000 | [diff] [blame] | 17 | |
| 18 | def test_EOFS(self): |
Alexandre Vassalotti | 8ae3e05 | 2008-05-16 00:41:41 +0000 | [diff] [blame] | 19 | expect = ("EOF while scanning triple-quoted string literal " |
| 20 | "(<string>, line 1)") |
Skip Montanaro | 8c91337 | 2002-08-15 01:28:54 +0000 | [diff] [blame] | 21 | try: |
| 22 | eval("""'''this is a test""") |
Guido van Rossum | b940e11 | 2007-01-10 16:19:56 +0000 | [diff] [blame] | 23 | except SyntaxError as msg: |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 24 | self.assertEqual(str(msg), expect) |
Skip Montanaro | 8c91337 | 2002-08-15 01:28:54 +0000 | [diff] [blame] | 25 | else: |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 26 | raise support.TestFailed |
Skip Montanaro | 8c91337 | 2002-08-15 01:28:54 +0000 | [diff] [blame] | 27 | |
| 28 | def test_main(): |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 29 | support.run_unittest(EOFTestCase) |
Skip Montanaro | 8c91337 | 2002-08-15 01:28:54 +0000 | [diff] [blame] | 30 | |
| 31 | if __name__ == "__main__": |
| 32 | test_main() |