#4228: Pack negative values the same way as 2.4

in struct's L format.
This commit is contained in:
Georg Brandl 2009-01-01 12:15:31 +00:00
parent 775c307068
commit 6269fec171
3 changed files with 15 additions and 6 deletions

View file

@ -2,6 +2,8 @@ import array
import unittest
import struct
import warnings
warnings.filterwarnings("ignore", "struct integer overflow masking is deprecated",
DeprecationWarning)
from functools import wraps
from test.test_support import TestFailed, verbose, run_unittest
@ -461,6 +463,11 @@ class StructTest(unittest.TestCase):
self.check_float_coerce(endian + fmt, 1.0)
self.check_float_coerce(endian + fmt, 1.5)
def test_issue4228(self):
# Packing a long may yield either 32 or 64 bits
x = struct.pack('L', -1)[:4]
self.assertEqual(x, '\xff'*4)
def test_unpack_from(self):
test_string = 'abcd01234'
fmt = '4s'