diff options
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_codeop.py | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/Lib/test/test_codeop.py b/Lib/test/test_codeop.py index d845e20..ad44121 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) |