summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2003-06-27 17:40:16 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2003-06-27 17:40:16 (GMT)
commit7ff55e6bc548495ea8045194325c0226bf725359 (patch)
tree62a89af21954d9ebfc5c16c0f6282170378de169 /Lib
parent3e3159ce6ac6dc27d17b99ba758c1322a67427bb (diff)
downloadcpython-7ff55e6bc548495ea8045194325c0226bf725359.zip
cpython-7ff55e6bc548495ea8045194325c0226bf725359.tar.gz
cpython-7ff55e6bc548495ea8045194325c0226bf725359.tar.bz2
Add tests for __nonzero__() problems.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_bool.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_bool.py b/Lib/test/test_bool.py
index dd18d84..f2a4322 100644
--- a/Lib/test/test_bool.py
+++ b/Lib/test/test_bool.py
@@ -320,6 +320,27 @@ class BoolTest(unittest.TestCase):
self.assertEqual(cPickle.dumps(True, True), "I01\n.")
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)