diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_struct.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/test/test_struct.py b/Lib/test/test_struct.py index ce2c22d..1877192 100644 --- a/Lib/test/test_struct.py +++ b/Lib/test/test_struct.py @@ -491,6 +491,9 @@ class StructTest(unittest.TestCase): self.test_unpack_from(cls=buffer) def test_bool(self): + class ExplodingBool(object): + def __nonzero__(self): + raise IOError for prefix in tuple("<>!=")+('',): false = (), [], [], '', 0 true = [1], 'test', 5, -1, 0xffffffffL+1, 0xffffffff//2 @@ -519,8 +522,11 @@ class StructTest(unittest.TestCase): self.assertFalse(prefix, msg='encoded bool is not one byte: %r' %packed) - for c in '\x01\x7f\xff\x0f\xf0': - self.assertTrue(struct.unpack('>?', c)[0]) + self.assertRaises(IOError, struct.pack, prefix + '?', + ExplodingBool()) + + for c in [b'\x01', b'\x7f', b'\xff', b'\x0f', b'\xf0']: + self.assertTrue(struct.unpack('>?', c)[0]) @unittest.skipUnless(IS32BIT, "Specific to 32bit machines") def test_crasher(self): |