summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/tests
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2016-06-02 20:47:23 (GMT)
committerBerker Peksag <berker.peksag@gmail.com>2016-06-02 20:47:23 (GMT)
commitfddf12198fa43d411abb232c3ce8e97290717bfb (patch)
tree659e3a8bcbd61b8ed4548a252bea31489e2a391a /Lib/distutils/tests
parent0d20189f63fcd6843a8ca5a7c5364ecb590bf01d (diff)
parent6a8e626a60baef76b03df81a0b087dc9fdc3efcf (diff)
downloadcpython-fddf12198fa43d411abb232c3ce8e97290717bfb.zip
cpython-fddf12198fa43d411abb232c3ce8e97290717bfb.tar.gz
cpython-fddf12198fa43d411abb232c3ce8e97290717bfb.tar.bz2
Issue #21776: Merge from 3.5
Diffstat (limited to 'Lib/distutils/tests')
-rw-r--r--Lib/distutils/tests/test_upload.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/Lib/distutils/tests/test_upload.py b/Lib/distutils/tests/test_upload.py
index dccaf77..19193d5 100644
--- a/Lib/distutils/tests/test_upload.py
+++ b/Lib/distutils/tests/test_upload.py
@@ -1,13 +1,16 @@
"""Tests for distutils.command.upload."""
import os
import unittest
+import unittest.mock as mock
+from urllib.request import HTTPError
+
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.log import ERROR, INFO
from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase
@@ -144,6 +147,32 @@ class uploadTestCase(PyPIRCCommandTestCase):
self.next_code = 404
self.assertRaises(DistutilsError, self.test_upload)
+ def test_wrong_exception_order(self):
+ tmp = self.mkdtemp()
+ path = os.path.join(tmp, 'xxx')
+ self.write_file(path)
+ dist_files = [('xxx', '2.6', path)] # command, pyversion, filename
+ self.write_file(self.rc, PYPIRC_LONG_PASSWORD)
+
+ pkg_dir, dist = self.create_dist(dist_files=dist_files)
+ tests = [
+ (OSError('oserror'), 'oserror', OSError),
+ (HTTPError('url', 400, 'httperror', {}, None),
+ 'Upload failed (400): httperror', DistutilsError),
+ ]
+ for exception, expected, raised_exception in tests:
+ with self.subTest(exception=type(exception).__name__):
+ with mock.patch('distutils.command.upload.urlopen',
+ new=mock.Mock(side_effect=exception)):
+ with self.assertRaises(raised_exception):
+ cmd = upload(dist)
+ cmd.ensure_finalized()
+ cmd.run()
+ results = self.get_logs(ERROR)
+ self.assertIn(expected, results[-1])
+ self.clear_logs()
+
+
def test_suite():
return unittest.makeSuite(uploadTestCase)