Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Improve tests for str to Fraction conversion#134010

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

serhiy-storchaka
Copy link
Member

No description provided.

self.assertEqual((3, 2), _components(F("3/2")))
self.assertEqual((3, 2), _components(F("3 / 2")))
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
Contributor

Choose a reason for hiding this comment

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

Why this was replaced, not added?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

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
Contributor

Choose a reason for hiding this comment

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

This looks fine.

But maybe use subTest?

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

StanFromIreland reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

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.

@skirpichevskirpichev self-requested a reviewMay 14, 2025 16:59
@serhiy-storchakaserhiy-storchaka merged commit17d0fec intopython:mainMay 14, 2025
50 checks passed
@miss-islington-app
Copy link

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-storchakaserhiy-storchaka deleted the testFromString branchMay 14, 2025 17:16
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestMay 14, 2025
(cherry picked from commit17d0fec)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestMay 14, 2025
(cherry picked from commit17d0fec)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-app
Copy link

GH-134016 is a backport of this pull request to the3.14 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.14bugs and security fixes labelMay 14, 2025
@bedevere-app
Copy link

GH-134017 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelMay 14, 2025
serhiy-storchaka added a commit that referenced this pull requestMay 14, 2025
…34017)(cherry picked from commit17d0fec)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this pull requestMay 14, 2025
…34016)(cherry picked from commit17d0fec)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@eendebakpteendebakptAwaiting requested review from eendebakpt

@skirpichevskirpichevAwaiting requested review from skirpichev

Assignees
No one assigned
Labels
skip issueskip newstestsTests in the Lib/test dir
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@serhiy-storchaka@skirpichev

[8]ページ先頭

©2009-2025 Movatter.jp