@@ -93,11 +93,40 @@ def test_getdata_zipfile(self):
93
93
94
94
del sys .modules [pkg ]
95
95
96
- def test_iter_modules (self ):
96
+ def test_issue44061_iter_modules (self ):
97
97
#see: issue44061
98
- actual = list (pkgutil .iter_modules ([Path ("/home" )], 'somepackage.somesubpackage' ))
99
- self .assertListEqual ([], actual )
98
+ zip = 'test_getdata_zipfile.zip'
99
+ pkg = 'test_getdata_zipfile'
100
+
101
+ # Include a LF and a CRLF, to test that binary data is read back
102
+ RESOURCE_DATA = b'Hello, world!\n Second line\r \n Third line'
103
+
104
+ # Make a package with some resources
105
+ zip_file = os .path .join (self .dirname , zip )
106
+ z = zipfile .ZipFile (zip_file , 'w' )
107
+
108
+ # Empty init.py
109
+ z .writestr (pkg + '/__init__.py' , "" )
110
+ # Resource files, res.txt
111
+ z .writestr (pkg + '/res.txt' , RESOURCE_DATA )
112
+ z .close ()
113
+
114
+ # Check we can read the resources
115
+ sys .path .insert (0 , zip_file )
116
+ res = pkgutil .get_data (pkg , 'res.txt' )
117
+ self .assertEqual (res , RESOURCE_DATA )
118
+
119
+ # make sure iter_modules accepts Path objects
120
+ names = []
121
+ for moduleinfo in pkgutil .iter_modules ([Path (zip_file )]):
122
+ self .assertIsInstance (moduleinfo , pkgutil .ModuleInfo )
123
+ names .append (moduleinfo .name )
124
+ self .assertEqual (names , [pkg ])
125
+
126
+ del sys .path [0 ]
127
+ del sys .modules [pkg ]
100
128
129
+ # assert path must be None or list of paths
101
130
expected_msg = "path must be None or list of paths to look for modules in"
102
131
with self .assertRaisesRegex (ValueError , expected_msg ):
103
132
list (pkgutil .iter_modules ("invalid_path" ))
0 commit comments