summaryrefslogtreecommitdiff
path: root/Lib/distutils/tests
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-06-18 23:07:46 -0400
committerAntoine Pitrou <solipsis@pitrou.net>2014-06-18 23:07:46 -0400
commit2e4d3b133a8fe7be5469bc8f0d1a0f80a57f608c (patch)
treee559882cf65c6410f6997902933856c81b4c339d /Lib/distutils/tests
parent845fd9aa445f0a4a441fbe0bc3c1e1e318d1f217 (diff)
downloadcpython-git-2e4d3b133a8fe7be5469bc8f0d1a0f80a57f608c.tar.gz
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/distutils/tests')
-rw-r--r--Lib/distutils/tests/test_upload.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/Lib/distutils/tests/test_upload.py b/Lib/distutils/tests/test_upload.py
index f53eb266ed..0380f97944 100644
--- a/Lib/distutils/tests/test_upload.py
+++ b/Lib/distutils/tests/test_upload.py
@@ -6,6 +6,7 @@ from 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.log import INFO
from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase
@@ -41,13 +42,14 @@ 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 getheader(self, name, default=None):
return {
@@ -58,7 +60,7 @@ class FakeOpen(object):
return b'xyzzy'
def getcode(self):
- return 200
+ return self.code
class uploadTestCase(PyPIRCCommandTestCase):
@@ -68,13 +70,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):
@@ -135,6 +139,10 @@ class uploadTestCase(PyPIRCCommandTestCase):
results = self.get_logs(INFO)
self.assertIn('xyzzy\n', results[-1])
+ 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)