|
8 | 8 |
|
9 | 9 | import os
|
10 | 10 | import io
|
| 11 | +import ftplib |
11 | 12 | import socket
|
12 | 13 | import array
|
13 | 14 | import sys
|
@@ -754,7 +755,6 @@ def connect_ftp(self, user, passwd, host, port, dirs,
|
754 | 755 | self.ftpwrapper = MockFTPWrapper(self.data)
|
755 | 756 | return self.ftpwrapper
|
756 | 757 |
|
757 |
| - import ftplib |
758 | 758 | data = "rheum rhaponicum"
|
759 | 759 | h = NullFTPHandler(data)
|
760 | 760 | h.parent = MockOpener()
|
@@ -794,6 +794,25 @@ def connect_ftp(self, user, passwd, host, port, dirs,
|
794 | 794 | self.assertEqual(headers.get("Content-type"), mimetype)
|
795 | 795 | self.assertEqual(int(headers["Content-length"]), len(data))
|
796 | 796 |
|
| 797 | + def test_ftp_error(self): |
| 798 | + class ErrorFTPHandler(urllib.request.FTPHandler): |
| 799 | + def __init__(self, exception): |
| 800 | + self._exception = exception |
| 801 | + |
| 802 | + def connect_ftp(self, user, passwd, host, port, dirs, |
| 803 | + timeout=socket._GLOBAL_DEFAULT_TIMEOUT): |
| 804 | + raise self._exception |
| 805 | + |
| 806 | + exception = ftplib.error_perm("500 OOPS: cannot change directory:/nonexistent") |
| 807 | + h = ErrorFTPHandler(exception) |
| 808 | + urlopen = urllib.request.build_opener(h).open |
| 809 | + try: |
| 810 | + urlopen("ftp://www.pythontest.net/") |
| 811 | + except urllib.error.URLError as raised: |
| 812 | + self.assertEqual(raised.reason, exception.args[0]) |
| 813 | + else: |
| 814 | + self.fail("Did not raise ftplib exception") |
| 815 | + |
797 | 816 | def test_file(self):
|
798 | 817 | import email.utils
|
799 | 818 | h = urllib.request.FileHandler()
|
|
0 commit comments