10000 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
address review: add mixin to test_getargs.py
  • Loading branch information
skirpichev committed Sep 8, 2024
commit 01036e69fd2965b811ff84fa2c16368515c4da87
27 changes: 12 additions & 15 deletions Lib/test/test_capi/test_getargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from test.support import import_helper
from test.support import script_helper
from test.support import warnings_helper
from test.support.testcase import FloatsAreIdenticalMixin
# Skip this test if the _testcapi module isn't available.
_testcapi = import_helper.import_module('_testcapi')
from _testcapi import getargs_keywords, getargs_keyword_only
Expand Down Expand Up @@ -436,11 +437,7 @@ def test_K(self):
self.assertEqual(VERY_LARGE & ULLONG_MAX, getargs_K(VERY_LARGE))


class Float_TestCase(unittest.TestCase):
def assertEqualWithSign(self, actual, expected):
self.assertEqual(actual, expected)
self.assertEqual(math.copysign(1, actual), math.copysign(1, expected))

class Float_TestCase(unittest.TestCase, FloatsAreIdenticalMixin):
def test_f(self):
from _testcapi import getargs_f
self.assertEqual(getargs_f(4.25), 4.25)
Expand All @@ -462,10 +459,10 @@ def test_f(self):
self.assertEqual(getargs_f(DBL_MAX), INF)
self.assertEqual(getargs_f(-DBL_MAX), -INF)
if FLT_MIN > DBL_MIN:
self.assertEqualWithSign(getargs_f(DBL_MIN), 0.0)
self.assertEqualWithSign(getargs_f(-DBL_MIN), -0.0)
self.assertEqualWithSign(getargs_f(0.0), 0.0)
self.assertEqualWithSign(getargs_f(-0.0), -0.0)
self.assertFloatsAreIdentical(getargs_f(DBL_MIN), 0.0)
self.assertFloatsAreIdentical(getargs_f(-DBL_MIN), -0.0)
self.assertFloatsAreIdentical(getargs_f(0.0), 0.0)
self.assertFloatsAreIdentical(getargs_f(-0.0), -0.0)
r = getargs_f(NAN)
self.assertNotEqual(r, r)

Expand Down Expand Up @@ -494,8 +491,8 @@ def test_d(self):
self.assertEqual(getargs_d(x), x)
self.assertRaises(OverflowError, getargs_d, 1<<DBL_MAX_EXP)
self.assertRaises(OverflowError, getargs_d, -1<<DBL_MAX_EXP)
self.assertEqualWithSign(getargs_d(0.0), 0.0)
self.assertEqualWithSign(getargs_d(-0.0), -0.0)
self.assertFloatsAreIdentical(getargs_d(0.0), 0.0)
self.assertFloatsAreIdentical(getargs_d(-0.0), -0.0)
r = getargs_d(NAN)
self.assertNotEqual(r, r)

Expand All @@ -519,10 +516,10 @@ def test_D(self):
self.assertEqual(getargs_D(c), c)
c = complex(1.0, x)
self.assertEqual(getargs_D(c), c)
self.assertEqualWithSign(getargs_D(complex(0.0, 1.0)).real, 0.0)
self.assertEqualWithSign(getargs_D(complex(-0.0, 1.0)).real, -0.0)
self.assertEqualWithSign(getargs_D(complex(1.0, 0.0)).imag, 0.0)
self.assertEqualWithSign(getargs_D(complex(1.0, -0.0)).imag, -0.0)
self.assertFloatsAreIdentical(getargs_D(complex(0.0, 1.0)).real, 0.0)
self.assertFloatsAreIdentical(getargs_D(complex(-0.0, 1.0)).real, -0.0)
self.assertFloatsAreIdentical(getargs_D(complex(1.0, 0.0)).imag, 0.0)
self.assertFloatsAreIdentical(getargs_D(complex(1.0, -0.0)).imag, -0.0)


class Paradox:
Expand Down
Loading
0