8000 gh-121039: add Floats/ComplexesAreIdenticalMixin to test.support.testcase by skirpichev · Pull Request #121071 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-121039: add Floats/ComplexesAreIdenticalMixin to test.support.testcase #121071

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
Prev Previous commit
Next Next commit
+ adapt Lib/test/test_ctypes/test_numbers.py
  • Loading branch information
skirpichev committed Jul 10, 2024
commit 4fc14b77bb75120a1f9bc28329b1f6b58fa5b280
31 changes: 2 additions & 29 deletions Lib/test/test_ctypes/test_numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import sys
import unittest
from itertools import combinations
from math import copysign, isnan
from operator import truth
from ctypes import (byref, sizeof, alignment,
c_char, c_byte, c_ubyte, c_short, c_ushort, c_int, c_uint,
c_long, c_ulong, c_longlong, c_ulonglong,
c_float, c_double, c_longdouble, c_bool)
from test.support.testcase import ComplexesAreIdenticalMixin


def valid_ranges(*types):
Expand Down Expand Up @@ -62,34 +62,7 @@ def __complex__(self):
NAN = float("nan")


class NumberTestCase(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 isnan(x) or isnan(y):
if isnan(x) and isnan(y):
return
elif x == y:
if x != 0.0:
return
# both zero; check that signs match
elif copysign(1.0, x) == copysign(1.0, y):
return
else:
msg += ': zeros have different signs'
self.fail(msg.format(x, y))

def assertComplexesAreIdentical(self, x, y):
self.assertFloatsAreIdentical(x.real, y.real)
self.assertFloatsAreIdentical(x.imag, y.imag)
class NumberTestCase(unittest.TestCase, ComplexesAreIdenticalMixin):

def test_default_init(self):
# default values are set to zero
Expand Down
Loading
0