summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-06-19 03:07:46 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-06-19 03:07:46 (GMT)
commit077c9564b7f0c09352d1d918f38d2cb75fe61881 (patch)
treef71d02992d0ef9e29ff3b2ec2fe12e7bf414dc25 /Lib
parentfa3b9cc7c8b9003dd607b608bdd4c1c2d42f4d4b (diff)
downloadcpython-077c9564b7f0c09352d1d918f38d2cb75fe61881.zip
cpython-077c9564b7f0c09352d1d918f38d2cb75fe61881.tar.gz
cpython-077c9564b7f0c09352d1d918f38d2cb75fe61881.tar.bz2
Issue #21722: The distutils "upload" command now exits with a non-zero return code when uploading fails.
Patch by Martin Dengler.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/distutils/command/upload.py9
-rw-r--r--Lib/distutils/tests/test_upload.py17
2 files changed, 18 insertions, 8 deletions
diff --git a/Lib/distutils/command/upload.py b/Lib/distutils/command/upload.py
index c43607f..9aa54ee 100644
--- a/Lib/distutils/command/upload.py
+++ b/Lib/distutils/command/upload.py
@@ -10,7 +10,7 @@ import urlparse
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 @@ class upload(PyPIRCCommand):
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 @@ class upload(PyPIRCCommand):
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
index 8b8262e..17735d3 100644
--- a/Lib/distutils/tests/test_upload.py
+++ b/Lib/distutils/tests/test_upload.py
@@ -7,6 +7,7 @@ from test.test_support import run_unittest
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 @@ username:me
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 @@ class uploadTestCase(PyPIRCCommandTestCase):
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 @@ class uploadTestCase(PyPIRCCommandTestCase):
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)