Skip to content
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

gh-108303: Move double_const to test_import where it belongs #112108

Merged
merged 6 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions Lib/test/test_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from test.support import os_helper
from test.support import (
STDLIB_DIR, swap_attr, swap_item, cpython_only, is_emscripten,
STDLIB_DIR, TEST_HOME_DIR, swap_attr, swap_item, cpython_only, is_emscripten,
sobolevn marked this conversation as resolved.
Show resolved Hide resolved
is_wasi, run_in_subinterp, run_in_subinterp_with_config, Py_TRACE_REFS)
from test.support.import_helper import (
forget, make_legacy_pyc, unlink, unload, ready_to_import,
Expand Down Expand Up @@ -408,11 +408,6 @@ def test_case_sensitivity(self):
with self.assertRaises(ImportError):
import RAnDoM

def test_double_const(self):
# Another brief digression to test the accuracy of manifest float
# constants.
from test import double_const # don't blink -- that *was* the test

def test_import(self):
def test_with_extension(ext):
# The extension is normally ".py", perhaps ".pyw".
Expand Down Expand Up @@ -877,6 +872,33 @@ def test_pyc_always_writable(self):
m = __import__(name)
self.assertEqual(m.x, 'rewritten')

def test_double_const(self):
sobolevn marked this conversation as resolved.
Show resolved Hide resolved
# Importing double_const checks that float constants
# serialiazed by marshal as PYC files don't lose precision
# (SF bug 422177).
filepath = os.path.join(
TEST_HOME_DIR,
'test_import',
'data',
'double_const.py',
)

with open(filepath, 'r', encoding='utf8') as f:
source = f.read()

with ready_to_import(source=source) as (name, path):
# Initial import should be fine:
__import__(name)

# Now, delete source file, only keep `.pyc` file and import again:
unlink(path)
unload(name)
importlib.invalidate_caches()

bytecode_only = path + 'c'
os.rename(importlib.util.cache_from_source(path), bytecode_only)
__import__(name)
sobolevn marked this conversation as resolved.
Show resolved Hide resolved


class PycRewritingTests(unittest.TestCase):
# Test that the `co_filename` attribute on code objects always points
Expand Down
File renamed without changes.
Loading