Skip to content

Commit 80ea3a1

Browse files
committed
gh-131178: Mock sys.stdout in test_ftplib CLI retrieve test
Mock sys.stdout in CommandLineTest.test_cli_retrieve_file so that accessing sys.stdout.buffer does not fail when regrtest or other test runners wrap sys.stdout in an io.StringIO object.
1 parent 4b21d15 commit 80ea3a1

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎Lib/test/test_ftplib.py‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,11 +1242,14 @@ def test_cli_commands(self, mock_netrc, mock_ftp_cls):
12421242
@mock.patch('netrc.netrc', side_effect=OSError)
12431243
def test_cli_retrieve_file(self, mock_netrc, mock_ftp_cls):
12441244
mock_ftp = mock_ftp_cls.return_value
1245-
with mock.patch('sys.argv', ['ftplib', 'example.com', 'testfile.txt']):
1245+
with mock.patch('sys.argv', ['ftplib', 'example.com', 'testfile.txt']), \
1246+
mock.patch('sys.stdout') as mock_stdout:
12461247
ftplib.test()
1247-
mock_ftp.retrbinary.assert_called_once()
1248-
args, kwargs = mock_ftp.retrbinary.call_args
1249-
self.assertEqual(args[0], 'RETR testfile.txt')
1248+
mock_ftp.retrbinary.assert_called_once_with(
1249+
'RETR testfile.txt', mock_stdout.buffer.write, 1024
1250+
)
1251+
mock_stdout.buffer.flush.assert_called_once()
1252+
mock_stdout.flush.assert_called_once()
12501253
mock_ftp.quit.assert_called_once()
12511254

12521255
@mock.patch('ftplib.FTP')

0 commit comments

Comments
 (0)