diff options
author | Frank Wierzbicki <fwierzbicki@gmail.com> | 2009-08-02 22:19:05 (GMT) |
---|---|---|
committer | Frank Wierzbicki <fwierzbicki@gmail.com> | 2009-08-02 22:19:05 (GMT) |
commit | 0d0367f76fc9c99b92bb75c4125fd35ee493828a (patch) | |
tree | cf6c71e5cc2dc5fd1406e9aff2be6ec5724e6c9e /Lib/test/test_codeop.py | |
parent | 45f799fe6e51f3217e0a56b39cfc61aba5aa0d11 (diff) | |
download | cpython-0d0367f76fc9c99b92bb75c4125fd35ee493828a.zip cpython-0d0367f76fc9c99b92bb75c4125fd35ee493828a.tar.gz cpython-0d0367f76fc9c99b92bb75c4125fd35ee493828a.tar.bz2 |
Merged revisions 74291 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74291 | frank.wierzbicki | 2009-08-02 16:37:48 -0400 (Sun, 02 Aug 2009) | 6 lines
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).
........
Diffstat (limited to 'Lib/test/test_codeop.py')
-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) |