Skip to content

Commit ca46d3d

Browse files
committed
Maintain context manager syntax
1 parent 2bf440c commit ca46d3d

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

Lib/test/test_getpass.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
try:
1818
import msvcrt
1919
except ImportError:
20-
mscvrt = None
20+
msvcrt = None
2121

2222
@mock.patch('os.environ')
2323
class GetpassGetuserTest(unittest.TestCase):
@@ -185,16 +185,11 @@ def test_uses_msvcrt_directly(self):
185185
mock_stream.flush.assert_called()
186186

187187
def test_handles_backspace(self):
188-
with (
189-
mock.patch('msvcrt.getch') as getch,
190-
mock.patch('msvcrt.putch') as putch,
191-
):
188+
with mock.patch('msvcrt.getch') as getch, \
189+
mock.patch('msvcrt.putch') as putch:
192190
getch.side_effect = [b'a', b'b', b'\b', b'c', b'\r']
193191
result = getpass.win_getpass()
194192
self.assertEqual(result, 'ac')
195-
# Verify putch was called to handle the backspace (erase character)
196-
# The exact sequence depends on the implementation, but should include
197-
# calls to handle the backspace character
198193
putch.assert_any_call(b'\b')
199194

200195
def test_handles_ctrl_c(self):
@@ -214,8 +209,7 @@ def test_flushes_stream_after_input(self):
214209

215210
def test_falls_back_to_fallback_if_msvcrt_raises(self):
216211
with mock.patch('msvcrt.getch') as getch, \
217-
mock.patch('getpass.fallback_getpass') as fallback:
218-
# Make getch raise an exception to trigger the fallback
212+
mock.patch('getpass.fallback_getpass') as fallback:
219213
getch.side_effect = RuntimeError("Simulated msvcrt failure")
220214
mock_stream = mock.Mock(spec=StringIO)
221215
getpass.win_getpass(stream=mock_stream)

0 commit comments

Comments
 (0)