[Python-checkins] cpython (2.7): Issue #21722: The distutils "upload" command now exits with a non-zero return

antoine.pitrou python-checkins at python.org
Thu Jun 19 05:15:07 CEST 2014


http://hg.python.org/cpython/rev/cf70f030a744
changeset: 91269:cf70f030a744
branch: 2.7
parent: 91249:8a64509b0bd5
user: Antoine Pitrou <solipsis at pitrou.net>
date: Wed Jun 18 23:07:46 2014 -0400
summary:
 Issue #21722: The distutils "upload" command now exits with a non-zero return code when uploading fails.
Patch by Martin Dengler.
files:
 Lib/distutils/command/upload.py | 9 +++++----
 Lib/distutils/tests/test_upload.py | 17 +++++++++++++----
 Misc/ACKS | 1 +
 Misc/NEWS | 3 +++
 4 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/Lib/distutils/command/upload.py b/Lib/distutils/command/upload.py
--- a/Lib/distutils/command/upload.py
+++ b/Lib/distutils/command/upload.py
@@ -10,7 +10,7 @@
 import cStringIO as StringIO
 from hashlib import md5
 
-from distutils.errors import DistutilsOptionError
+from distutils.errors import DistutilsError, DistutilsOptionError
 from distutils.core import PyPIRCCommand
 from distutils.spawn import spawn
 from distutils import log
@@ -181,7 +181,7 @@
 self.announce(msg, log.INFO)
 except socket.error, e:
 self.announce(str(e), log.ERROR)
- return
+ raise
 except HTTPError, e:
 status = e.code
 reason = e.msg
@@ -190,5 +190,6 @@
 self.announce('Server response (%s): %s' % (status, reason),
 log.INFO)
 else:
- self.announce('Upload failed (%s): %s' % (status, reason),
- log.ERROR)
+ msg = 'Upload failed (%s): %s' % (status, reason)
+ self.announce(msg, log.ERROR)
+ raise DistutilsError(msg)
diff --git a/Lib/distutils/tests/test_upload.py b/Lib/distutils/tests/test_upload.py
--- a/Lib/distutils/tests/test_upload.py
+++ b/Lib/distutils/tests/test_upload.py
@@ -7,6 +7,7 @@
 from distutils.command import upload as upload_mod
 from distutils.command.upload import upload
 from distutils.core import Distribution
+from distutils.errors import DistutilsError
 
 from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase
 
@@ -41,16 +42,17 @@
 
 class FakeOpen(object):
 
- def __init__(self, url):
+ def __init__(self, url, msg=None, code=None):
 self.url = url
 if not isinstance(url, str):
 self.req = url
 else:
 self.req = None
- self.msg = 'OK'
+ self.msg = msg or 'OK'
+ self.code = code or 200
 
 def getcode(self):
- return 200
+ return self.code
 
 
 class uploadTestCase(PyPIRCCommandTestCase):
@@ -60,13 +62,15 @@
 self.old_open = upload_mod.urlopen
 upload_mod.urlopen = self._urlopen
 self.last_open = None
+ self.next_msg = None
+ self.next_code = None
 
 def tearDown(self):
 upload_mod.urlopen = self.old_open
 super(uploadTestCase, self).tearDown()
 
 def _urlopen(self, url):
- self.last_open = FakeOpen(url)
+ self.last_open = FakeOpen(url, msg=self.next_msg, code=self.next_code)
 return self.last_open
 
 def test_finalize_options(self):
@@ -124,6 +128,11 @@
 auth = self.last_open.req.headers['Authorization']
 self.assertNotIn('\n', auth)
 
+ def test_upload_fails(self):
+ self.next_msg = "Not Found"
+ self.next_code = 404
+ self.assertRaises(DistutilsError, self.test_upload)
+
 def test_suite():
 return unittest.makeSuite(uploadTestCase)
 
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -306,6 +306,7 @@
 Arnaud Delobelle
 Konrad Delong
 Erik Demaine
+Martin Dengler
 John Dennis
 L. Peter Deutsch
 Roger Dev
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -29,6 +29,9 @@
 Library
 -------
 
+- Issue #21722: The distutils "upload" command now exits with a non-zero
+ return code when uploading fails. Patch by Martin Dengler.
+
 - Issue #21766: Prevent a security hole in CGIHTTPServer by URL unquoting paths
 before checking for a CGI script at that path.
 
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /