mirror of
https://github.com/python/cpython.git
synced 2025-11-09 01:51:26 +00:00
gh-121249: unconditionally support complex types in struct (GH-132864)
Co-authored-by: Lisandro Dalcin <dalcinl@gmail.com> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
This commit is contained in:
parent
e6c518d2eb
commit
f425509349
5 changed files with 21 additions and 89 deletions
|
|
@ -22,12 +22,6 @@
|
|||
INF = float('inf')
|
||||
NAN = float('nan')
|
||||
|
||||
try:
|
||||
struct.pack('D', 1j)
|
||||
have_c_complex = True
|
||||
except struct.error:
|
||||
have_c_complex = False
|
||||
|
||||
def iter_integer_formats(byteorders=byteorders):
|
||||
for code in integer_codes:
|
||||
for byteorder in byteorders:
|
||||
|
|
@ -796,7 +790,6 @@ def test_repr(self):
|
|||
s = struct.Struct('=i2H')
|
||||
self.assertEqual(repr(s), f'Struct({s.format!r})')
|
||||
|
||||
@unittest.skipUnless(have_c_complex, "requires C11 complex type support")
|
||||
def test_c_complex_round_trip(self):
|
||||
values = [complex(*_) for _ in combinations([1, -1, 0.0, -0.0, 2,
|
||||
-3, INF, -INF, NAN], 2)]
|
||||
|
|
@ -806,19 +799,6 @@ def test_c_complex_round_trip(self):
|
|||
round_trip = struct.unpack(f, struct.pack(f, z))[0]
|
||||
self.assertComplexesAreIdentical(z, round_trip)
|
||||
|
||||
@unittest.skipIf(have_c_complex, "requires no C11 complex type support")
|
||||
def test_c_complex_error(self):
|
||||
msg1 = "'F' format not supported on this system"
|
||||
msg2 = "'D' format not supported on this system"
|
||||
with self.assertRaisesRegex(struct.error, msg1):
|
||||
struct.pack('F', 1j)
|
||||
with self.assertRaisesRegex(struct.error, msg1):
|
||||
struct.unpack('F', b'1')
|
||||
with self.assertRaisesRegex(struct.error, msg2):
|
||||
struct.pack('D', 1j)
|
||||
with self.assertRaisesRegex(struct.error, msg2):
|
||||
struct.unpack('D', b'1')
|
||||
|
||||
|
||||
class UnpackIteratorTest(unittest.TestCase):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue