10000 Address review · python/cpython@23319d9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 23319d9

Browse files
committed
Address review
1 parent 106c268 commit 23319d9

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

Lib/test/test_import/__init__.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
from test.support import os_helper
2727
from test.support import (
28-
STDLIB_DIR, swap_attr, swap_item, cpython_only, is_emscripten,
28+
STDLIB_DIR, TEST_HOME_DIR, swap_attr, swap_item, cpython_only, is_emscripten,
2929
is_wasi, run_in_subinterp, run_in_subinterp_with_config, Py_TRACE_REFS)
3030
from test.support.import_helper import (
3131
forget, make_legacy_pyc, unlink, unload, ready_to_import,
@@ -408,11 +408,6 @@ def test_case_sensitivity(self):
408408
with self.assertRaises(ImportError):
409409
import RAnDoM
410410

411-
def test_double_const(self):
412-
# Another brief digression to test the accuracy of manifest float
413-
# constants.
414-
from test.test_import.data import double_const # don't blink -- that *was* the test
415-
416411
def test_import(self):
417412
def test_with_extension(ext):
418413
# The extension is normally ".py", perhaps ".pyw".
@@ -877,6 +872,33 @@ def test_pyc_always_writable(self):
877872
m = __import__(name)
878873
self.assertEqual(m.x, 'rewritten')
879874

875+
def test_double_const(self):
876+
# Importing double_const checks that float constants
877+
# serialiazed by marshal as PYC files don't lose precision
878+
# (SF bug 422177).
879+
filepath = os.path.join(
880+
TEST_HOME_DIR,
881+
'test_import',
882+
'data',
883+
'double_const.py',
884+
)
885+
886+
with open(filepath, 'r', encoding='utf8') as f:
887+
source = f.read()
888+
889+
with ready_to_import(source=source) as (name, path):
890+
# Initial import should be fine:
891+
__import__(name)
892+
893+
# Now, delete source file, only keep `.pyc` file and import again:
894+
unlink(path)
895+
unload(name)
896+
importlib.invalidate_caches()
897+
898+
bytecode_only = path + 'c'
899+
os.rename(importlib.util.cache_from_source(path), bytecode_only)
900+
__import__(name)
901+
880902

881903
class PycRewritingTests(unittest.TestCase):
882904
# Test that the `co_filename` attribute on code objects always points

0 commit comments

Comments
 (0)
0