[Python-checkins] python/dist/src/Lib/test test_bool.py,1.13,1.14

jhylton@users.sourceforge.net jhylton@users.sourceforge.net
Fri, 27 Jun 2003 10:40:18 -0700


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

Modified Files:
	test_bool.py 
Log Message:
Add tests for __nonzero__() problems.


Index: test_bool.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_bool.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** test_bool.py	12 May 2003 20:19:36 -0000	1.13
--- test_bool.py	27 Jun 2003 17:40:16 -0000	1.14
***************
*** 321,324 ****
--- 321,345 ----
          self.assertEqual(cPickle.dumps(False, True), "I00\n.")
  
+     def test_convert_to_bool(self):
+         # Verify that TypeError occurs when bad things are returned
+         # from __nonzero__().  This isn't really a bool test, but
+         # it's related.
+         check = lambda o: self.assertRaises(TypeError, bool, o)
+         class Foo(object):
+             def __nonzero__(self):
+                 return self
+         check(Foo())
+         
+         class Bar(object):
+             def __nonzero__(self):
+                 return "Yes"
+         check(Bar())
+         
+         class Baz(int):
+             def __nonzero__(self):
+                 return self
+         check(Baz())
+         
+ 
  def test_main():
      test_support.run_unittest(BoolTest)