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
+ use ComplexesAreIdenticalMixin from test.support
  • Loading branch information
skirpichev committed Oct 7, 2024
commit 4097aaf547aef6d9a3fd8d1a9dc297e9503f4571
31 changes: 2 additions & 29 deletions Lib/test/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from test import support
from test.support import import_helper, suppress_immortalization
from test.support.script_helper import assert_python_ok
from test.support.testcase import ComplexesAreIdenticalMixin

ISBIGENDIAN = sys.byteorder == "big"

Expand Down Expand Up @@ -43,35 +44,7 @@ def bigendian_to_native(value):
else:
return string_reverse(value)

class StructTest(unittest.TestCase):
# from Lib/test/test_complex.py
def assertFloatsAreIdentical(self, x, y):
"""assert that floats x and y are identical, in the sense that:
(1) both x and y are nans, or
(2) both x and y are infinities, with the same sign, or
(3) both x and y are zeros, with the same sign, or
(4) x and y are both finite and nonzero, and x == y

"""
msg = 'floats {!r} and {!r} are not identical'

if math.isnan(x) or math.isnan(y):
if math.isnan(x) and math.isnan(y):
return
elif x == y:
if x != 0.0:
return
# both zero; check that signs match
elif math.copysign(1.0, x) == math.copysign(1.0, y):
return
else:
msg += ': zeros have different signs'
self.fail(msg.format(x, y 5E74 ))

def assertComplexesAreIdentical(self, x, y):
self.assertFloatsAreIdentical(x.real, y.real)
self.assertFloatsAreIdentical(x.imag, y.imag)

class StructTest(ComplexesAreIdenticalMixin, unittest.TestCase):
def test_isbigendian(self):
self.assertEqual((struct.pack('=i', 1)[0] == 0), ISBIGENDIAN)

Expand Down
Loading
0