[Python-3000] need help fixing broken tests in py3k-pep3137 branch

Christian Heimes lists at cheimes.de
Sat Nov 3 14:18:32 CET 2007


Paul Moore wrote:
> One of the failures here is in
> 
>     def test_create_from_bytes(self):
>         a = array.array('H', b"1234")
>         self.assertEqual(len(a) * a.itemsize, 4)
> 
> Traceback (most recent call last):
>   File "Lib/test/test_array.py", line 737, in test_create_from_bytes
>     self.assertEqual(len(a) * a.itemsize, 4)
> AssertionError: 8 != 4
> 
> However, 'H' is unsigned short, so I'd expect a.itemsize to be 2, and
> so the results *should* be 8 rather than 4.
> 
> Is this just a bug in the test?

No, it was a bug in the C code. 'H' represents a 16bit type. The correct
result is

>>> array.array('H', b"1234")
array('H', [12849, 13363])

However the code was reading the byte sequence int by int and created an
array with 4 elements instead of 2 elements. I've already fixed it.

Christian



More information about the Python-3000 mailing list