OLD | NEW |
(Empty) | |
| 1 |
| 2 import distutils.core |
| 3 import os |
| 4 import sys |
| 5 import tempfile |
| 6 import shutil |
| 7 import stat |
| 8 import unittest |
| 9 |
| 10 import pkg_resources |
| 11 import warnings |
| 12 from setuptools.command import egg_info |
| 13 from setuptools import svn_utils |
| 14 from setuptools.tests import environment, test_svn |
| 15 from setuptools.tests.py26compat import skipIf |
| 16 |
| 17 ENTRIES_V10 = pkg_resources.resource_string(__name__, 'entries-v10') |
| 18 "An entries file generated with svn 1.6.17 against the legacy Setuptools repo" |
| 19 |
| 20 |
| 21 class TestEggInfo(unittest.TestCase): |
| 22 |
| 23 def setUp(self): |
| 24 self.test_dir = tempfile.mkdtemp() |
| 25 os.mkdir(os.path.join(self.test_dir, '.svn')) |
| 26 |
| 27 self.old_cwd = os.getcwd() |
| 28 os.chdir(self.test_dir) |
| 29 |
| 30 def tearDown(self): |
| 31 os.chdir(self.old_cwd) |
| 32 shutil.rmtree(self.test_dir) |
| 33 |
| 34 def _write_entries(self, entries): |
| 35 fn = os.path.join(self.test_dir, '.svn', 'entries') |
| 36 entries_f = open(fn, 'wb') |
| 37 entries_f.write(entries) |
| 38 entries_f.close() |
| 39 |
| 40 def _create_project(self): |
| 41 with open('setup.py', 'w') as f: |
| 42 f.write('from setuptools import setup\n') |
| 43 f.write('\n') |
| 44 f.write('setup(\n') |
| 45 f.write(" name='foo',\n") |
| 46 f.write(" py_modules=['hello'],\n") |
| 47 f.write(" entry_points={'console_scripts': ['hi = hello.run']},\n
") |
| 48 f.write(' zip_safe=False,\n') |
| 49 f.write(' )\n') |
| 50 with open('hello.py', 'w') as f: |
| 51 f.write('def run():\n') |
| 52 f.write(" print('hello')\n") |
| 53 |
| 54 @skipIf(not test_svn._svn_check, "No SVN to text, in the first place") |
| 55 def test_version_10_format(self): |
| 56 """ |
| 57 """ |
| 58 #keeping this set for 1.6 is a good check on the get_svn_revision |
| 59 #to ensure I return using svnversion what would had been returned |
| 60 version_str = svn_utils.SvnInfo.get_svn_version() |
| 61 version = [int(x) for x in version_str.split('.')[:2]] |
| 62 if version != [1, 6]: |
| 63 if hasattr(self, 'skipTest'): |
| 64 self.skipTest('') |
| 65 else: |
| 66 sys.stderr.write('\n Skipping due to SVN Version\n') |
| 67 return |
| 68 |
| 69 self._write_entries(ENTRIES_V10) |
| 70 rev = egg_info.egg_info.get_svn_revision() |
| 71 self.assertEqual(rev, '89000') |
| 72 |
| 73 def test_version_10_format_legacy_parser(self): |
| 74 """ |
| 75 """ |
| 76 path_variable = None |
| 77 for env in os.environ: |
| 78 if env.lower() == 'path': |
| 79 path_variable = env |
| 80 |
| 81 if path_variable: |
| 82 old_path = os.environ[path_variable] |
| 83 os.environ[path_variable] = '' |
| 84 #catch_warnings not available until py26 |
| 85 warning_filters = warnings.filters |
| 86 warnings.filters = warning_filters[:] |
| 87 try: |
| 88 warnings.simplefilter("ignore", DeprecationWarning) |
| 89 self._write_entries(ENTRIES_V10) |
| 90 rev = egg_info.egg_info.get_svn_revision() |
| 91 finally: |
| 92 #restore the warning filters |
| 93 warnings.filters = warning_filters |
| 94 #restore the os path |
| 95 if path_variable: |
| 96 os.environ[path_variable] = old_path |
| 97 |
| 98 self.assertEqual(rev, '89000') |
| 99 |
| 100 def test_egg_base_installed_egg_info(self): |
| 101 self._create_project() |
| 102 temp_dir = tempfile.mkdtemp(prefix='setuptools-test.') |
| 103 os.chmod(temp_dir, stat.S_IRWXU) |
| 104 try: |
| 105 paths = {} |
| 106 for dirname in ['home', 'lib', 'scripts', 'data', 'egg-base']: |
| 107 paths[dirname] = os.path.join(temp_dir, dirname) |
| 108 os.mkdir(paths[dirname]) |
| 109 config = os.path.join(paths['home'], '.pydistutils.cfg') |
| 110 with open(config, 'w') as f: |
| 111 f.write('[egg_info]\n') |
| 112 f.write('egg-base = %s\n' % paths['egg-base']) |
| 113 environ = os.environ.copy() |
| 114 environ['HOME'] = paths['home'] |
| 115 code, data = environment.run_setup_py( |
| 116 cmd=[ |
| 117 'install', '--home', paths['home'], |
| 118 '--install-lib', paths['lib'], |
| 119 '--install-scripts', paths['scripts'], |
| 120 '--install-data', paths['data']], |
| 121 pypath=os.pathsep.join([paths['lib'], self.old_cwd]), |
| 122 data_stream=1, |
| 123 env=environ) |
| 124 if code: |
| 125 raise AssertionError(data) |
| 126 egg_info = None |
| 127 for dirpath, dirnames, filenames in os.walk(paths['lib']): |
| 128 if os.path.basename(dirpath) == 'EGG-INFO': |
| 129 egg_info = sorted(filenames) |
| 130 self.assertEqual( |
| 131 egg_info, |
| 132 ['PKG-INFO', |
| 133 'SOURCES.txt', |
| 134 'dependency_links.txt', |
| 135 'entry_points.txt', |
| 136 'not-zip-safe', |
| 137 'top_level.txt']) |
| 138 finally: |
| 139 shutil.rmtree(temp_dir) |
| 140 |
| 141 |
| 142 DUMMY_SOURCE_TXT = """CHANGES.txt |
| 143 CONTRIBUTORS.txt |
| 144 HISTORY.txt |
| 145 LICENSE |
| 146 MANIFEST.in |
| 147 README.txt |
| 148 setup.py |
| 149 dummy/__init__.py |
| 150 dummy/test.txt |
| 151 dummy.egg-info/PKG-INFO |
| 152 dummy.egg-info/SOURCES.txt |
| 153 dummy.egg-info/dependency_links.txt |
| 154 dummy.egg-info/top_level.txt""" |
| 155 |
| 156 |
| 157 class TestSvnDummy(environment.ZippedEnvironment): |
| 158 |
| 159 def setUp(self): |
| 160 version = svn_utils.SvnInfo.get_svn_version() |
| 161 if not version: # None or Empty |
| 162 return None |
| 163 |
| 164 self.base_version = tuple([int(x) for x in version.split('.')][:2]) |
| 165 |
| 166 if not self.base_version: |
| 167 raise ValueError('No SVN tools installed') |
| 168 elif self.base_version < (1, 3): |
| 169 raise ValueError('Insufficient SVN Version %s' % version) |
| 170 elif self.base_version >= (1, 9): |
| 171 #trying the latest version |
| 172 self.base_version = (1, 8) |
| 173 |
| 174 self.dataname = "dummy%i%i" % self.base_version |
| 175 self.datafile = os.path.join('setuptools', 'tests', |
| 176 'svn_data', self.dataname + ".zip") |
| 177 super(TestSvnDummy, self).setUp() |
| 178 |
| 179 @skipIf(not test_svn._svn_check, "No SVN to text, in the first place") |
| 180 def test_sources(self): |
| 181 code, data = environment.run_setup_py(["sdist"], |
| 182 pypath=self.old_cwd, |
| 183 data_stream=1) |
| 184 if code: |
| 185 raise AssertionError(data) |
| 186 |
| 187 sources = os.path.join('dummy.egg-info', 'SOURCES.txt') |
| 188 infile = open(sources, 'r') |
| 189 try: |
| 190 read_contents = infile.read() |
| 191 finally: |
| 192 infile.close() |
| 193 del infile |
| 194 |
| 195 self.assertEqual(DUMMY_SOURCE_TXT, read_contents) |
| 196 |
| 197 return data |
| 198 |
| 199 @skipIf(not test_svn._svn_check, "No SVN to text, in the first place") |
| 200 def test_svn_tags(self): |
| 201 code, data = environment.run_setup_py(["egg_info", |
| 202 "--tag-svn-revision"], |
| 203 pypath=self.old_cwd, |
| 204 data_stream=1) |
| 205 if code: |
| 206 raise AssertionError(data) |
| 207 |
| 208 pkginfo = os.path.join('dummy.egg-info', 'PKG-INFO') |
| 209 infile = open(pkginfo, 'r') |
| 210 try: |
| 211 read_contents = infile.readlines() |
| 212 finally: |
| 213 infile.close() |
| 214 del infile |
| 215 |
| 216 self.assertTrue("Version: 0.1.1.post1\n" in read_contents) |
| 217 |
| 218 @skipIf(not test_svn._svn_check, "No SVN to text, in the first place") |
| 219 def test_no_tags(self): |
| 220 code, data = environment.run_setup_py(["egg_info"], |
| 221 pypath=self.old_cwd, |
| 222 data_stream=1) |
| 223 if code: |
| 224 raise AssertionError(data) |
| 225 |
| 226 pkginfo = os.path.join('dummy.egg-info', 'PKG-INFO') |
| 227 infile = open(pkginfo, 'r') |
| 228 try: |
| 229 read_contents = infile.readlines() |
| 230 finally: |
| 231 infile.close() |
| 232 del infile |
| 233 |
| 234 self.assertTrue("Version: 0.1.1\n" in read_contents) |
| 235 |
| 236 |
| 237 class TestSvnDummyLegacy(environment.ZippedEnvironment): |
| 238 |
| 239 def setUp(self): |
| 240 self.base_version = (1, 6) |
| 241 self.dataname = "dummy%i%i" % self.base_version |
| 242 self.datafile = os.path.join('setuptools', 'tests', |
| 243 'svn_data', self.dataname + ".zip") |
| 244 super(TestSvnDummyLegacy, self).setUp() |
| 245 |
| 246 def test_sources(self): |
| 247 code, data = environment.run_setup_py(["sdist"], |
| 248 pypath=self.old_cwd, |
| 249 path="", |
| 250 data_stream=1) |
| 251 if code: |
| 252 raise AssertionError(data) |
| 253 |
| 254 sources = os.path.join('dummy.egg-info', 'SOURCES.txt') |
| 255 infile = open(sources, 'r') |
| 256 try: |
| 257 read_contents = infile.read() |
| 258 finally: |
| 259 infile.close() |
| 260 del infile |
| 261 |
| 262 self.assertEqual(DUMMY_SOURCE_TXT, read_contents) |
| 263 |
| 264 return data |
| 265 |
| 266 |
| 267 def test_suite(): |
| 268 return unittest.defaultTestLoader.loadTestsFromName(__name__) |
OLD | NEW |