(self)
| 97 | del sys.modules[pkg] |
| 98 | |
| 99 | def test_issue44061_iter_modules(self): |
| 100 | #see: issue44061 |
| 101 | zip = 'test_getdata_zipfile.zip' |
| 102 | pkg = 'test_getdata_zipfile' |
| 103 | |
| 104 | # Include a LF and a CRLF, to test that binary data is read back |
| 105 | RESOURCE_DATA = b'Hello, world!\nSecond line\r\nThird line' |
| 106 | |
| 107 | # Make a package with some resources |
| 108 | zip_file = os.path.join(self.dirname, zip) |
| 109 | z = zipfile.ZipFile(zip_file, 'w') |
| 110 | |
| 111 | # Empty init.py |
| 112 | z.writestr(pkg + '/__init__.py', "") |
| 113 | # Resource files, res.txt |
| 114 | z.writestr(pkg + '/res.txt', RESOURCE_DATA) |
| 115 | z.close() |
| 116 | |
| 117 | # Check we can read the resources |
| 118 | sys.path.insert(0, zip_file) |
| 119 | try: |
| 120 | res = pkgutil.get_data(pkg, 'res.txt') |
| 121 | self.assertEqual(res, RESOURCE_DATA) |
| 122 | |
| 123 | # make sure iter_modules accepts Path objects |
| 124 | names = [] |
| 125 | for moduleinfo in pkgutil.iter_modules([FakePath(zip_file)]): |
| 126 | self.assertIsInstance(moduleinfo, pkgutil.ModuleInfo) |
| 127 | names.append(moduleinfo.name) |
| 128 | self.assertEqual(names, [pkg]) |
| 129 | finally: |
| 130 | del sys.path[0] |
| 131 | sys.modules.pop(pkg, None) |
| 132 | |
| 133 | # assert path must be None or list of paths |
| 134 | expected_msg = "path must be None or list of paths to look for modules in" |
| 135 | with self.assertRaisesRegex(ValueError, expected_msg): |
| 136 | list(pkgutil.iter_modules("invalid_path")) |
| 137 | |
| 138 | def test_unreadable_dir_on_syspath(self): |
| 139 | # issue7367 - walk_packages failed if unreadable dir on sys.path |
nothing calls this directly
no test coverage detected