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