[Python-checkins] CVS: python/dist/src/Lib/test test_contains.py,1.3,1.4

Jeremy Hylton python-dev@python.org
2000年4月27日 17:40:11 -0400


Update of /projects/cvsroot/python/dist/src/Lib/test
In directory goon.cnri.reston.va.us:/home/jhylton/python/src/Lib/test
Modified Files:
	test_contains.py 
Log Message:
add some more contains tests on the builtin types
Index: test_contains.py
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Lib/test/test_contains.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** test_contains.py	2000年04月10日 13:52:13	1.3
--- test_contains.py	2000年04月27日 21:40:08	1.4
***************
*** 120,121 ****
--- 120,168 ----
 except TypeError:
 	pass
+ 
+ # A collection of tests on builtin sequence types
+ a = range(10)
+ for i in a:
+ 	check(i in a, "%s not in %s" % (`i`, `a`))
+ check(16 not in a, "16 not in %s" % `a`)
+ check(a not in a, "%s not in %s" % (`a`, `a`))
+ 
+ a = tuple(a)
+ for i in a:
+ 	check(i in a, "%s not in %s" % (`i`, `a`))
+ check(16 not in a, "16 not in %s" % `a`)
+ check(a not in a, "%s not in %s" % (`a`, `a`))
+ 
+ class Deviant1:
+ 	"""Behaves strangely when compared
+ 
+ 	This class is designed to make sure that the contains code
+ 	works when the list is modified during the check.
+ 	"""
+ 
+ 	aLongList = range(15)
+ 	aShortList = range(5)
+ 	aList = aLongList
+ 	
+ 	def __cmp__(self, other):
+ 		if other == 12:
+ 			self.aList = self.aShortList
+ 		return 1
+ 
+ check(Deviant1() not in Deviant1.aList, "Deviant1 failed")
+ 
+ class Deviant2:
+ 	"""Behaves strangely when compared
+ 
+ 	This class raises an exception during comparison. That in
+ 	turn causes the comparison to fail with a TypeError.
+ 	"""
+ 
+ 	def __cmp__(self, other):
+ 		if other == 4:
+ 			raise RuntimeError, "gotcha"
+ 
+ try:
+ 	check(Deviant2() not in a, "oops")
+ except TypeError:
+ 	pass

AltStyle によって変換されたページ (->オリジナル) /