| 1 | n/a | """Tests for distutils.command.sdist.""" |
|---|
| 2 | n/a | import os |
|---|
| 3 | n/a | import tarfile |
|---|
| 4 | n/a | import unittest |
|---|
| 5 | n/a | import warnings |
|---|
| 6 | n/a | import zipfile |
|---|
| 7 | n/a | from os.path import join |
|---|
| 8 | n/a | from textwrap import dedent |
|---|
| 9 | n/a | from test.support import captured_stdout, check_warnings, run_unittest |
|---|
| 10 | n/a | |
|---|
| 11 | n/a | try: |
|---|
| 12 | n/a | import zlib |
|---|
| 13 | n/a | ZLIB_SUPPORT = True |
|---|
| 14 | n/a | except ImportError: |
|---|
| 15 | n/a | ZLIB_SUPPORT = False |
|---|
| 16 | n/a | |
|---|
| 17 | n/a | try: |
|---|
| 18 | n/a | import grp |
|---|
| 19 | n/a | import pwd |
|---|
| 20 | n/a | UID_GID_SUPPORT = True |
|---|
| 21 | n/a | except ImportError: |
|---|
| 22 | n/a | UID_GID_SUPPORT = False |
|---|
| 23 | n/a | |
|---|
| 24 | n/a | from distutils.command.sdist import sdist, show_formats |
|---|
| 25 | n/a | from distutils.core import Distribution |
|---|
| 26 | n/a | from distutils.tests.test_config import BasePyPIRCCommandTestCase |
|---|
| 27 | n/a | from distutils.errors import DistutilsOptionError |
|---|
| 28 | n/a | from distutils.spawn import find_executable |
|---|
| 29 | n/a | from distutils.log import WARN |
|---|
| 30 | n/a | from distutils.filelist import FileList |
|---|
| 31 | n/a | from distutils.archive_util import ARCHIVE_FORMATS |
|---|
| 32 | n/a | |
|---|
| 33 | n/a | SETUP_PY = """ |
|---|
| 34 | n/a | from distutils.core import setup |
|---|
| 35 | n/a | import somecode |
|---|
| 36 | n/a | |
|---|
| 37 | n/a | setup(name='fake') |
|---|
| 38 | n/a | """ |
|---|
| 39 | n/a | |
|---|
| 40 | n/a | MANIFEST = """\ |
|---|
| 41 | n/a | # file GENERATED by distutils, do NOT edit |
|---|
| 42 | n/a | README |
|---|
| 43 | n/a | buildout.cfg |
|---|
| 44 | n/a | inroot.txt |
|---|
| 45 | n/a | setup.py |
|---|
| 46 | n/a | data%(sep)sdata.dt |
|---|
| 47 | n/a | scripts%(sep)sscript.py |
|---|
| 48 | n/a | some%(sep)sfile.txt |
|---|
| 49 | n/a | some%(sep)sother_file.txt |
|---|
| 50 | n/a | somecode%(sep)s__init__.py |
|---|
| 51 | n/a | somecode%(sep)sdoc.dat |
|---|
| 52 | n/a | somecode%(sep)sdoc.txt |
|---|
| 53 | n/a | """ |
|---|
| 54 | n/a | |
|---|
| 55 | n/a | class SDistTestCase(BasePyPIRCCommandTestCase): |
|---|
| 56 | n/a | |
|---|
| 57 | n/a | def setUp(self): |
|---|
| 58 | n/a | # PyPIRCCommandTestCase creates a temp dir already |
|---|
| 59 | n/a | # and put it in self.tmp_dir |
|---|
| 60 | n/a | super(SDistTestCase, self).setUp() |
|---|
| 61 | n/a | # setting up an environment |
|---|
| 62 | n/a | self.old_path = os.getcwd() |
|---|
| 63 | n/a | os.mkdir(join(self.tmp_dir, 'somecode')) |
|---|
| 64 | n/a | os.mkdir(join(self.tmp_dir, 'dist')) |
|---|
| 65 | n/a | # a package, and a README |
|---|
| 66 | n/a | self.write_file((self.tmp_dir, 'README'), 'xxx') |
|---|
| 67 | n/a | self.write_file((self.tmp_dir, 'somecode', '__init__.py'), '#') |
|---|
| 68 | n/a | self.write_file((self.tmp_dir, 'setup.py'), SETUP_PY) |
|---|
| 69 | n/a | os.chdir(self.tmp_dir) |
|---|
| 70 | n/a | |
|---|
| 71 | n/a | def tearDown(self): |
|---|
| 72 | n/a | # back to normal |
|---|
| 73 | n/a | os.chdir(self.old_path) |
|---|
| 74 | n/a | super(SDistTestCase, self).tearDown() |
|---|
| 75 | n/a | |
|---|
| 76 | n/a | def get_cmd(self, metadata=None): |
|---|
| 77 | n/a | """Returns a cmd""" |
|---|
| 78 | n/a | if metadata is None: |
|---|
| 79 | n/a | metadata = {'name': 'fake', 'version': '1.0', |
|---|
| 80 | n/a | 'url': 'xxx', 'author': 'xxx', |
|---|
| 81 | n/a | 'author_email': 'xxx'} |
|---|
| 82 | n/a | dist = Distribution(metadata) |
|---|
| 83 | n/a | dist.script_name = 'setup.py' |
|---|
| 84 | n/a | dist.packages = ['somecode'] |
|---|
| 85 | n/a | dist.include_package_data = True |
|---|
| 86 | n/a | cmd = sdist(dist) |
|---|
| 87 | n/a | cmd.dist_dir = 'dist' |
|---|
| 88 | n/a | return dist, cmd |
|---|
| 89 | n/a | |
|---|
| 90 | n/a | @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run') |
|---|
| 91 | n/a | def test_prune_file_list(self): |
|---|
| 92 | n/a | # this test creates a project with some VCS dirs and an NFS rename |
|---|
| 93 | n/a | # file, then launches sdist to check they get pruned on all systems |
|---|
| 94 | n/a | |
|---|
| 95 | n/a | # creating VCS directories with some files in them |
|---|
| 96 | n/a | os.mkdir(join(self.tmp_dir, 'somecode', '.svn')) |
|---|
| 97 | n/a | self.write_file((self.tmp_dir, 'somecode', '.svn', 'ok.py'), 'xxx') |
|---|
| 98 | n/a | |
|---|
| 99 | n/a | os.mkdir(join(self.tmp_dir, 'somecode', '.hg')) |
|---|
| 100 | n/a | self.write_file((self.tmp_dir, 'somecode', '.hg', |
|---|
| 101 | n/a | 'ok'), 'xxx') |
|---|
| 102 | n/a | |
|---|
| 103 | n/a | os.mkdir(join(self.tmp_dir, 'somecode', '.git')) |
|---|
| 104 | n/a | self.write_file((self.tmp_dir, 'somecode', '.git', |
|---|
| 105 | n/a | 'ok'), 'xxx') |
|---|
| 106 | n/a | |
|---|
| 107 | n/a | self.write_file((self.tmp_dir, 'somecode', '.nfs0001'), 'xxx') |
|---|
| 108 | n/a | |
|---|
| 109 | n/a | # now building a sdist |
|---|
| 110 | n/a | dist, cmd = self.get_cmd() |
|---|
| 111 | n/a | |
|---|
| 112 | n/a | # zip is available universally |
|---|
| 113 | n/a | # (tar might not be installed under win32) |
|---|
| 114 | n/a | cmd.formats = ['zip'] |
|---|
| 115 | n/a | |
|---|
| 116 | n/a | cmd.ensure_finalized() |
|---|
| 117 | n/a | cmd.run() |
|---|
| 118 | n/a | |
|---|
| 119 | n/a | # now let's check what we have |
|---|
| 120 | n/a | dist_folder = join(self.tmp_dir, 'dist') |
|---|
| 121 | n/a | files = os.listdir(dist_folder) |
|---|
| 122 | n/a | self.assertEqual(files, ['fake-1.0.zip']) |
|---|
| 123 | n/a | |
|---|
| 124 | n/a | zip_file = zipfile.ZipFile(join(dist_folder, 'fake-1.0.zip')) |
|---|
| 125 | n/a | try: |
|---|
| 126 | n/a | content = zip_file.namelist() |
|---|
| 127 | n/a | finally: |
|---|
| 128 | n/a | zip_file.close() |
|---|
| 129 | n/a | |
|---|
| 130 | n/a | # making sure everything has been pruned correctly |
|---|
| 131 | n/a | self.assertEqual(len(content), 4) |
|---|
| 132 | n/a | |
|---|
| 133 | n/a | @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run') |
|---|
| 134 | n/a | @unittest.skipIf(find_executable('tar') is None, |
|---|
| 135 | n/a | "The tar command is not found") |
|---|
| 136 | n/a | @unittest.skipIf(find_executable('gzip') is None, |
|---|
| 137 | n/a | "The gzip command is not found") |
|---|
| 138 | n/a | def test_make_distribution(self): |
|---|
| 139 | n/a | # now building a sdist |
|---|
| 140 | n/a | dist, cmd = self.get_cmd() |
|---|
| 141 | n/a | |
|---|
| 142 | n/a | # creating a gztar then a tar |
|---|
| 143 | n/a | cmd.formats = ['gztar', 'tar'] |
|---|
| 144 | n/a | cmd.ensure_finalized() |
|---|
| 145 | n/a | cmd.run() |
|---|
| 146 | n/a | |
|---|
| 147 | n/a | # making sure we have two files |
|---|
| 148 | n/a | dist_folder = join(self.tmp_dir, 'dist') |
|---|
| 149 | n/a | result = os.listdir(dist_folder) |
|---|
| 150 | n/a | result.sort() |
|---|
| 151 | n/a | self.assertEqual(result, ['fake-1.0.tar', 'fake-1.0.tar.gz']) |
|---|
| 152 | n/a | |
|---|
| 153 | n/a | os.remove(join(dist_folder, 'fake-1.0.tar')) |
|---|
| 154 | n/a | os.remove(join(dist_folder, 'fake-1.0.tar.gz')) |
|---|
| 155 | n/a | |
|---|
| 156 | n/a | # now trying a tar then a gztar |
|---|
| 157 | n/a | cmd.formats = ['tar', 'gztar'] |
|---|
| 158 | n/a | |
|---|
| 159 | n/a | cmd.ensure_finalized() |
|---|
| 160 | n/a | cmd.run() |
|---|
| 161 | n/a | |
|---|
| 162 | n/a | result = os.listdir(dist_folder) |
|---|
| 163 | n/a | result.sort() |
|---|
| 164 | n/a | self.assertEqual(result, ['fake-1.0.tar', 'fake-1.0.tar.gz']) |
|---|
| 165 | n/a | |
|---|
| 166 | n/a | @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run') |
|---|
| 167 | n/a | def test_add_defaults(self): |
|---|
| 168 | n/a | |
|---|
| 169 | n/a | # http://bugs.python.org/issue2279 |
|---|
| 170 | n/a | |
|---|
| 171 | n/a | # add_default should also include |
|---|
| 172 | n/a | # data_files and package_data |
|---|
| 173 | n/a | dist, cmd = self.get_cmd() |
|---|
| 174 | n/a | |
|---|
| 175 | n/a | # filling data_files by pointing files |
|---|
| 176 | n/a | # in package_data |
|---|
| 177 | n/a | dist.package_data = {'': ['*.cfg', '*.dat'], |
|---|
| 178 | n/a | 'somecode': ['*.txt']} |
|---|
| 179 | n/a | self.write_file((self.tmp_dir, 'somecode', 'doc.txt'), '#') |
|---|
| 180 | n/a | self.write_file((self.tmp_dir, 'somecode', 'doc.dat'), '#') |
|---|
| 181 | n/a | |
|---|
| 182 | n/a | # adding some data in data_files |
|---|
| 183 | n/a | data_dir = join(self.tmp_dir, 'data') |
|---|
| 184 | n/a | os.mkdir(data_dir) |
|---|
| 185 | n/a | self.write_file((data_dir, 'data.dt'), '#') |
|---|
| 186 | n/a | some_dir = join(self.tmp_dir, 'some') |
|---|
| 187 | n/a | os.mkdir(some_dir) |
|---|
| 188 | n/a | # make sure VCS directories are pruned (#14004) |
|---|
| 189 | n/a | hg_dir = join(self.tmp_dir, '.hg') |
|---|
| 190 | n/a | os.mkdir(hg_dir) |
|---|
| 191 | n/a | self.write_file((hg_dir, 'last-message.txt'), '#') |
|---|
| 192 | n/a | # a buggy regex used to prevent this from working on windows (#6884) |
|---|
| 193 | n/a | self.write_file((self.tmp_dir, 'buildout.cfg'), '#') |
|---|
| 194 | n/a | self.write_file((self.tmp_dir, 'inroot.txt'), '#') |
|---|
| 195 | n/a | self.write_file((some_dir, 'file.txt'), '#') |
|---|
| 196 | n/a | self.write_file((some_dir, 'other_file.txt'), '#') |
|---|
| 197 | n/a | |
|---|
| 198 | n/a | dist.data_files = [('data', ['data/data.dt', |
|---|
| 199 | n/a | 'buildout.cfg', |
|---|
| 200 | n/a | 'inroot.txt', |
|---|
| 201 | n/a | 'notexisting']), |
|---|
| 202 | n/a | 'some/file.txt', |
|---|
| 203 | n/a | 'some/other_file.txt'] |
|---|
| 204 | n/a | |
|---|
| 205 | n/a | # adding a script |
|---|
| 206 | n/a | script_dir = join(self.tmp_dir, 'scripts') |
|---|
| 207 | n/a | os.mkdir(script_dir) |
|---|
| 208 | n/a | self.write_file((script_dir, 'script.py'), '#') |
|---|
| 209 | n/a | dist.scripts = [join('scripts', 'script.py')] |
|---|
| 210 | n/a | |
|---|
| 211 | n/a | cmd.formats = ['zip'] |
|---|
| 212 | n/a | cmd.use_defaults = True |
|---|
| 213 | n/a | |
|---|
| 214 | n/a | cmd.ensure_finalized() |
|---|
| 215 | n/a | cmd.run() |
|---|
| 216 | n/a | |
|---|
| 217 | n/a | # now let's check what we have |
|---|
| 218 | n/a | dist_folder = join(self.tmp_dir, 'dist') |
|---|
| 219 | n/a | files = os.listdir(dist_folder) |
|---|
| 220 | n/a | self.assertEqual(files, ['fake-1.0.zip']) |
|---|
| 221 | n/a | |
|---|
| 222 | n/a | zip_file = zipfile.ZipFile(join(dist_folder, 'fake-1.0.zip')) |
|---|
| 223 | n/a | try: |
|---|
| 224 | n/a | content = zip_file.namelist() |
|---|
| 225 | n/a | finally: |
|---|
| 226 | n/a | zip_file.close() |
|---|
| 227 | n/a | |
|---|
| 228 | n/a | # making sure everything was added |
|---|
| 229 | n/a | self.assertEqual(len(content), 12) |
|---|
| 230 | n/a | |
|---|
| 231 | n/a | # checking the MANIFEST |
|---|
| 232 | n/a | f = open(join(self.tmp_dir, 'MANIFEST')) |
|---|
| 233 | n/a | try: |
|---|
| 234 | n/a | manifest = f.read() |
|---|
| 235 | n/a | finally: |
|---|
| 236 | n/a | f.close() |
|---|
| 237 | n/a | self.assertEqual(manifest, MANIFEST % {'sep': os.sep}) |
|---|
| 238 | n/a | |
|---|
| 239 | n/a | @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run') |
|---|
| 240 | n/a | def test_metadata_check_option(self): |
|---|
| 241 | n/a | # testing the `medata-check` option |
|---|
| 242 | n/a | dist, cmd = self.get_cmd(metadata={}) |
|---|
| 243 | n/a | |
|---|
| 244 | n/a | # this should raise some warnings ! |
|---|
| 245 | n/a | # with the `check` subcommand |
|---|
| 246 | n/a | cmd.ensure_finalized() |
|---|
| 247 | n/a | cmd.run() |
|---|
| 248 | n/a | warnings = [msg for msg in self.get_logs(WARN) if |
|---|
| 249 | n/a | msg.startswith('warning: check:')] |
|---|
| 250 | n/a | self.assertEqual(len(warnings), 2) |
|---|
| 251 | n/a | |
|---|
| 252 | n/a | # trying with a complete set of metadata |
|---|
| 253 | n/a | self.clear_logs() |
|---|
| 254 | n/a | dist, cmd = self.get_cmd() |
|---|
| 255 | n/a | cmd.ensure_finalized() |
|---|
| 256 | n/a | cmd.metadata_check = 0 |
|---|
| 257 | n/a | cmd.run() |
|---|
| 258 | n/a | warnings = [msg for msg in self.get_logs(WARN) if |
|---|
| 259 | n/a | msg.startswith('warning: check:')] |
|---|
| 260 | n/a | self.assertEqual(len(warnings), 0) |
|---|
| 261 | n/a | |
|---|
| 262 | n/a | def test_check_metadata_deprecated(self): |
|---|
| 263 | n/a | # makes sure make_metadata is deprecated |
|---|
| 264 | n/a | dist, cmd = self.get_cmd() |
|---|
| 265 | n/a | with check_warnings() as w: |
|---|
| 266 | n/a | warnings.simplefilter("always") |
|---|
| 267 | n/a | cmd.check_metadata() |
|---|
| 268 | n/a | self.assertEqual(len(w.warnings), 1) |
|---|
| 269 | n/a | |
|---|
| 270 | n/a | def test_show_formats(self): |
|---|
| 271 | n/a | with captured_stdout() as stdout: |
|---|
| 272 | n/a | show_formats() |
|---|
| 273 | n/a | |
|---|
| 274 | n/a | # the output should be a header line + one line per format |
|---|
| 275 | n/a | num_formats = len(ARCHIVE_FORMATS.keys()) |
|---|
| 276 | n/a | output = [line for line in stdout.getvalue().split('\n') |
|---|
| 277 | n/a | if line.strip().startswith('--formats=')] |
|---|
| 278 | n/a | self.assertEqual(len(output), num_formats) |
|---|
| 279 | n/a | |
|---|
| 280 | n/a | def test_finalize_options(self): |
|---|
| 281 | n/a | dist, cmd = self.get_cmd() |
|---|
| 282 | n/a | cmd.finalize_options() |
|---|
| 283 | n/a | |
|---|
| 284 | n/a | # default options set by finalize |
|---|
| 285 | n/a | self.assertEqual(cmd.manifest, 'MANIFEST') |
|---|
| 286 | n/a | self.assertEqual(cmd.template, 'MANIFEST.in') |
|---|
| 287 | n/a | self.assertEqual(cmd.dist_dir, 'dist') |
|---|
| 288 | n/a | |
|---|
| 289 | n/a | # formats has to be a string splitable on (' ', ',') or |
|---|
| 290 | n/a | # a stringlist |
|---|
| 291 | n/a | cmd.formats = 1 |
|---|
| 292 | n/a | self.assertRaises(DistutilsOptionError, cmd.finalize_options) |
|---|
| 293 | n/a | cmd.formats = ['zip'] |
|---|
| 294 | n/a | cmd.finalize_options() |
|---|
| 295 | n/a | |
|---|
| 296 | n/a | # formats has to be known |
|---|
| 297 | n/a | cmd.formats = 'supazipa' |
|---|
| 298 | n/a | self.assertRaises(DistutilsOptionError, cmd.finalize_options) |
|---|
| 299 | n/a | |
|---|
| 300 | n/a | # the following tests make sure there is a nice error message instead |
|---|
| 301 | n/a | # of a traceback when parsing an invalid manifest template |
|---|
| 302 | n/a | |
|---|
| 303 | n/a | def _check_template(self, content): |
|---|
| 304 | n/a | dist, cmd = self.get_cmd() |
|---|
| 305 | n/a | os.chdir(self.tmp_dir) |
|---|
| 306 | n/a | self.write_file('MANIFEST.in', content) |
|---|
| 307 | n/a | cmd.ensure_finalized() |
|---|
| 308 | n/a | cmd.filelist = FileList() |
|---|
| 309 | n/a | cmd.read_template() |
|---|
| 310 | n/a | warnings = self.get_logs(WARN) |
|---|
| 311 | n/a | self.assertEqual(len(warnings), 1) |
|---|
| 312 | n/a | |
|---|
| 313 | n/a | def test_invalid_template_unknown_command(self): |
|---|
| 314 | n/a | self._check_template('taunt knights *') |
|---|
| 315 | n/a | |
|---|
| 316 | n/a | def test_invalid_template_wrong_arguments(self): |
|---|
| 317 | n/a | # this manifest command takes one argument |
|---|
| 318 | n/a | self._check_template('prune') |
|---|
| 319 | n/a | |
|---|
| 320 | n/a | @unittest.skipIf(os.name != 'nt', 'test relevant for Windows only') |
|---|
| 321 | n/a | def test_invalid_template_wrong_path(self): |
|---|
| 322 | n/a | # on Windows, trailing slashes are not allowed |
|---|
| 323 | n/a | # this used to crash instead of raising a warning: #8286 |
|---|
| 324 | n/a | self._check_template('include examples/') |
|---|
| 325 | n/a | |
|---|
| 326 | n/a | @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run') |
|---|
| 327 | n/a | def test_get_file_list(self): |
|---|
| 328 | n/a | # make sure MANIFEST is recalculated |
|---|
| 329 | n/a | dist, cmd = self.get_cmd() |
|---|
| 330 | n/a | |
|---|
| 331 | n/a | # filling data_files by pointing files in package_data |
|---|
| 332 | n/a | dist.package_data = {'somecode': ['*.txt']} |
|---|
| 333 | n/a | self.write_file((self.tmp_dir, 'somecode', 'doc.txt'), '#') |
|---|
| 334 | n/a | cmd.formats = ['gztar'] |
|---|
| 335 | n/a | cmd.ensure_finalized() |
|---|
| 336 | n/a | cmd.run() |
|---|
| 337 | n/a | |
|---|
| 338 | n/a | f = open(cmd.manifest) |
|---|
| 339 | n/a | try: |
|---|
| 340 | n/a | manifest = [line.strip() for line in f.read().split('\n') |
|---|
| 341 | n/a | if line.strip() != ''] |
|---|
| 342 | n/a | finally: |
|---|
| 343 | n/a | f.close() |
|---|
| 344 | n/a | |
|---|
| 345 | n/a | self.assertEqual(len(manifest), 5) |
|---|
| 346 | n/a | |
|---|
| 347 | n/a | # adding a file |
|---|
| 348 | n/a | self.write_file((self.tmp_dir, 'somecode', 'doc2.txt'), '#') |
|---|
| 349 | n/a | |
|---|
| 350 | n/a | # make sure build_py is reinitialized, like a fresh run |
|---|
| 351 | n/a | build_py = dist.get_command_obj('build_py') |
|---|
| 352 | n/a | build_py.finalized = False |
|---|
| 353 | n/a | build_py.ensure_finalized() |
|---|
| 354 | n/a | |
|---|
| 355 | n/a | cmd.run() |
|---|
| 356 | n/a | |
|---|
| 357 | n/a | f = open(cmd.manifest) |
|---|
| 358 | n/a | try: |
|---|
| 359 | n/a | manifest2 = [line.strip() for line in f.read().split('\n') |
|---|
| 360 | n/a | if line.strip() != ''] |
|---|
| 361 | n/a | finally: |
|---|
| 362 | n/a | f.close() |
|---|
| 363 | n/a | |
|---|
| 364 | n/a | # do we have the new file in MANIFEST ? |
|---|
| 365 | n/a | self.assertEqual(len(manifest2), 6) |
|---|
| 366 | n/a | self.assertIn('doc2.txt', manifest2[-1]) |
|---|
| 367 | n/a | |
|---|
| 368 | n/a | @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run') |
|---|
| 369 | n/a | def test_manifest_marker(self): |
|---|
| 370 | n/a | # check that autogenerated MANIFESTs have a marker |
|---|
| 371 | n/a | dist, cmd = self.get_cmd() |
|---|
| 372 | n/a | cmd.ensure_finalized() |
|---|
| 373 | n/a | cmd.run() |
|---|
| 374 | n/a | |
|---|
| 375 | n/a | f = open(cmd.manifest) |
|---|
| 376 | n/a | try: |
|---|
| 377 | n/a | manifest = [line.strip() for line in f.read().split('\n') |
|---|
| 378 | n/a | if line.strip() != ''] |
|---|
| 379 | n/a | finally: |
|---|
| 380 | n/a | f.close() |
|---|
| 381 | n/a | |
|---|
| 382 | n/a | self.assertEqual(manifest[0], |
|---|
| 383 | n/a | '# file GENERATED by distutils, do NOT edit') |
|---|
| 384 | n/a | |
|---|
| 385 | n/a | @unittest.skipUnless(ZLIB_SUPPORT, "Need zlib support to run") |
|---|
| 386 | n/a | def test_manifest_comments(self): |
|---|
| 387 | n/a | # make sure comments don't cause exceptions or wrong includes |
|---|
| 388 | n/a | contents = dedent("""\ |
|---|
| 389 | n/a | # bad.py |
|---|
| 390 | n/a | #bad.py |
|---|
| 391 | n/a | good.py |
|---|
| 392 | n/a | """) |
|---|
| 393 | n/a | dist, cmd = self.get_cmd() |
|---|
| 394 | n/a | cmd.ensure_finalized() |
|---|
| 395 | n/a | self.write_file((self.tmp_dir, cmd.manifest), contents) |
|---|
| 396 | n/a | self.write_file((self.tmp_dir, 'good.py'), '# pick me!') |
|---|
| 397 | n/a | self.write_file((self.tmp_dir, 'bad.py'), "# don't pick me!") |
|---|
| 398 | n/a | self.write_file((self.tmp_dir, '#bad.py'), "# don't pick me!") |
|---|
| 399 | n/a | cmd.run() |
|---|
| 400 | n/a | self.assertEqual(cmd.filelist.files, ['good.py']) |
|---|
| 401 | n/a | |
|---|
| 402 | n/a | @unittest.skipUnless(ZLIB_SUPPORT, 'Need zlib support to run') |
|---|
| 403 | n/a | def test_manual_manifest(self): |
|---|
| 404 | n/a | # check that a MANIFEST without a marker is left alone |
|---|
| 405 | n/a | dist, cmd = self.get_cmd() |
|---|
| 406 | n/a | cmd.formats = ['gztar'] |
|---|
| 407 | n/a | cmd.ensure_finalized() |
|---|
| 408 | n/a | self.write_file((self.tmp_dir, cmd.manifest), 'README.manual') |
|---|
| 409 | n/a | self.write_file((self.tmp_dir, 'README.manual'), |
|---|
| 410 | n/a | 'This project maintains its MANIFEST file itself.') |
|---|
| 411 | n/a | cmd.run() |
|---|
| 412 | n/a | self.assertEqual(cmd.filelist.files, ['README.manual']) |
|---|
| 413 | n/a | |
|---|
| 414 | n/a | f = open(cmd.manifest) |
|---|
| 415 | n/a | try: |
|---|
| 416 | n/a | manifest = [line.strip() for line in f.read().split('\n') |
|---|
| 417 | n/a | if line.strip() != ''] |
|---|
| 418 | n/a | finally: |
|---|
| 419 | n/a | f.close() |
|---|
| 420 | n/a | |
|---|
| 421 | n/a | self.assertEqual(manifest, ['README.manual']) |
|---|
| 422 | n/a | |
|---|
| 423 | n/a | archive_name = join(self.tmp_dir, 'dist', 'fake-1.0.tar.gz') |
|---|
| 424 | n/a | archive = tarfile.open(archive_name) |
|---|
| 425 | n/a | try: |
|---|
| 426 | n/a | filenames = [tarinfo.name for tarinfo in archive] |
|---|
| 427 | n/a | finally: |
|---|
| 428 | n/a | archive.close() |
|---|
| 429 | n/a | self.assertEqual(sorted(filenames), ['fake-1.0', 'fake-1.0/PKG-INFO', |
|---|
| 430 | n/a | 'fake-1.0/README.manual']) |
|---|
| 431 | n/a | |
|---|
| 432 | n/a | @unittest.skipUnless(ZLIB_SUPPORT, "requires zlib") |
|---|
| 433 | n/a | @unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support") |
|---|
| 434 | n/a | @unittest.skipIf(find_executable('tar') is None, |
|---|
| 435 | n/a | "The tar command is not found") |
|---|
| 436 | n/a | @unittest.skipIf(find_executable('gzip') is None, |
|---|
| 437 | n/a | "The gzip command is not found") |
|---|
| 438 | n/a | def test_make_distribution_owner_group(self): |
|---|
| 439 | n/a | # now building a sdist |
|---|
| 440 | n/a | dist, cmd = self.get_cmd() |
|---|
| 441 | n/a | |
|---|
| 442 | n/a | # creating a gztar and specifying the owner+group |
|---|
| 443 | n/a | cmd.formats = ['gztar'] |
|---|
| 444 | n/a | cmd.owner = pwd.getpwuid(0)[0] |
|---|
| 445 | n/a | cmd.group = grp.getgrgid(0)[0] |
|---|
| 446 | n/a | cmd.ensure_finalized() |
|---|
| 447 | n/a | cmd.run() |
|---|
| 448 | n/a | |
|---|
| 449 | n/a | # making sure we have the good rights |
|---|
| 450 | n/a | archive_name = join(self.tmp_dir, 'dist', 'fake-1.0.tar.gz') |
|---|
| 451 | n/a | archive = tarfile.open(archive_name) |
|---|
| 452 | n/a | try: |
|---|
| 453 | n/a | for member in archive.getmembers(): |
|---|
| 454 | n/a | self.assertEqual(member.uid, 0) |
|---|
| 455 | n/a | self.assertEqual(member.gid, 0) |
|---|
| 456 | n/a | finally: |
|---|
| 457 | n/a | archive.close() |
|---|
| 458 | n/a | |
|---|
| 459 | n/a | # building a sdist again |
|---|
| 460 | n/a | dist, cmd = self.get_cmd() |
|---|
| 461 | n/a | |
|---|
| 462 | n/a | # creating a gztar |
|---|
| 463 | n/a | cmd.formats = ['gztar'] |
|---|
| 464 | n/a | cmd.ensure_finalized() |
|---|
| 465 | n/a | cmd.run() |
|---|
| 466 | n/a | |
|---|
| 467 | n/a | # making sure we have the good rights |
|---|
| 468 | n/a | archive_name = join(self.tmp_dir, 'dist', 'fake-1.0.tar.gz') |
|---|
| 469 | n/a | archive = tarfile.open(archive_name) |
|---|
| 470 | n/a | |
|---|
| 471 | n/a | # note that we are not testing the group ownership here |
|---|
| 472 | n/a | # because, depending on the platforms and the container |
|---|
| 473 | n/a | # rights (see #7408) |
|---|
| 474 | n/a | try: |
|---|
| 475 | n/a | for member in archive.getmembers(): |
|---|
| 476 | n/a | self.assertEqual(member.uid, os.getuid()) |
|---|
| 477 | n/a | finally: |
|---|
| 478 | n/a | archive.close() |
|---|
| 479 | n/a | |
|---|
| 480 | n/a | def test_suite(): |
|---|
| 481 | n/a | return unittest.makeSuite(SDistTestCase) |
|---|
| 482 | n/a | |
|---|
| 483 | n/a | if __name__ == "__main__": |
|---|
| 484 | n/a | run_unittest(test_suite()) |
|---|