11"""Tests for distutils.command.sdist."""
22import os
3+ import tarfile
34import unittest
4- import shutil
5+ import warnings
56import zipfile
67from os .path import join
7- import sys
8- import tempfile
9- import warnings
8+ from textwrap import dedent
109
1110from test .support import captured_stdout , check_warnings , run_unittest
1211
1312from distutils .command .sdist import sdist , show_formats
1413from distutils .core import Distribution
1514from distutils .tests .test_config import PyPIRCCommandTestCase
16- from distutils .errors import DistutilsExecError , DistutilsOptionError
15+ from distutils .errors import DistutilsOptionError
1716from distutils .spawn import find_executable
18- from distutils .tests import support
1917from distutils .log import WARN
2018from distutils .archive_util import ARCHIVE_FORMATS
2119
@@ -346,13 +344,33 @@ def test_manifest_marker(self):
346344 self .assertEqual (manifest [0 ],
347345 '# file GENERATED by distutils, do NOT edit' )
348346
347+ @unittest .skipUnless (ZLIB_SUPPORT , "Need zlib support to run" )
348+ def test_manifest_comments (self ):
349+ # make sure comments don't cause exceptions or wrong includes
350+ contents = dedent ("""\
351+ # bad.py
352+ #bad.py
353+ good.py
354+ """ )
355+ dist , cmd = self .get_cmd ()
356+ cmd .ensure_finalized ()
357+ self .write_file ((self .tmp_dir , cmd .manifest ), contents )
358+ self .write_file ((self .tmp_dir , 'good.py' ), '# pick me!' )
359+ self .write_file ((self .tmp_dir , 'bad.py' ), "# don't pick me!" )
360+ self .write_file ((self .tmp_dir , '#bad.py' ), "# don't pick me!" )
361+ cmd .run ()
362+ self .assertEqual (cmd .filelist .files , ['good.py' ])
363+
349364 @unittest .skipUnless (ZLIB_SUPPORT , 'Need zlib support to run' )
350365 def test_manual_manifest (self ):
351366 # check that a MANIFEST without a marker is left alone
352367 dist , cmd = self .get_cmd ()
353368 cmd .ensure_finalized ()
354369 self .write_file ((self .tmp_dir , cmd .manifest ), 'README.manual' )
370+ self .write_file ((self .tmp_dir , 'README.manual' ),
371+ 'This project maintains its MANIFEST file itself.' )
355372 cmd .run ()
373+ self .assertEqual (cmd .filelist .files , ['README.manual' ])
356374
357375 f = open (cmd .manifest )
358376 try :
@@ -363,6 +381,15 @@ def test_manual_manifest(self):
363381
364382 self .assertEqual (manifest , ['README.manual' ])
365383
384+ archive_name = join (self .tmp_dir , 'dist' , 'fake-1.0.tar.gz' )
385+ archive = tarfile .open (archive_name )
386+ try :
387+ filenames = [tarinfo .name for tarinfo in archive ]
388+ finally :
389+ archive .close ()
390+ self .assertEqual (sorted (filenames ), ['fake-1.0' , 'fake-1.0/PKG-INFO' ,
391+ 'fake-1.0/README.manual' ])
392+
366393def test_suite ():
367394 return unittest .makeSuite (SDistTestCase )
368395
0 commit comments