[Python-checkins] cpython: #17699: Fix the new getpass test failures on windows.
r.david.murray
python-checkins at python.org
Thu Apr 11 23:47:56 CEST 2013
http://hg.python.org/cpython/rev/c84a5e5f73c3
changeset: 83257:c84a5e5f73c3
user: R David Murray <rdmurray at bitdance.com>
date: Thu Apr 11 17:45:32 2013 -0400
summary:
#17699: Fix the new getpass test failures on windows.
Patch by Zachary Ware.
files:
Lib/test/test_getpass.py | 37 ++++++++++++++++++---------
1 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/Lib/test/test_getpass.py b/Lib/test/test_getpass.py
--- a/Lib/test/test_getpass.py
+++ b/Lib/test/test_getpass.py
@@ -1,11 +1,19 @@
import getpass
import os
-import termios
import unittest
from io import StringIO
from unittest import mock
from test import support
+try:
+ import termios
+except ImportError:
+ termios = None
+try:
+ import pwd
+except ImportError:
+ pwd = None
+
@mock.patch('os.environ')
class GetpassGetuserTest(unittest.TestCase):
@@ -16,7 +24,10 @@
def test_username_priorities_of_env_values(self, environ):
environ.get.return_value = None
- getpass.getuser()
+ try:
+ getpass.getuser()
+ except ImportError: # in case there's no pwd module
+ pass
self.assertEqual(
environ.get.call_args_list,
[mock.call(x) for x in ('LOGNAME', 'USER', 'LNAME', 'USERNAME')])
@@ -24,13 +35,16 @@
def test_username_falls_back_to_pwd(self, environ):
expected_name = 'some_name'
environ.get.return_value = None
- with mock.patch('os.getuid') as uid, \
- mock.patch('pwd.getpwuid') as getpw:
- uid.return_value = 42
- getpw.return_value = [expected_name]
- self.assertEqual(expected_name,
- getpass.getuser())
- getpw.assert_called_once_with(42)
+ if pwd:
+ with mock.patch('os.getuid') as uid, \
+ mock.patch('pwd.getpwuid') as getpw:
+ uid.return_value = 42
+ getpw.return_value = [expected_name]
+ self.assertEqual(expected_name,
+ getpass.getuser())
+ getpw.assert_called_once_with(42)
+ else:
+ self.assertRaises(ImportError, getpass.getuser)
class GetpassRawinputTest(unittest.TestCase):
@@ -68,9 +82,8 @@
# the password input be taken directly from the tty, and that it not be echoed
# on the screen, unless we are falling back to stderr/stdin.
-# Some of these might run on other platforms, but play it safe.
- at unittest.skipUnless(os.name == 'posix',
- 'tests are for the unix version of getpass')
+# Some of these might run on platforms without termios, but play it safe.
+ at unittest.skipUnless(termios, 'tests require system with termios')
class UnixGetpassTest(unittest.TestCase):
def test_uses_tty_directly(self):
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list