Skip to content

Commit 81e71a9

Browse files
committed
Add test case with control chars
1 parent 3c027d4 commit 81e71a9

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Lib/test/test_getpass.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def test_echochar_replaces_input_with_asterisks(self):
176176
mock_input.assert_called_once_with('Password: ', textio(), textio(), '*')
177177
self.assertEqual(result, mock_result)
178178

179-
def test_input_with_echochar(self):
179+
def test_input_with_control_characters(self):
180180
passwd = 'my1pa$$word!'
181181
mock_input = StringIO(f'{passwd}\n')
182182
mock_output = StringIO()
@@ -187,6 +187,18 @@ def test_input_with_echochar(self):
187187
self.assertEqual(result, passwd)
188188
self.assertEqual('Password: ************', mock_output.getvalue())
189189

190+
def test_control_chars_with_echochar(self):
191+
passwd = 'pass\twd\b'
192+
expect_result = 'pass\tw'
193+
mock_input = StringIO(f'{passwd}\n')
194+
mock_output = StringIO()
195+
with mock.patch('sys.stdin', mock_input), \
196+
mock.patch('sys.stdout', mock_output):
197+
result = getpass._input_with_echochar('Password: ', mock_output,
198+
mock_input, '*')
199+
self.assertEqual(result, expect_result)
200+
self.assertEqual('Password: *******\x08 \x08', mock_output.getvalue())
201+
190202

191203
if __name__ == "__main__":
192204
unittest.main()

0 commit comments

Comments
 (0)