-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
gh-109546: Add more tests for formatting floats and fractions #109548
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1220,6 +1220,30 @@ def test_invalid_formats(self): | |
with self.assertRaises(ValueError): | ||
format(fraction, spec) | ||
|
||
@requires_IEEE_754 | ||
def test_float_format_testfile(self): | ||
from test.test_float import format_testfile | ||
with open(format_testfile, encoding="utf-8") as testfile: | ||
for line in testfile: | ||
if line.startswith('--'): | ||
continue | ||
line = line.strip() | ||
if not line: | ||
continue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose that such logic is used in other files using formatfloat_testcases.txt. Is there a good place to share common code? If we add mathdata/, can we add a helper function there which would iterate on the file and strip comments? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was going to add it in |
||
|
||
lhs, rhs = map(str.strip, line.split('->')) | ||
fmt, arg = lhs.split() | ||
if fmt == '%r': | ||
continue | ||
with self.subTest(fmt=fmt, arg=arg): | ||
f = F(float(arg)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a variable for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
self.assertEqual(format(f, fmt[1:]), rhs) | ||
if f: # skip negative zero | ||
self.assertEqual(format(-f, fmt[1:]), '-' + rhs) | ||
f = F(arg) | ||
self.assertEqual(float(format(f, fmt[1:])), float(rhs)) | ||
self.assertEqual(float(format(-f, fmt[1:])), float('-' + rhs)) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to just copy/paste the code to get the path here:
I prefer to not make tests inter-dependents. Sometimes, just importing a test has side effects.