8000 gh-128051: Fix tests if sys.float_repr_style is 'legacy' (#135908) · vstinner/cpython@8e7d6f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8e7d6f2

Browse files
skirpichevvstinner
andcommitted
pythongh-128051: Fix tests if sys.float_repr_style is 'legacy' (python#135908)
Co-authored-by: Victor Stinner <vstinner@python.org> (cherry picked from commit f3aec60)
1 parent ea25f4a commit 8e7d6f2

15 files changed

+49
-43
lines changed

Lib/difflib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ class SequenceMatcher:
7878
sequences. As a rule of thumb, a .ratio() value over 0.6 means the
7979
sequences are close matches:
8080
81-
>>> print(round(s.ratio(), 3))
82-
0.866
81+
>>> print(round(s.ratio(), 2))
82+
0.87
8383
>>>
8484
8585
If you're only interested in where the sequences match,

Lib/test/test_builtin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2774,7 +2774,8 @@ def test_namespace_order(self):
27742774

27752775
def load_tests(loader, tests, pattern):
27762776
from doctest import DocTestSuite
2777-
tests.addTest(DocTestSuite(builtins))
2777+
if sys.float_repr_style == 'short':
2778+
tests.addTest(DocTestSuite(builtins))
27782779
return tests
27792780

27802781
if __name__ == "__main__":

Lib/test/test_configparser.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -986,12 +986,12 @@ def test_add_section_default(self):
986986

987987
def test_defaults_keyword(self):
988988
"""bpo-23835 fix for ConfigParser"""
989-
cf = self.newconfig(defaults={1: 2.4})
990-
self.assertEqual(cf[self.default_section]['1'], '2.4')
991-
self.assertAlmostEqual(cf[self.default_section].getfloat('1'), 2.4)
992-
cf = self.newconfig(defaults={"A": 5.2})
993-
self.assertEqual(cf[self.default_section]['a'], '5.2')
994-
self.assertAlmostEqual(cf[self.default_section].getfloat('a'), 5.2)
989+
cf = self.newconfig(defaults={1: 2.5})
990+
self.assertEqual(cf[self.default_section]['1'], '2.5')
991+
self.assertAlmostEqual(< 9E88 span class="pl-s1">cf[self.default_section].getfloat('1'), 2.5)
992+
cf = self.newconfig(defaults={"A": 5.25})
993+
self.assertEqual(cf[self.default_section]['a'], '5.25')
994+
self.assertAlmostEqual(cf[self.default_section].getfloat('a'), 5.25)
995995

996996

997997
class ConfigParserTestCaseNoInterpolation(BasicTestCase, unittest.TestCase):

Lib/test/test_ctypes/test_parameters.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
import unittest
23
import test.support
34
from ctypes import (CDLL, PyDLL, ArgumentError,
@@ -226,7 +227,8 @@ def test_parameter_repr(self):
226227
self.assertRegex(repr(c_ulonglong.from_param(20000)), r"^<cparam '[LIQ]' \(20000\)>$")
227228
self.assertEqual(repr(c_float.from_param(1.5)), "<cparam 'f' (1.5)>")
228229
self.assertEqual(repr(c_double.from_param(1.5)), "<cparam 'd' (1.5)>")
229-
self.assertEqual(repr(c_double.from_param(1e300)), "<cparam 'd' (1e+300)>")
230+
if sys.float_repr_style == 'short':
231+
self.assertEqual(repr(c_double.from_param(1e300)), "<cparam 'd' (1e+300)>")
230232
self.assertRegex(repr(c_longdouble.from_param(1.5)), r"^<cparam ('d' \(1.5\)|'g' at 0x[A-Fa-f0-9]+)>$")
231233
self.assertRegex(repr(c_char_p.from_param(b'hihi')), r"^<cparam 'z' \(0x[A-Fa-f0-9]+\)>$")
232234
self.assertRegex(repr(c_wchar_p.from_param('hihi')), r"^<cparam 'Z' \(0x[A-Fa-f0-9]+\)>$")

Lib/test/test_enum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def load_tests(loader, tests, ignore):
3636
optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE,
3737
))
3838
howto_tests = os.path.join(REPO_ROOT, 'Doc/howto/enum.rst')
39-
if os.path.exists(howto_tests):
39+
if os.path.exists(howto_tests) and sys.float_repr_style == 'short':
4040
tests.addTests(doctest.DocFileSuite(
4141
howto_tests,
4242
module_relative=False,

Lib/test/test_float.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,8 @@ def test_format(self):
724724
self.assertEqual(format(INF, 'F'), 'INF')
725725

726726
@support.requires_IEEE_754
727+
@unittest.skipUnless(sys.float_repr_style == 'short',
728+
"applies only when using short float repr style")
727729
def test_format_testfile(self):
728730
with open(format_testfile, encoding="utf-8") as testfile:
729731
for line in testfile:

Lib/test/test_format.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,12 @@ def __bytes__(self):
342342
testcommon(b"%s", memoryview(b"abc"), b"abc")
343343
# %a will give the equivalent of
344344
# repr(some_obj).encode('ascii', 'backslashreplace')
345-
testcommon(b"%a", 3.14, b"3.14")
345+
testcommon(b"%a", 3.25, b"3.25")
346346
testcommon(b"%a", b"ghi", b"b'ghi'")
347347
testcommon(b"%a", "jkl", b"'jkl'")
348348
testcommon(b"%a", "\u0544", b"'\\u0544'")
349349
# %r is an alias for %a
350-
testcommon(b"%r", 3.14, b"3.14")
350+
testcommon(b"%r", 3.25, b"3.25")
351351
testcommon(b"%r", b"ghi", b"b'ghi'")
352352
testcommon(b"%r", "jkl", b"'jkl'")
353353
testcommon(b"%r", "\u0544", b"'\\u0544'")
@@ -403,19 +403,19 @@ def test_non_ascii(self):
403403

404404
self.assertEqual(format("abc", "\u2007<5"), "abc\u2007\u2007")
405405
self.assertEqual(format(123, "\u2007<5"), "123\u2007\u2007")
406-
self.assertEqual(format(12.3, "\u2007<6"), "12.3\u2007\u2007")
406+
self.assertEqual(format(12.5, "\u2007<6"), "12.5\u2007\u2007")
407407
self.assertEqual(format(0j, "\u2007<4"), "0j\u2007\u2007")
408408
self.assertEqual(format(1+2j, "\u2007<8"), "(1+2j)\u2007\u2007")
409409

410410
self.assertEqual(format("abc", "\u2007>5"), "\u2007\u2007abc")
411411
self.assertEqual(format(123, "\u2007>5"), "\u2007\u2007123")
412-
self.assertEqual(format(12.3, "\u2007>6"), "\u2007\u200712.3")
412+
self.assertEqual(format(12.5, "\u2007>6"), "\u2007\u200712.5")
413413
self.assertEqual(format(1+2j, "\u2007>8"), "\u2007\u2007(1+2j)")
414414
self.assertEqual(format(0j, "\u2007>4"), "\u2007\u20070j")
415415

416416
self.assertEqual(format("abc", "\u2007^5"), "\u2007abc\u2007")
417417
self.assertEqual(format(123, "\u2007^5"), "\u2007123\u2007")
418-
self.assertEqual(format(12.3, "\u2007^6"), "\u200712.3\u2007")
418+
self.assertEqual(format(12.5, "\u2007^6"), "\u200712.5\u2007")
419419
self.assertEqual(format(1+2j, "\u2007^8"), "\u2007(1+2j)\u2007")
420420
self.assertEqual(format(0j, "\u2007^4"), "\u20070j\u2007")
421421

Lib/test/test_fstring.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,9 +1325,9 @@ def test_equal_equal(self):
13251325

13261326
def test_conversions(self):
13271327
self.assertEqual(f'{3.14:10.10}', ' 3.14')
1328-
self.assertEqual(f'{3.14!s:10.10}', '3.14 ')
1329-
self.assertEqual(f'{3.14!r:10.10}', '3.14 ')
1330-
self.assertEqual(f'{3.14!a:10.10}', '3.14 ')
1328+
self.assertEqual(f'{1.25!s:10.10}', '1.25 ')
1329+
self.assertEqual(f'{1.25!r:10.10}', '1.25 ')
1330+
self.assertEqual(f'{1.25!a:10.10}', '1.25 ')
13311331

13321332
self.assertEqual(f'{"a"}', 'a')
13331333
self.assertEqual(f'{"a"!r}', "'a'")
@@ -1336,7 +1336,7 @@ def test_conversions(self):
13361336
# Conversions can have trailing whitespace after them since it
13371337
# does not provide any significance
13381338
self.assertEqual(f"{3!s }", "3")
1339-
self.assertEqual(f'{3.14!s :10.10}', '3.14 ')
1339+
self.assertEqual(f'{1.25!s :10.10}', '1.25 ')
13401340

13411341
# Not a conversion.
13421342
self.assertEqual(f'{"a!r"}', "a!r")

Lib/test/test_optparse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,9 +614,9 @@ def test_float_default(self):
614614
self.parser.add_option(
615615
"-p", "--prob",
616616
help="blow up with probability PROB [default: %default]")
617-
self.parser.set_defaults(prob=0.43)
617+
self.parser.set_defaults(prob=0.25)
618618
expected_help = self.help_prefix + \
619-
" -p PROB, --prob=PROB blow up with probability PROB [default: 0.43]\n"
619+
" -p PROB, --prob=PROB blow up with probability PROB [default: 0.25]\n"
620620
self.assertHelp(self.parser, expected_help)
621621

622622
def test_alt_expand(self):

Lib/test/test_peepholer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,9 @@ def format(fmt, *values):
562562
self.assertEqual(format('x = %d!', 1234), 'x = 1234!')
563563
self.assertEqual(format('x = %x!', 1234), 'x = 4d2!')
564564
self.assertEqual(format('x = %f!', 1234), 'x = 1234.000000!')
565-
self.assertEqual(format('x = %s!', 1234.5678901), 'x = 1234.5678901!')
566-
self.assertEqual(format('x = %f!', 1234.5678901), 'x = 1234.567890!')
567-
self.assertEqual(format('x = %d!', 1234.5678901), 'x = 1234!')
565+
self.assertEqual(format('x = %s!', 1234.0000625), 'x = 1234.0000625!')
566+
self.assertEqual(format('x = %f!', 1234.0000625), 'x = 1234.000063!')
567+
self.assertEqual(format('x = %d!', 1234.0000625), 'x = 1234!')
568568
self.assertEqual(format('x = %s%% %%%%', 1234), 'x = 1234% %%')
569569
self.assertEqual(format('x = %s!', '%% %s'), 'x = %% %s!')
570570
self.assertEqual(format('x = %s, y = %d', 12, 34), 'x = 12, y = 34')

0 commit comments

Comments
 (0)
0