summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorIgor Filatov <iafilatov@users.noreply.github.com>2017-09-25 01:03:24 (GMT)
committerNick Coghlan <ncoghlan@gmail.com>2017-09-25 01:03:24 (GMT)
commitcf7197ae43767c4346864e5b41246f628edd9b51 (patch)
tree31b2ad79968e1509a5b09ced5fc344346700640d /Lib/test
parentda86874a3d8f882d6aedd882b2e27f59b59d6798 (diff)
downloadcpython-cf7197ae43767c4346864e5b41246f628edd9b51.zip
cpython-cf7197ae43767c4346864e5b41246f628edd9b51.tar.gz
cpython-cf7197ae43767c4346864e5b41246f628edd9b51.tar.bz2
[2.7] bpo-31351: Set return code in ensurepip when pip fails (GH-3734)
Previously ensurepip would always report success, even if the pip installation failed. (cherry picked from commit 9adda0cdf89432386b7a04444a6199b580d287a1)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_ensurepip.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/Lib/test/test_ensurepip.py b/Lib/test/test_ensurepip.py
index 3316fcf..cb9d10a 100644
--- a/Lib/test/test_ensurepip.py
+++ b/Lib/test/test_ensurepip.py
@@ -21,6 +21,7 @@ class EnsurepipMixin:
def setUp(self):
run_pip_patch = mock.patch("ensurepip._run_pip")
self.run_pip = run_pip_patch.start()
+ self.run_pip.return_value = 0
self.addCleanup(run_pip_patch.stop)
# Avoid side effects on the actual os module
@@ -258,7 +259,7 @@ class TestBootstrappingMainFunction(EnsurepipMixin, unittest.TestCase):
self.assertFalse(self.run_pip.called)
def test_basic_bootstrapping(self):
- ensurepip._main([])
+ exit_code = ensurepip._main([])
self.run_pip.assert_called_once_with(
[
@@ -270,6 +271,13 @@ class TestBootstrappingMainFunction(EnsurepipMixin, unittest.TestCase):
additional_paths = self.run_pip.call_args[0][1]
self.assertEqual(len(additional_paths), 2)
+ self.assertEqual(exit_code, 0)
+
+ def test_bootstrapping_error_code(self):
+ self.run_pip.return_value = 2
+ exit_code = ensurepip._main([])
+ self.assertEqual(exit_code, 2)
+
class TestUninstallationMainFunction(EnsurepipMixin, unittest.TestCase):
@@ -284,7 +292,7 @@ class TestUninstallationMainFunction(EnsurepipMixin, unittest.TestCase):
def test_basic_uninstall(self):
with fake_pip():
- ensurepip._uninstall._main([])
+ exit_code = ensurepip._uninstall._main([])
self.run_pip.assert_called_once_with(
[
@@ -293,6 +301,13 @@ class TestUninstallationMainFunction(EnsurepipMixin, unittest.TestCase):
]
)
+ self.assertEqual(exit_code, 0)
+
+ def test_uninstall_error_code(self):
+ with fake_pip():
+ self.run_pip.return_value = 2
+ exit_code = ensurepip._uninstall._main([])
+ self.assertEqual(exit_code, 2)
if __name__ == "__main__":
test.test_support.run_unittest(__name__)