[Python-checkins] python/dist/src/Lib/test test_new.py,1.17,1.18

mwh at users.sourceforge.net mwh at users.sourceforge.net
Thu Aug 12 19:56:32 CEST 2004


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31215/Lib/test

Modified Files:
	test_new.py 
Log Message:
Fix bug

[ 1005248 ] new.code() not cleanly checking its arguments

using the result of new.code() can still destroy the sun, but merely
calling the function shouldn't any more.

I also rewrote the existing tests of new.code() to use vastly less
un-bogus arguments, and added tests for the previous insane behaviours.


Index: test_new.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_new.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** test_new.py	12 Jun 2004 16:30:32 -0000	1.17
--- test_new.py	12 Aug 2004 17:56:29 -0000	1.18
***************
*** 1,3 ****
! from test.test_support import verbose, verify
  import sys
  import new
--- 1,3 ----
! from test.test_support import verbose, verify, TestFailed
  import sys
  import new
***************
*** 100,109 ****
  # Note: Jython will never have new.code()
  if hasattr(new, 'code'):
!     # XXX should use less criminally bogus arguments!
!     d = new.code(3, 3, 3, 3, codestr, (), (), (),
!                  "<string>", "<name>", 1, "", (), ())
      # test backwards-compatibility version with no freevars or cellvars
!     d = new.code(3, 3, 3, 3, codestr, (), (), (),
!                  "<string>", "<name>", 1, "")
      if verbose:
          print d
--- 100,165 ----
  # Note: Jython will never have new.code()
  if hasattr(new, 'code'):
!     def f(a): pass
!     
!     c = f.func_code
!     argcount = c.co_argcount
!     nlocals = c.co_nlocals
!     stacksize = c.co_stacksize
!     flags = c.co_flags
!     codestring = c.co_code
!     constants = c.co_consts
!     names = c.co_names
!     varnames = c.co_varnames
!     filename = c.co_filename
!     name = c.co_name
!     firstlineno = c.co_firstlineno
!     lnotab = c.co_lnotab
!     freevars = c.co_freevars
!     cellvars = c.co_cellvars
!     
!     d = new.code(argcount, nlocals, stacksize, flags, codestring,
!                  constants, names, varnames, filename, name,
!                  firstlineno, lnotab, freevars, cellvars)
!     
      # test backwards-compatibility version with no freevars or cellvars
!     d = new.code(argcount, nlocals, stacksize, flags, codestring,
!                  constants, names, varnames, filename, name,
!                  firstlineno, lnotab)
!     
!     try: # this used to trigger a SystemError
!         d = new.code(-argcount, nlocals, stacksize, flags, codestring,
!                      constants, names, varnames, filename, name,
!                      firstlineno, lnotab)
!     except ValueError:
!         pass
!     else:
!         raise TestFailed, "negative co_argcount didn't trigger an exception"
! 
!     try: # this used to trigger a SystemError
!         d = new.code(argcount, -nlocals, stacksize, flags, codestring,
!                      constants, names, varnames, filename, name,
!                      firstlineno, lnotab)
!     except ValueError:
!         pass
!     else:
!         raise TestFailed, "negative co_nlocals didn't trigger an exception"
!     
!     try: # this used to trigger a Py_FatalError!
!         d = new.code(argcount, nlocals, stacksize, flags, codestring,
!                      constants, (5,), varnames, filename, name,
!                      firstlineno, lnotab)
!     except TypeError:
!         pass
!     else:
!         raise TestFailed, "non-string co_name didn't trigger an exception"
! 
!     # new.code used to be a way to mutate a tuple...
!     class S(str): pass
!     t = (S("ab"),)
!     d = new.code(argcount, nlocals, stacksize, flags, codestring,
!                  constants, t, varnames, filename, name,
!                  firstlineno, lnotab)
!     verify(type(t[0]) is S, "eek, tuple changed under us!")
! 
      if verbose:
          print d



More information about the Python-checkins mailing list