Skip to content

Commit 3857258

Browse files
committed
Backport the test capturing the behavior selectively.
1 parent c6dfba2 commit 3857258

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

Lib/test/test_importlib/resources/test_files.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,42 @@ def test_implicit_files(self):
108108
_path.build(spec, self.site_dir)
109109
assert importlib.import_module('somepkg').val == 'resources are the best'
110110

111+
def test_implicit_files_zip_submodule(self):
112+
"""
113+
Special test for gh-121735 for Python 3.12.
114+
"""
115+
import os
116+
import zipfile
117+
118+
def create_zip_from_directory(source_dir, zip_filename):
119+
with zipfile.ZipFile(zip_filename, 'w') as zipf:
120+
for root, _, files in os.walk(source_dir):
121+
for file in files:
122+
file_path = os.path.join(root, file)
123+
# Ensure files are at the root
124+
arcname = os.path.relpath(file_path, source_dir)
125+
zipf.write(file_path, arcname)
126+
127+
set_val = textwrap.dedent(
128+
"""
129+
import importlib.resources as res
130+
val = res.files().joinpath('res.txt').read_text(encoding='utf-8')
131+
"""
132+
)
133+
spec = {
134+
'somepkg': {
135+
'__init__.py': set_val,
136+
'submod.py': set_val,
137+
'res.txt': 'resources are the best',
138+
},
139+
}
140+
build_dir = self.fixtures.enter_context(os_helper.temp_dir())
141+
_path.build(spec, build_dir)
142+
zip_file = os.path.join(self.site_dir, 'thepkg.zip')
143+
create_zip_from_directory(build_dir, zip_file)
144+
self.fixtures.enter_context(import_helper.DirsOnSysPath(zip_file))
145+
assert importlib.import_module('somepkg.submod').val == 'resources are the best'
146+
111147

112148
if __name__ == '__main__':
113149
unittest.main()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy