[Python-checkins] python/dist/src/Lib/test test_isinstance.py, 1.7, 1.8

bcannon at users.sourceforge.net bcannon at users.sourceforge.net
Sat Mar 20 17:52:23 EST 2004


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

Modified Files:
	test_isinstance.py 
Log Message:
Limit the nesting depth of a tuple passed as the second argument to
isinstance() or issubclass() to the recursion limit of the interpreter.


Index: test_isinstance.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_isinstance.py,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** test_isinstance.py	1 May 2003 17:45:37 -0000	1.7
--- test_isinstance.py	20 Mar 2004 22:52:14 -0000	1.8
***************
*** 5,8 ****
--- 5,9 ----
  import unittest
  from test import test_support
+ import sys
  
  
***************
*** 245,249 ****
--- 246,266 ----
          self.assertEqual(True, issubclass(str, (unicode, (Child, NewChild, basestring))))
  
+     def test_subclass_recursion_limit(self):
+         # make sure that issubclass raises RuntimeError before the C stack is
+         # blown
+         self.assertRaises(RuntimeError, blowstack, issubclass, str, str)
  
+     def test_isinstance_recursion_limit(self):
+         # make sure that issubclass raises RuntimeError before the C stack is
+         # blown 
+         self.assertRaises(RuntimeError, blowstack, isinstance, '', str)
+ 
+ def blowstack(fxn, arg, compare_to):
+     # Make sure that calling isinstance with a deeply nested tuple for its
+     # argument will raise RuntimeError eventually.
+     tuple_arg = (compare_to,)
+     for cnt in xrange(sys.getrecursionlimit()+5):
+         tuple_arg = (tuple_arg,)
+         fxn(arg, tuple_arg)
  
  




More information about the Python-checkins mailing list