GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — case error in test_unary.py · Issue #99688 · python/cpython

case error in test_unary.py #99688

New issue
Copy link
New issue
Copy link
Closed
Closed
case error in test_unary.py#99688
Copy link
Labels
testsTests in the Lib/test dirTests in the Lib/test dir

Description

@Isaac-Lee
Isaac-Lee
opened on Nov 22, 2022
Issue body actions

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.

cpython/Lib/test/test_unary.py

Lines 23 to 27 in 7e3f09c

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.

cpython/Lib/test/test_unary.py

Lines 7 to 13 in 7e3f09c

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)

cpython/Lib/test/test_unary.py

Lines 15 to 21 in 7e3f09c

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

  • gh-99688: Fix tests in test in test_unary.py #99712

Activity

  1. AlexWaygood
    added
    testsTests in the Lib/test dirTests in the Lib/test dir
    on Nov 22, 2022
  2. sweeneyde commented on Nov 22, 2022

    @sweeneyde
    sweeneyde
    on Nov 22, 2022
    Member
    More actions

    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?

  3. Isaac-Lee commented on Nov 23, 2022

    @Isaac-Lee
    Isaac-Lee
    on Nov 23, 2022
    ContributorAuthor
    More actions

    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.

  4. sweeneyde
    added a commit that references this issue on Dec 11, 2022

    gh-99688: Fix outdated tests in test_unary (#99712)

    54289f8
  5. sweeneyde commented on Dec 11, 2022

    @sweeneyde
    sweeneyde
    on Dec 11, 2022
    Member
    More actions

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

    Reacted by Yesung(Isaac) Lee
    Reacted by Yesung(Isaac) Lee
  6. sweeneyde
    closed this as completedon Dec 11, 2022
  7. carljm
    added a commit that references this issue on Dec 14, 2022

    Merge branch 'main' into typedocs

    53d33a1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirTests in the Lib/test dir

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.