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

case error in test_unary.py #99688

Closed
Isaac-Lee opened this issue Nov 22, 2022 · 3 comments
Closed

case error in test_unary.py #99688

Isaac-Lee opened this issue Nov 22, 2022 · 3 comments
Labels
tests Tests in the Lib/test dir

Comments

@Isaac-Lee
Copy link
Contributor

Isaac-Lee commented Nov 22, 2022

Hello all,
I was looking throw the test code in cpython to use a test cases for my own python interpreter.
While looking at the code, I got curious.

First is this function.

def test_invert(self):
self.assertTrue(-2 == 0 - 2)
self.assertEqual(-0, 0)
self.assertEqual(--2, 2)
self.assertTrue(-2 == 0 - 2)

I think this function is not testing invert operator.
Instead it is just copying test cases of negative operator.

Next is these functions.

def test_negative(self):
self.assertTrue(-2 == 0 - 2)
self.assertEqual(-0, 0)
self.assertEqual(--2, 2)
self.assertTrue(-2 == 0 - 2)
self.assertTrue(-2.0 == 0 - 2.0)
self.assertTrue(-2j == 0 - 2j)

def test_positive(self):
self.assertEqual(+2, 2)
self.assertEqual(+0, 0)
self.assertEqual(++2, 2)
self.assertEqual(+2, 2)
self.assertEqual(+2.0, 2.0)
self.assertEqual(+2j, 2j)

I think these functions have duplicated test cases.
self.assertTrue(-2 == 0 - 2) tested twice in test_negative,
self.assertEqual(+2, 2) tested twice as well in test_positive.

I want to know if there is an intention that I don't know.
Or if there is a problem, I think we need to fix the test code.

Linked PRs

@AlexWaygood AlexWaygood added the tests Tests in the Lib/test dir label Nov 22, 2022
@sweeneyde
Copy link
Member

It looks like some of this is left over from Python 2, where the test cases would have said self.assertEqual(+2L, 2L). Redundant tests can be safely removed now.

I agree that test_invert should be fixed to actually test the ~ operator.

Would you like to make a PR?

@Isaac-Lee
Copy link
Contributor Author

Isaac-Lee commented Nov 23, 2022

It looks like some of this is left over from Python 2, where the test cases would have said self.assertEqual(+2L, 2L). Redundant tests can be safely removed now.

Thank you for your answer. Now I understand.

And sure if I can make a PR then it would be grateful.

sweeneyde pushed a commit that referenced this issue Dec 11, 2022
* Remove duplicates from "L" suffix removal
* test_invert now tests `~`.
@sweeneyde
Copy link
Member

I'm sorry this took me so long to get to. Thanks for your contribution!

carljm added a commit to carljm/cpython that referenced this issue Dec 14, 2022
* main: (103 commits)
  pythongh-100248: Add missing `ssl_shutdown_timeout` parameter in `asyncio` docs (python#100249)
  Assorted minor fixes for specialization stats. (pythonGH-100219)
  pythongh-100176: venv: Remove redundant compat code for Python <= 3.2 (python#100177)
  pythonGH-100222: Redefine _Py_CODEUNIT as a union to clarify structure of code unit. (pythonGH-100223)
  pythongh-99955: undef ERROR and SUCCESS before redefining (fixes sanitizer warning) (python#100215)
  pythonGH-100206: use versionadded for the addition of sysconfig.get_default_scheme (python#100207)
  pythongh-81057: Move _Py_RefTotal to the "Ignored Globals" List (pythongh-100203)
  pythongh-81057: Move Signal-Related Globals to _PyRuntimeState (pythongh-100085)
  pythongh-81057: Move faulthandler Globals to _PyRuntimeState (pythongh-100152)
  pythongh-81057: Move tracemalloc Globals to _PyRuntimeState (pythongh-100151)
  pythonGH-100143: Improve collecting pystats for parts of runs (pythonGH-100144)
  pythongh-99955: standardize return values of functions in compiler's code-gen (python#100010)
  pythongh-79218: Define `MS_WIN64` macro for Mingw-w64 64bit on Windows (pythonGH-100137)
  Fix: typo (Indention) (pythonGH-99904)
  pythongh-96715 Remove redundant NULL check in `profile_trampoline` function (python#96716)
  pythongh-100176: remove incorrect version compatibility check from argument clinic (python#100190)
  clarify the 4300-digit limit on int-str conversion (python#100175)
  pythongh-70393: Clarify mention of "middle" scope (python#98839)
  pythongh-99688: Fix outdated tests in test_unary (python#99712)
  pythongh-100174: [Enum] Correct PowersOfThree example. (pythonGH-100178)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir
Projects
None yet
Development

No branches or pull requests

3 participants