summaryrefslogtreecommitdiff
path: root/Lib/test/test_getpass.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2013-07-10 17:02:24 -0400
committerR David Murray <rdmurray@bitdance.com>2013-07-10 17:02:24 -0400
commit16dbbae2981c96c7c9b1ae81e1708d54b08c10ac (patch)
treea1e1d877ee7619ba1d19e2332a2af0b550545904 /Lib/test/test_getpass.py
parentacb362e29f46a7c748a6dff450d4f912ca03b633 (diff)
downloadcpython-git-16dbbae2981c96c7c9b1ae81e1708d54b08c10ac.tar.gz
#18116: getpass no longer always falls back to stdin.
Also fixes a resource warning that occurred when the fallback is taken. Patch by Serhiy Storchaka. (We couldn't figure out how to write tests for this.)
Diffstat (limited to 'Lib/test/test_getpass.py')
-rw-r--r--Lib/test/test_getpass.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/Lib/test/test_getpass.py b/Lib/test/test_getpass.py
index 15537b90b3..1731bd44a6 100644
--- a/Lib/test/test_getpass.py
+++ b/Lib/test/test_getpass.py
@@ -1,7 +1,7 @@
import getpass
import os
import unittest
-from io import StringIO
+from io import BytesIO, StringIO
from unittest import mock
from test import support
@@ -88,7 +88,8 @@ class UnixGetpassTest(unittest.TestCase):
def test_uses_tty_directly(self):
with mock.patch('os.open') as open, \
- mock.patch('os.fdopen'):
+ mock.patch('io.FileIO') as fileio, \
+ mock.patch('io.TextIOWrapper') as textio:
# By setting open's return value to None the implementation will
# skip code we don't care about in this test. We can mock this out
# fully if an alternate implementation works differently.
@@ -96,10 +97,13 @@ class UnixGetpassTest(unittest.TestCase):
getpass.unix_getpass()
open.assert_called_once_with('/dev/tty',
os.O_RDWR | os.O_NOCTTY)
+ fileio.assert_called_once_with(open.return_value, 'w+')
+ textio.assert_called_once_with(fileio.return_value)
def test_resets_termios(self):
with mock.patch('os.open') as open, \
- mock.patch('os.fdopen'), \
+ mock.patch('io.FileIO'), \
+ mock.patch('io.TextIOWrapper'), \
mock.patch('termios.tcgetattr') as tcgetattr, \
mock.patch('termios.tcsetattr') as tcsetattr:
open.return_value = 3
@@ -110,21 +114,23 @@ class UnixGetpassTest(unittest.TestCase):
def test_falls_back_to_fallback_if_termios_raises(self):
with mock.patch('os.open') as open, \
- mock.patch('os.fdopen') as fdopen, \
+ mock.patch('io.FileIO') as fileio, \
+ mock.patch('io.TextIOWrapper') as textio, \
mock.patch('termios.tcgetattr'), \
mock.patch('termios.tcsetattr') as tcsetattr, \
mock.patch('getpass.fallback_getpass') as fallback:
open.return_value = 3
- fdopen.return_value = StringIO()
+ fileio.return_value = BytesIO()
tcsetattr.side_effect = termios.error
getpass.unix_getpass()
fallback.assert_called_once_with('Password: ',
- fdopen.return_value)
+ textio.return_value)
def test_flushes_stream_after_input(self):
# issue 7208
with mock.patch('os.open') as open, \
- mock.patch('os.fdopen'), \
+ mock.patch('io.FileIO'), \
+ mock.patch('io.TextIOWrapper'), \
mock.patch('termios.tcgetattr'), \
mock.patch('termios.tcsetattr'):
open.return_value = 3