8000 gh-121249: Support _Complex types in the struct module by skirpichev · Pull Request #121613 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-121249: Support _Complex types in the struct module #121613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Oct 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
address review: separate tests
  • Loading branch information
skirpichev committed Jul 13, 2024
commit caaef44f08b2c05a6a59932f52ff19213fa2409f
27 changes: 14 additions & 13 deletions Lib/test/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,20 +812,8 @@ 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")
def test_c_complex_round_trip(self):
if not have_c_complex:
msg1 = "'E' format not supported on this system"
msg2 = "'C' format not supported on this system"
with self.assertRaisesRegex(struct.error, msg1):
struct.pack('E', 1j)
with self.assertRaisesRegex(struct.error, msg1):
struct.unpack('E', b'1')
with self.assertRaisesRegex(struct.error, msg2):
struct.pack('C', 1j)
with self.assertRaisesRegex(struct.error, msg2):
struct.unpack('C', b'1')
return

values = [complex(*_) for _ in combinations([1, -1, 0.0, -0.0, 2,
-3, INF, -INF, NAN], 2)]
for z in values:
Expand All @@ -834,6 +822,19 @@ 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")
def test_c_complex_error(self):
msg1 = "'E' format not supported on this system"
msg2 = "'C' format not supported on this system"
with self.assertRaisesRegex(struct.error, msg1):
struct.pack('E', 1j)
with self.assertRaisesRegex(struct.error, msg1):
struct.unpack('E', b'1')
with self.assertRaisesRegex(struct.error, msg2):
struct.pack('C', 1j)
with self.assertRaisesRegex(struct.error, msg2):
struct.unpack('C', b'1')


class UnpackIteratorTest(unittest.TestCase):
"""
Expand Down
Loading
0