| OLD | NEW |
| 1 """Tests for packaging.command.install_data.""" | 1 """Tests for packaging.command.install_data.""" |
| 2 import os | 2 import os |
| 3 import sys | 3 import sys |
| 4 import sysconfig | 4 import sysconfig |
| 5 import packaging.database | 5 import packaging.database |
| 6 from sysconfig import _get_default_scheme | 6 from sysconfig import _get_default_scheme |
| 7 from packaging.tests import unittest, support | 7 from packaging.tests import unittest, support |
| 8 from packaging.command.install_data import install_data | 8 from packaging.command.install_data import install_data |
| 9 from packaging.command.install_dist import install_dist | 9 from packaging.command.install_dist import install_dist |
| 10 from packaging.command.install_distinfo import install_distinfo | 10 from packaging.command.install_distinfo import install_distinfo |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 # let's check the result | 88 # let's check the result |
| 89 self.assertEqual(len(cmd.get_outputs()), 3) | 89 self.assertEqual(len(cmd.get_outputs()), 3) |
| 90 self.assertTrue(os.path.exists(os.path.join(inst2, rtwo))) | 90 self.assertTrue(os.path.exists(os.path.join(inst2, rtwo))) |
| 91 self.assertTrue(os.path.exists(os.path.join(inst, rone))) | 91 self.assertTrue(os.path.exists(os.path.join(inst, rone))) |
| 92 | 92 |
| 93 def test_resources(self): | 93 def test_resources(self): |
| 94 install_dir = self.mkdtemp() | 94 install_dir = self.mkdtemp() |
| 95 scripts_dir = self.mkdtemp() | 95 scripts_dir = self.mkdtemp() |
| 96 project_dir, dist = self.create_dist( | 96 project_dir, dist = self.create_dist( |
| 97 name='Spamlib', version='0.1', | 97 name='Spamlib', version='0.1', |
| 98 data_files={'spamd': '{scripts}/spamd'}) | 98 data_files={'spamd': '{scripts}/spamd', |
| 99 'entry_points.txt': '{dist-info}/entry_points.txt'}) |
| 99 | 100 |
| 100 os.chdir(project_dir) | 101 os.chdir(project_dir) |
| 101 self.write_file('spamd', '# Python script') | 102 self.write_file('spamd', '# Python script') |
| 103 self.write_file('entry_points.txt', '[entry_points]\nham = eggs:cheese') |
| 102 sysconfig._SCHEMES.set(_get_default_scheme(), 'scripts', scripts_dir) | 104 sysconfig._SCHEMES.set(_get_default_scheme(), 'scripts', scripts_dir) |
| 103 sys.path.insert(0, install_dir) | 105 sys.path.insert(0, install_dir) |
| 104 packaging.database.disable_cache() | 106 packaging.database.disable_cache() |
| 105 self.addCleanup(sys.path.remove, install_dir) | 107 self.addCleanup(sys.path.remove, install_dir) |
| 106 self.addCleanup(packaging.database.enable_cache) | 108 self.addCleanup(packaging.database.enable_cache) |
| 107 | 109 |
| 108 cmd = install_dist(dist) | 110 cmd = install_dist(dist) |
| 109 cmd.outputs = ['spamd'] | 111 cmd.outputs = ['spamd'] |
| 110 cmd.install_lib = install_dir | 112 cmd.install_lib = install_dir |
| 111 dist.command_obj['install_dist'] = cmd | 113 dist.command_obj['install_dist'] = cmd |
| 112 | 114 |
| 113 cmd = install_data(dist) | 115 cmd = install_data(dist) |
| 114 cmd.install_dir = install_dir | 116 cmd.install_dir = install_dir |
| 115 cmd.ensure_finalized() | 117 cmd.ensure_finalized() |
| 116 dist.command_obj['install_data'] = cmd | 118 dist.command_obj['install_data'] = cmd |
| 117 cmd.run() | 119 cmd.run() |
| 118 | 120 |
| 119 cmd = install_distinfo(dist) | 121 cmd = install_distinfo(dist) |
| 120 cmd.ensure_finalized() | 122 cmd.ensure_finalized() |
| 121 dist.command_obj['install_distinfo'] = cmd | 123 dist.command_obj['install_distinfo'] = cmd |
| 122 cmd.run() | 124 cmd.run() |
| 123 | 125 |
| 124 # first a few sanity checks | 126 # first a few sanity checks |
| 125 self.assertEqual(os.listdir(scripts_dir), ['spamd']) | 127 self.assertEqual(os.listdir(scripts_dir), ['spamd']) |
| 126 self.assertEqual(os.listdir(install_dir), ['Spamlib-0.1.dist-info']) | 128 self.assertEqual(os.listdir(install_dir), ['Spamlib-0.1.dist-info'])
|
| 127 | 129 |
| 128 # now the real test | 130 # now the real test |
| 129 fn = os.path.join(install_dir, 'Spamlib-0.1.dist-info', 'RESOURCES') | 131 fn = os.path.join(install_dir, 'Spamlib-0.1.dist-info', 'RESOURCES') |
| 130 with open(fn, encoding='utf-8') as fp: | 132 with open(fn, encoding='utf-8') as fp: |
| 131 content = fp.read().strip() | 133 content = fp.read().strip() |
| 132 | 134 |
| 133 expected = 'spamd,%s' % os.path.join(scripts_dir, 'spamd') | 135 expected = 'spamd,%s\nentry_points.txt,%s' % (os.path.join(scripts_dir,
'spamd'), |
| 136 os.path.join(install_dir, |
| 137 'Spamlib-0.1.
dist-info', |
| 138 'entry_points
.txt')) |
| 134 self.assertEqual(content, expected) | 139 self.assertEqual(content, expected) |
| 135 | 140 |
| 136 # just to be sure, we also test that get_file works here, even though | 141 # just to be sure, we also test that get_file works here, even though |
| 137 # packaging.database has its own test file | 142 # packaging.database has its own test file |
| 138 with packaging.database.get_file('Spamlib', 'spamd') as fp: | 143 with packaging.database.get_file('Spamlib', 'spamd') as fp: |
| 139 content = fp.read() | 144 content = fp.read() |
| 140 | 145 |
| 141 self.assertEqual('# Python script', content) | 146 self.assertEqual('# Python script', content) |
| 142 | 147 |
| 143 | 148 |
| 144 def test_suite(): | 149 def test_suite(): |
| 145 return unittest.makeSuite(InstallDataTestCase) | 150 return unittest.makeSuite(InstallDataTestCase) |
| 146 | 151 |
| 147 if __name__ == "__main__": | 152 if __name__ == "__main__": |
| 148 unittest.main(defaultTest="test_suite") | 153 unittest.main(defaultTest="test_suite") |
| OLD | NEW |