summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_bool.py
diff options
context:
space:
mode:
authorJack Diederich <jackdied@gmail.com>2006-11-28 19:15:13 (GMT)
committerJack Diederich <jackdied@gmail.com>2006-11-28 19:15:13 (GMT)
commit4dafcc4ece09c2a60473bb109513de4e7d2c2b11 (patch)
tree32be8af9dd16e1ea407bf008c92d62f7cd7539bd /Lib/test/test_bool.py
parentdfc9d4f7aa38a3961847c034532e39f05a569f54 (diff)
downloadcpython-4dafcc4ece09c2a60473bb109513de4e7d2c2b11.zip
cpython-4dafcc4ece09c2a60473bb109513de4e7d2c2b11.tar.gz
cpython-4dafcc4ece09c2a60473bb109513de4e7d2c2b11.tar.bz2
- patch #1600346 submitted by Tomer Filiba
- Renamed nb_nonzero slots to nb_bool - Renamed __nonzero__ methods to __bool__ - update core, lib, docs, and tests to match
Diffstat (limited to 'Lib/test/test_bool.py')
-rw-r--r--Lib/test/test_bool.py35
1 files changed, 31 insertions, 4 deletions
diff --git a/Lib/test/test_bool.py b/Lib/test/test_bool.py
index 97ac480..8121e03 100644
--- a/Lib/test/test_bool.py
+++ b/Lib/test/test_bool.py
@@ -335,24 +335,51 @@ class BoolTest(unittest.TestCase):
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
+ # from __bool__(). 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):
+ def __bool__(self):
return self
check(Foo())
class Bar(object):
- def __nonzero__(self):
+ def __bool__(self):
return "Yes"
check(Bar())
class Baz(int):
- def __nonzero__(self):
+ def __bool__(self):
return self
check(Baz())
+ # __bool__() must return a bool not an int
+ class Spam(int):
+ def __bool__(self):
+ return 1
+ check(Spam())
+
+ class Eggs:
+ def __len__(self):
+ return -1
+ self.assertRaises(ValueError, bool, Eggs())
+
+ def test_sane_len(self):
+ # this test just tests our assumptions about __len__
+ # this will start failing if __len__ changes assertions
+ for badval in ['illegal', -1, 1 << 32]:
+ class A:
+ def __len__(self):
+ return badval
+ try:
+ bool(A())
+ except (Exception), e_bool:
+ pass
+ try:
+ len(A())
+ except (Exception), e_len:
+ pass
+ self.assertEqual(str(e_bool), str(e_len))
def test_main():
test_support.run_unittest(BoolTest)