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 @@ -1,6 +1,8 @@ # -*- encoding: utf8 -*- """Tests for distutils.command.upload.""" import os +import sys +import StringIO import unittest from test.test_support import run_unittest @@ -85,16 +87,28 @@ ('repository', 'https://pypi.python.org/pypi')): self.assertEqual(getattr(cmd, attr), waited) - def test_saved_password(self): - # file with no password + def test_undefined_password(self): + # Simulate .pypirc file that has no password defined. self.write_file(self.rc, PYPIRC_NOPASSWORD) - # make sure it passes dist = Distribution() cmd = upload(dist) - cmd.finalize_options() - self.assertEqual(cmd.password, None) + + # Test `cmd.finalize_options()` with stdin + # being monkey-patched with a mock object. + stdin_original = sys.stdin + stdin_mock = StringIO.StringIO("test\n") + stdin_mock.seek(0) + try: + sys.stdin = stdin_mock + # Expected to prompt for password if process is attached to tty, + # or to read directly from stdin otherwise. + cmd.finalize_options() + finally: + sys.stdin = stdin_original + self.assertEqual(cmd.password, "test") + # make sure we get it as well, if another command # initialized it at the dist level dist.password = 'xxx'