Skip to content
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

Add assertFloatsAreIdentical/assertComplexAreIdentical to unittest (or kwarg to assertEqual)? #121039

Open
skirpichev opened this issue Jun 26, 2024 · 1 comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@skirpichev
Copy link
Contributor

skirpichev commented Jun 26, 2024

Feature or enhancement

Proposal:

Clones of assertFloatsAreIdentical() are scattered across the CPython tests:

def assertFloatsAreIdentical(self, x, y):

def assertFloatIdentical(self, x, y):

def identical(self, x, y):

def assertEqualWithSign(self, actual, expected):

Maybe it's worth to have a dedicated check?

Or a special kwarg for the assertEqual method, to workaround NAN and -0.0 values for floats/complexes.

Edit:

Or at least some support from Lib/test/support... I was adding similar helper yet in another test file and that looks odd.

Numpy has numpy.testing.assert_equal():

>>> np.testing.assert_equal([0.0], [+0.0])
>>> np.testing.assert_equal([0.0], [-0.0])
Traceback (most recent call last):
  ...
AssertionError: 
Items are not equal:
item=0

 ACTUAL: 0.0
 DESIRED: -0.0
>>> np.testing.assert_equal([np.nan], [np.nan])
>>> np.testing.assert_equal([0.0], [np.nan])
Traceback (most recent call last):
  ...
AssertionError: 
Items are not equal:
item=0

 ACTUAL: 0.0
 DESIRED: nan

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

@skirpichev skirpichev added the type-feature A feature request or enhancement label Jun 26, 2024
@Eclips4 Eclips4 added stdlib Python modules in the Lib dir type-feature A feature request or enhancement and removed type-feature A feature request or enhancement stdlib Python modules in the Lib dir labels Jun 26, 2024
skirpichev added a commit to skirpichev/cpython that referenced this issue Jun 27, 2024
@skirpichev
Copy link
Contributor Author

pr is ready: #121071 (it implements the last option: methods added to test.support)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
2 participants