Skip to content

Commit d55f554

Browse files
CPython Developersyouknowone
CPython Developers
authored andcommitted
test_import from CPython 3.11.2
1 parent a0472e1 commit d55f554

28 files changed

+1483
-0
lines changed

Lib/test/double_const.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from test.support import TestFailed
2+
3+
# A test for SF bug 422177: manifest float constants varied way too much in
4+
# precision depending on whether Python was loading a module for the first
5+
# time, or reloading it from a precompiled .pyc. The "expected" failure
6+
# mode is that when test_import imports this after all .pyc files have been
7+
# erased, it passes, but when test_import imports this from
8+
# double_const.pyc, it fails. This indicates a woeful loss of precision in
9+
# the marshal format for doubles. It's also possible that repr() doesn't
10+
# produce enough digits to get reasonable precision for this box.
11+
12+
PI = 3.14159265358979324
13+
TWOPI = 6.28318530717958648
14+
15+
PI_str = "3.14159265358979324"
16+
TWOPI_str = "6.28318530717958648"
17+
18+
# Verify that the double x is within a few bits of eval(x_str).
19+
def check_ok(x, x_str):
20+
assert x > 0.0
21+
x2 = eval(x_str)
22+
assert x2 > 0.0
23+
diff = abs(x - x2)
24+
# If diff is no larger than 3 ULP (wrt x2), then diff/8 is no larger
25+
# than 0.375 ULP, so adding diff/8 to x2 should have no effect.
26+
if x2 + (diff / 8.) != x2:
27+
raise TestFailed("Manifest const %s lost too much precision " % x_str)
28+
29+
check_ok(PI, PI_str)
30+
check_ok(TWOPI, TWOPI_str)

Lib/test/relimport.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .test_import import *

0 commit comments

Comments
 (0)