MCPcopy Index your code
hub / github.com/python/cpython / test_ftp_error

Method test_ftp_error

Lib/test/test_urllib2.py:801–820  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

799
800 @support.requires_resource("network")
801 def test_ftp_error(self):
802 class ErrorFTPHandler(urllib.request.FTPHandler):
803 def __init__(self, exception):
804 self._exception = exception
805
806 def connect_ftp(self, user, passwd, host, port, dirs,
807 timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
808 raise self._exception
809
810 exception = ftplib.error_perm(
811 "500 OOPS: cannot change directory:/nonexistent")
812 h = ErrorFTPHandler(exception)
813 urlopen = urllib.request.build_opener(h).open
814 try:
815 urlopen("ftp://www.pythontest.net/")
816 except urllib.error.URLError as raised:
817 self.assertEqual(raised.reason,
818 f"ftp error: {exception.args[0]}")
819 else:
820 self.fail("Did not raise ftplib exception")
821
822 def test_file(self):
823 import email.utils

Callers

nothing calls this directly

Calls 4

ErrorFTPHandlerClass · 0.85
urlopenFunction · 0.85
assertEqualMethod · 0.45
failMethod · 0.45

Tested by

no test coverage detected