(self)
| 62 | del sys.modules[pkg] |
| 63 | |
| 64 | def test_getdata_zipfile(self): |
| 65 | zip = 'test_getdata_zipfile.zip' |
| 66 | pkg = 'test_getdata_zipfile' |
| 67 | |
| 68 | # Include a LF and a CRLF, to test that binary data is read back |
| 69 | RESOURCE_DATA = b'Hello, world!\nSecond line\r\nThird line' |
| 70 | |
| 71 | # Make a package with some resources |
| 72 | zip_file = os.path.join(self.dirname, zip) |
| 73 | z = zipfile.ZipFile(zip_file, 'w') |
| 74 | |
| 75 | # Empty init.py |
| 76 | z.writestr(pkg + '/__init__.py', "") |
| 77 | # Resource files, res.txt, sub/res.txt |
| 78 | z.writestr(pkg + '/res.txt', RESOURCE_DATA) |
| 79 | z.writestr(pkg + '/sub/res.txt', RESOURCE_DATA) |
| 80 | z.close() |
| 81 | |
| 82 | # Check we can read the resources |
| 83 | sys.path.insert(0, zip_file) |
| 84 | res1 = pkgutil.get_data(pkg, 'res.txt') |
| 85 | self.assertEqual(res1, RESOURCE_DATA) |
| 86 | res2 = pkgutil.get_data(pkg, 'sub/res.txt') |
| 87 | self.assertEqual(res2, RESOURCE_DATA) |
| 88 | |
| 89 | names = [] |
| 90 | for moduleinfo in pkgutil.iter_modules([zip_file]): |
| 91 | self.assertIsInstance(moduleinfo, pkgutil.ModuleInfo) |
| 92 | names.append(moduleinfo.name) |
| 93 | self.assertEqual(names, ['test_getdata_zipfile']) |
| 94 | |
| 95 | del sys.path[0] |
| 96 | |
| 97 | del sys.modules[pkg] |
| 98 | |
| 99 | def test_issue44061_iter_modules(self): |
| 100 | #see: issue44061 |
nothing calls this directly
no test coverage detected