Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Lib/test/test_ftplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1242,15 +1242,18 @@ def test_cli_commands(self, mock_netrc, mock_ftp_cls):
@mock.patch('netrc.netrc', side_effect=OSError)
def test_cli_retrieve_file(self, mock_netrc, mock_ftp_cls):
mock_ftp = mock_ftp_cls.return_value
with mock.patch('sys.argv', ['ftplib', 'example.com', 'testfile.txt']):
with mock.patch('sys.argv', ['ftplib', 'example.com', 'testfile.txt']), \
mock.patch('sys.stdout') as mock_stdout:
ftplib.test()
mock_ftp.retrbinary.assert_called_once()
args, kwargs = mock_ftp.retrbinary.call_args
self.assertEqual(args[0], 'RETR testfile.txt')
mock_ftp.retrbinary.assert_called_once_with(
'RETR testfile.txt', mock_stdout.buffer.write, 1024
)
mock_stdout.buffer.flush.assert_called_once()
mock_stdout.flush.assert_called_once()
mock_ftp.quit.assert_called_once()

@mock.patch('ftplib.FTP')
@mock.patch('netrc.netrc', side_effect=OSError('file not found'))
@mock.patch('netrc.netrc', side_effect=OSError)
def test_cli_custom_rcfile_error(self, mock_netrc, mock_ftp_cls):
with mock.patch('sys.argv', ['ftplib', '-rnonexistent.netrc', 'example.com']), \
support.captured_stderr() as stderr:
Expand Down
Loading