[Python-checkins] CVS: python/dist/src/Lib/test test_grammar.py,1.24,1.25

Jeremy Hylton jhylton@users.sourceforge.net
Thu, 25 Jan 2001 09:03:39 -0800


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv27469

Modified Files:
	test_grammar.py 
Log Message:
add extra tests to verify that co_varnames is being set up properly

also normalize checks for syntax errors and delete commented out
definition of verify.


Index: test_grammar.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_grammar.py,v
retrieving revision 1.24
retrieving revision 1.25
diff -C2 -r1.24 -r1.25
*** test_grammar.py	2001/01/23 01:51:40	1.24
--- test_grammar.py	2001/01/25 17:03:37	1.25
***************
*** 4,7 ****
--- 4,15 ----
  from test_support import *
  
+ def check_syntax(statement):
+     try:
+         compile(statement, '<string>', 'exec')
+     except SyntaxError:
+         print 'SyntaxError expected for "%s"' % statement
+     else:
+         print 'Missing SyntaxError: "%s"' % statement
+ 
  print '1. Parser'
  
***************
*** 84,90 ****
  print '1.1.3 String literals'
  
- ##def verify(s):
- ##      if not s: raise TestFailed, 'see traceback'
- 
  x = ''; y = ""; verify(len(x) == 0 and x == y)
  x = '\''; y = "'"; verify(len(x) == 1 and x == y and ord(x) == 39)
--- 92,95 ----
***************
*** 155,158 ****
--- 160,169 ----
  def f3(two, arguments): pass
  def f4(two, (compound, (argument, list))): pass
+ def f5((compound, first), two): pass
+ verify(f2.func_code.co_varnames == ('one_argument',))
+ verify(f3.func_code.co_varnames == ('two', 'arguments'))
+ verify(f4.func_code.co_varnames == ('two', '.2', 'compound', 'argument',
+                                     'list'))
+ verify(f5.func_code.co_varnames == ('.0', 'two', 'compound', 'first'))
  def a1(one_arg,): pass
  def a2(two, args,): pass
***************
*** 160,164 ****
  def v1(a, *rest): pass
  def v2(a, b, *rest): pass
! def v3(a, (b, c), *rest): pass
  def d01(a=1): pass
  d01()
--- 171,177 ----
  def v1(a, *rest): pass
  def v2(a, b, *rest): pass
! def v3(a, (b, c), *rest): return a, b, c, rest
! verify(v3.func_code.co_varnames == ('a', '.2', 'rest', 'b', 'c'))
! verify(v3(1, (2, 3), 4) == (1, 2, 3, (4,)))
  def d01(a=1): pass
  d01()
***************
*** 303,313 ****
  
  # syntax errors
- def check_syntax(statement):
-     try:
-         compile(statement, '<string>', 'exec')
-     except SyntaxError:
-         pass
-     else:
-         print 'Missing SyntaxError: "%s"' % statement
  check_syntax('print ,')
  check_syntax('print >> x,')
--- 316,319 ----
***************
*** 618,633 ****
  
  print test_in_func(nums)
- 
- try:
-     eval("[i, s for i in nums for s in strs]")
-     print "FAIL: should have raised a SyntaxError!"
- except SyntaxError:
-     print "good: got a SyntaxError as expected"
  
! try:
!     eval("[x if y]")
!     print "FAIL: should have raised a SyntaxError!"
! except SyntaxError:
!     print "good: got a SyntaxError as expected"
  
  suppliers = [
--- 624,630 ----
  
  print test_in_func(nums)
  
! check_syntax("[i, s for i in nums for s in strs]")
! check_syntax("[x if y]")
  
  suppliers = [