| 33 | del sys.path[0] |
| 34 | |
| 35 | def test_getdata_filesys(self): |
| 36 | pkg = 'test_getdata_filesys' |
| 37 | |
| 38 | # Include a LF and a CRLF, to test that binary data is read back |
| 39 | RESOURCE_DATA = b'Hello, world!\nSecond line\r\nThird line' |
| 40 | |
| 41 | # Make a package with some resources |
| 42 | package_dir = os.path.join(self.dirname, pkg) |
| 43 | os.mkdir(package_dir) |
| 44 | # Empty init.py |
| 45 | f = open(os.path.join(package_dir, '__init__.py'), "wb") |
| 46 | f.close() |
| 47 | # Resource files, res.txt, sub/res.txt |
| 48 | f = open(os.path.join(package_dir, 'res.txt'), "wb") |
| 49 | f.write(RESOURCE_DATA) |
| 50 | f.close() |
| 51 | os.mkdir(os.path.join(package_dir, 'sub')) |
| 52 | f = open(os.path.join(package_dir, 'sub', 'res.txt'), "wb") |
| 53 | f.write(RESOURCE_DATA) |
| 54 | f.close() |
| 55 | |
| 56 | # Check we can read the resources |
| 57 | res1 = pkgutil.get_data(pkg, 'res.txt') |
| 58 | self.assertEqual(res1, RESOURCE_DATA) |
| 59 | res2 = pkgutil.get_data(pkg, 'sub/res.txt') |
| 60 | self.assertEqual(res2, RESOURCE_DATA) |
| 61 | |
| 62 | del sys.modules[pkg] |
| 63 | |
| 64 | def test_getdata_zipfile(self): |
| 65 | zip = 'test_getdata_zipfile.zip' |