FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Improve tests for str to Fraction conversion by serhiy-storchaka · Pull Request #134010 · python/cpython · GitHub

Repository navigation

Improve tests for str to Fraction conversion - #134010

Merged
serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:testFromString
May 14, 2025
Merged

serhiy-storchaka merged 1 commit into
python:mainfrom
serhiy-storchaka:testFromString

Conversation

Copy link
Copy Markdown
Member

No description provided.

self.assertEqual((3, 2), _components(F(" \n +3/2")))
self.assertEqual((-3, 2), _components(F("-3/2 ")))
self.assertEqual((13, 2), _components(F(" 013/02 \n ")))
self.assertEqual((13, 2), _components(F(" 0013/002 \n ")))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Why this was replaced, not added?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It is virtually the same test, but tests that more than one zero is accepted. There were no tests for leading zero in other forms, so they were added.

Comment on lines +425 to +427
def check_invalid(s):
msg = "Invalid literal for Fraction: " + repr(s)
self.assertRaisesMessage(ValueError, msg, F, s)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This looks fine.

But maybe use subTest?

for value in ["3/", "/2",  # there can be a lot of...
              # Denominators don't need a sign.
              "3/+2", "3/-2",
              # Imitate float's parsing.
              ...]:
    with self.subTest(value=value):
        check_invalid(value)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The main reason is that if we make error messages more specific, it is easier to add an optional parameter, while keeping default for most tests. For example, I originally planned to add the tests here that are currently in test_limit_int.

skirpichev self-requested a review May 14, 2025 16:59
serhiy-storchaka merged commit 17d0fec into python:main May 14, 2025

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

serhiy-storchaka deleted the testFromString branch May 14, 2025 17:16
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 14, 2025
(cherry picked from commit 17d0fec)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 14, 2025
(cherry picked from commit 17d0fec)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>

bedevere-app Bot commented May 14, 2025

Copy link
Copy Markdown

GH-134016 is a backport of this pull request to the 3.14 branch.

bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label May 14, 2025

bedevere-app Bot commented May 14, 2025

Copy link
Copy Markdown

GH-134017 is a backport of this pull request to the 3.13 branch.

bedevere-app Bot removed the needs backport to 3.13 only security fixes label May 14, 2025
serhiy-storchaka added a commit that referenced this pull request May 14, 2025
…34017)

(cherry picked from commit 17d0fec)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this pull request May 14, 2025
…34016)

(cherry picked from commit 17d0fec)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
skirpichev removed their request for review January 28, 2026 01:22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip issue skip news tests Tests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL