summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorFrank Wierzbicki <fwierzbicki@gmail.com>2009-08-02 20:37:48 (GMT)
committerFrank Wierzbicki <fwierzbicki@gmail.com>2009-08-02 20:37:48 (GMT)
commit6c0f337904c1a6414fbaee84f7923cc0877e47eb (patch)
tree06b551434e249342433bab56af0ae1b1c1c74722 /Lib
parent9a6d6c93b45b32c21db5bce25495fec756f6c53d (diff)
downloadcpython-6c0f337904c1a6414fbaee84f7923cc0877e47eb.zip
cpython-6c0f337904c1a6414fbaee84f7923cc0877e47eb.tar.gz
cpython-6c0f337904c1a6414fbaee84f7923cc0877e47eb.tar.bz2
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')
-rw-r--r--Lib/test/test_codeop.py116
1 files changed, 116 insertions, 0 deletions
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)