[Python-checkins] CVS: python/dist/src/Lib/test test_codeop.py,NONE,1.1.2.1 test_b1.py,1.34.6.2,1.34.6.3 test_b2.py,1.24.6.1,1.24.6.2 test_import.py,1.3.4.1,1.3.4.2 test_pyexpat.py,1.7.6.1,1.7.6.2 test_scope.py,1.14.4.2,1.14.4.3
Tim Peters
tim_one@users.sourceforge.net
Wed, 01 Aug 2001 19:40:45 -0700
Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv23606/descr/dist/src/Lib/test
Modified Files:
Tag: descr-branch
test_b1.py test_b2.py test_import.py test_pyexpat.py
test_scope.py
Added Files:
Tag: descr-branch
test_codeop.py
Log Message:
Mrege of trunk tag delta date2001-07-30 to date2001-08-01.
--- NEW FILE: test_codeop.py ---
"""
Test cases for codeop.py
Nick Mathewson
"""
import unittest
from test_support import run_unittest
from codeop import compile_command
class CodeopTests(unittest.TestCase):
def assertValid(self, str, symbol='single'):
'''succeed iff str is a valid piece of code'''
expected = compile(str, "<input>", symbol)
self.assertEquals( compile_command(str, "<input>", symbol), expected)
def assertIncomplete(self, str, symbol='single'):
'''succeed iff str is the start of a valid piece of code'''
self.assertEquals( compile_command(str, symbol=symbol), None)
def assertInvalid(self, str, symbol='single', is_syntax=1):
'''succeed iff str is the start of an invalid piece of code'''
try:
compile_command(str,symbol=symbol)
self.fail("No exception thrown for invalid code")
except SyntaxError:
self.assert_(is_syntax)
except OverflowError:
self.assert_(not is_syntax)
def test_valid(self):
av = self.assertValid
av("a = 1\n")
av("def x():\n pass\n")
av("pass\n")
av("3**3\n")
av("if 9==3:\n pass\nelse:\n pass\n")
av("#a\n#b\na = 3\n")
av("#a\n\n \na=3\n")
av("a=3\n\n")
# special case
self.assertEquals(compile_command(""),
compile("pass", "<input>", 'single'))
av("3**3","eval")
av("(lambda z: \n z**3)","eval")
av("#a\n#b\na**3","eval")
def test_incomplete(self):
ai = self.assertIncomplete
ai("(a **")
ai("def x():\n")
ai("(a,b,")
ai("(a,b,(")
ai("(a,b,(")
ai("if 9==3:\n pass\nelse:\n")
ai("if 9==3:\n pass\nelse:\n pass")
ai("a = (")
ai("a = 9+ \\")
ai("(","eval")
ai("(\n\n\n","eval")
ai("(9+","eval")
ai("9+ \\","eval")
ai("lambda z: \\","eval")
def test_invalid(self):
ai = self.assertInvalid
ai("a b")
ai("a = ")
ai("a = 9 +")
ai("a = 1","eval")
ai("a = (","eval")
ai("]","eval")
ai("())","eval")
ai("[}","eval")
ai("9+","eval")
ai("lambda z:","eval")
ai("a b","eval")
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)
run_unittest(CodeopTests)
Index: test_b1.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_b1.py,v
retrieving revision 1.34.6.2
retrieving revision 1.34.6.3
diff -C2 -d -r1.34.6.2 -r1.34.6.3
*** test_b1.py 2001/07/28 05:02:59 1.34.6.2
--- test_b1.py 2001/08/02 02:40:43 1.34.6.3
***************
*** 257,264 ****
--- 257,282 ----
import sys
if getattr(sys, 'stdout') is not sys.stdout: raise TestFailed, 'getattr'
+ try:
+ getattr(sys, 1)
+ except TypeError:
+ pass
+ else:
+ raise TestFailed, "getattr(sys, 1) should raise an exception"
+ try:
+ getattr(sys, 1, "foo")
+ except TypeError:
+ pass
+ else:
+ raise TestFailed, 'getattr(sys, 1, "foo") should raise an exception'
print 'hasattr'
import sys
if not hasattr(sys, 'stdout'): raise TestFailed, 'hasattr'
+ try:
+ hasattr(sys, 1)
+ except TypeError:
+ pass
+ else:
+ raise TestFailed, "hasattr(sys, 1) should raise an exception"
print 'hash'
Index: test_b2.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_b2.py,v
retrieving revision 1.24.6.1
retrieving revision 1.24.6.2
diff -C2 -d -r1.24.6.1 -r1.24.6.2
*** test_b2.py 2001/07/07 22:55:28 1.24.6.1
--- test_b2.py 2001/08/02 02:40:43 1.24.6.2
***************
*** 206,209 ****
--- 206,215 ----
setattr(sys, 'spam', 1)
if sys.spam != 1: raise TestFailed, 'setattr(sys, \'spam\', 1)'
+ try:
+ setattr(sys, 1, 'spam')
+ except TypeError:
+ pass
+ else:
+ raise TestFailed, "setattr(sys, 1, 'spam') should raise exception"
print 'str'
Index: test_import.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_import.py,v
retrieving revision 1.3.4.1
retrieving revision 1.3.4.2
diff -C2 -d -r1.3.4.1 -r1.3.4.2
*** test_import.py 2001/07/07 22:55:28 1.3.4.1
--- test_import.py 2001/08/02 02:40:43 1.3.4.2
***************
*** 20,25 ****
source = TESTFN + ".py"
- pyc = TESTFN + ".pyc"
pyo = TESTFN + ".pyo"
f = open(source, "w")
--- 20,28 ----
source = TESTFN + ".py"
pyo = TESTFN + ".pyo"
+ if sys.platform.startswith('java'):
+ pyc = TESTFN + "$py.class"
+ else:
+ pyc = TESTFN + ".pyc"
f = open(source, "w")
Index: test_pyexpat.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_pyexpat.py,v
retrieving revision 1.7.6.1
retrieving revision 1.7.6.2
diff -C2 -d -r1.7.6.1 -r1.7.6.2
*** test_pyexpat.py 2001/07/07 22:55:29 1.7.6.1
--- test_pyexpat.py 2001/08/02 02:40:43 1.7.6.2
***************
*** 4,7 ****
--- 4,8 ----
# handler, are obscure and unhelpful.
+ import pyexpat
from xml.parsers import expat
Index: test_scope.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_scope.py,v
retrieving revision 1.14.4.2
retrieving revision 1.14.4.3
diff -C2 -d -r1.14.4.2 -r1.14.4.3
*** test_scope.py 2001/07/14 07:47:34 1.14.4.2
--- test_scope.py 2001/08/02 02:40:43 1.14.4.3
***************
*** 466,467 ****
--- 466,480 ----
adaptgetter("foo", TestClass, (1, ""))
sys.settrace(None)
+
+ print "20. eval with free variables"
+
+ def f(x):
+ return lambda: x + 1
+
+ g = f(3)
+ try:
+ eval(g.func_code)
+ except TypeError:
+ pass
+ else:
+ print "eval() should have failed, because code contained free vars"