1515from distutils .errors import DistutilsOptionError
1616from distutils .spawn import find_executable
1717from distutils .log import WARN
18+ from distutils .filelist import FileList
1819from distutils .archive_util import ARCHIVE_FORMATS
1920
2021SETUP_PY = """
@@ -78,9 +79,6 @@ def get_cmd(self, metadata=None):
7879 dist .include_package_data = True
7980 cmd = sdist (dist )
8081 cmd .dist_dir = 'dist'
81- def _warn (* args ):
82- pass
83- cmd .warn = _warn
8482 return dist , cmd
8583
8684 @unittest .skipUnless (ZLIB_SUPPORT , 'Need zlib support to run' )
@@ -235,7 +233,8 @@ def test_metadata_check_option(self):
235233 # with the `check` subcommand
236234 cmd .ensure_finalized ()
237235 cmd .run ()
238- warnings = self .get_logs (WARN )
236+ warnings = [msg for msg in self .get_logs (WARN ) if
237+ msg .startswith ('warning: check:' )]
239238 self .assertEqual (len (warnings ), 2 )
240239
241240 # trying with a complete set of metadata
@@ -244,7 +243,8 @@ def test_metadata_check_option(self):
244243 cmd .ensure_finalized ()
245244 cmd .metadata_check = 0
246245 cmd .run ()
247- warnings = self .get_logs (WARN )
246+ warnings = [msg for msg in self .get_logs (WARN ) if
247+ msg .startswith ('warning: check:' )]
248248 self .assertEqual (len (warnings ), 0 )
249249
250250 def test_check_metadata_deprecated (self ):
@@ -266,7 +266,6 @@ def test_show_formats(self):
266266 self .assertEqual (len (output ), num_formats )
267267
268268 def test_finalize_options (self ):
269-
270269 dist , cmd = self .get_cmd ()
271270 cmd .finalize_options ()
272271
@@ -286,6 +285,32 @@ def test_finalize_options(self):
286285 cmd .formats = 'supazipa'
287286 self .assertRaises (DistutilsOptionError , cmd .finalize_options )
288287
288+ # the following tests make sure there is a nice error message instead
289+ # of a traceback when parsing an invalid manifest template
290+
291+ def _test_template (self , content ):
292+ dist , cmd = self .get_cmd ()
293+ os .chdir (self .tmp_dir )
294+ self .write_file ('MANIFEST.in' , content )
295+ cmd .ensure_finalized ()
296+ cmd .filelist = FileList ()
297+ cmd .read_template ()
298+ warnings = self .get_logs (WARN )
299+ self .assertEqual (len (warnings ), 1 )
300+
301+ def test_invalid_template_unknown_command (self ):
302+ self ._test_template ('taunt knights *' )
303+
304+ def test_invalid_template_wrong_arguments (self ):
305+ # this manifest command takes one argument
306+ self ._test_template ('prune' )
307+
308+ @unittest .skipIf (os .name != 'nt' , 'test relevant for Windows only' )
309+ def test_invalid_template_wrong_path (self ):
310+ # on Windows, trailing slashes are not allowed
311+ # this used to crash instead of raising a warning: #8286
312+ self ._test_template ('include examples/' )
313+
289314 @unittest .skipUnless (ZLIB_SUPPORT , 'Need zlib support to run' )
290315 def test_get_file_list (self ):
291316 # make sure MANIFEST is recalculated
0 commit comments