From 6c0f337904c1a6414fbaee84f7923cc0877e47eb Mon Sep 17 00:00:00 2001 From: Frank Wierzbicki Date: Sun, 2 Aug 2009 20:37:48 +0000 Subject: Adding tests derived from the Jython project. These are primarily tests of 'single' statements with partial sentences (so they test things like "try:" in interactive mode). Others tests hit areas that previously failed in Jython. A couple still fail in Jython, mainly due to the difficulty of parsing partial sentences (but should be fixed by Jython 2.6). --- Lib/test/test_codeop.py | 116 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/Lib/test/test_codeop.py b/Lib/test/test_codeop.py index 6900408..c8fa990 100644 --- a/Lib/test/test_codeop.py +++ b/Lib/test/test_codeop.py @@ -108,6 +108,20 @@ class CodeopTests(unittest.TestCase): av("\n \na**3","eval") av("#a\n#b\na**3","eval") + av("\n\na = 1\n\n") + av("\n\nif 1: a=1\n\n") + + av("if 1:\n pass\n if 1:\n pass\n else:\n pass\n") + av("#a\n\n \na=3\n\n") + + av("\n\na**3","eval") + av("\n \na**3","eval") + av("#a\n#b\na**3","eval") + + av("def f():\n try: pass\n finally: [x for x in (1,2)]\n") + av("def f():\n pass\n#foo\n") + av("@a.b.c\ndef f():\n pass\n") + def test_incomplete(self): ai = self.assertIncomplete @@ -149,6 +163,93 @@ class CodeopTests(unittest.TestCase): ai("9+ \\","eval") ai("lambda z: \\","eval") + ai("if True:\n if True:\n if True: \n") + + ai("@a(") + ai("@a(b") + ai("@a(b,") + ai("@a(b,c") + ai("@a(b,c,") + + ai("from a import (") + ai("from a import (b") + ai("from a import (b,") + ai("from a import (b,c") + ai("from a import (b,c,") + + ai("["); + ai("[a"); + ai("[a,"); + ai("[a,b"); + ai("[a,b,"); + + ai("{"); + ai("{a"); + ai("{a:"); + ai("{a:b"); + ai("{a:b,"); + ai("{a:b,c"); + ai("{a:b,c:"); + ai("{a:b,c:d"); + ai("{a:b,c:d,"); + + ai("a(") + ai("a(b") + ai("a(b,") + ai("a(b,c") + ai("a(b,c,") + + ai("a[") + ai("a[b") + ai("a[b,") + ai("a[b:") + ai("a[b:c") + ai("a[b:c:") + ai("a[b:c:d") + + ai("def a(") + ai("def a(b") + ai("def a(b,") + ai("def a(b,c") + ai("def a(b,c,") + + ai("(") + ai("(a") + ai("(a,") + ai("(a,b") + ai("(a,b,") + + ai("if a:\n pass\nelif b:") + ai("if a:\n pass\nelif b:\n pass\nelse:") + + ai("while a:") + ai("while a:\n pass\nelse:") + + ai("for a in b:") + ai("for a in b:\n pass\nelse:") + + ai("try:") + ai("try:\n pass\nexcept:") + ai("try:\n pass\nfinally:") + ai("try:\n pass\nexcept:\n pass\nfinally:") + + ai("with a:") + ai("with a as b:") + + ai("class a:") + ai("class a(") + ai("class a(b") + ai("class a(b,") + ai("class a():") + + ai("[x for") + ai("[x for x in") + ai("[x for x in (") + + ai("(x for") + ai("(x for x in") + ai("(x for x in (") + def test_invalid(self): ai = self.assertInvalid ai("a b") @@ -177,12 +278,27 @@ class CodeopTests(unittest.TestCase): ai("lambda z:","eval") ai("a b","eval") + ai("return 2.3") + ai("if (a == 1 and b = 2): pass") + + ai("del 1") + ai("del ()") + ai("del (1,)") + ai("del [1]") + ai("del '1'") + + ai("[i for i in range(10)] = (1, 2, 3)") + def test_filename(self): self.assertEquals(compile_command("a = 1\n", "abc").co_filename, compile("a = 1\n", "abc", 'single').co_filename) self.assertNotEquals(compile_command("a = 1\n", "abc").co_filename, compile("a = 1\n", "def", 'single').co_filename) + def test_no_universal_newlines(self): + code = compile_command("'\rfoo\r'", symbol='eval') + self.assertEqual(eval(code), '\rfoo\r') + def test_main(): run_unittest(CodeopTests) -- cgit v0.12