@@ -108,6 +108,42 @@ def test_implicit_files(self):
108
108
_path .build (spec , self .site_dir )
109
109
assert importlib .import_module ('somepkg' ).val == 'resources are the best'
110
110
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
+
111
147
112
148
if __name__ == '__main__' :
113
149
unittest .main ()
0 commit comments