Back to index

python3.2  3.2.2
Public Member Functions
test.test_urllibnet.urlopenNetworkTests Class Reference

List of all members.

Public Member Functions

def urlopen
def test_basic
def test_readlines
def test_info
def test_geturl
def test_getcode
def test_fileno
def test_bad_address

Detailed Description

Tests urllib.reqest.urlopen using the network.

These tests are not exhaustive.  Assuming that testing using files does a
good job overall of some of the basic interface features.  There are no
tests exercising the optional 'data' and 'proxies' arguments.  No tests
for transparent redirection have been written.

setUp is not used for always constructing a connection to
http://www.python.org/ since there a few tests that don't use that address
and making a connection is expensive enough to warrant minimizing unneeded
connections.

Definition at line 32 of file test_urllibnet.py.


Member Function Documentation

Definition at line 113 of file test_urllibnet.py.

00113 
00114     def test_bad_address(self):
00115         # Make sure proper exception is raised when connecting to a bogus
00116         # address.
00117         bogus_domain = "sadflkjsasf.i.nvali.d"
00118         try:
00119             socket.gethostbyname(bogus_domain)
00120         except socket.gaierror:
00121             pass
00122         else:
00123             # This happens with some overzealous DNS providers such as OpenDNS
00124             self.skipTest("%r should not resolve for test to work" % bogus_domain)
00125         self.assertRaises(IOError,
00126                           # SF patch 809915:  In Sep 2003, VeriSign started
00127                           # highjacking invalid .com and .net addresses to
00128                           # boost traffic to their own site.  This test
00129                           # started failing then.  One hopes the .invalid
00130                           # domain will be spared to serve its defined
00131                           # purpose.
00132                           # urllib.urlopen, "http://www.sadflkjsasadf.com/")
00133                           urllib.request.urlopen,
00134                           "http://sadflkjsasf.i.nvali.d/")
00135 

Here is the call graph for this function:

Definition at line 57 of file test_urllibnet.py.

00057 
00058     def test_basic(self):
00059         # Simple test expected to pass.
00060         with self.urlopen("http://www.python.org/") as open_url:
00061             for attr in ("read", "readline", "readlines", "fileno", "close",
00062                          "info", "geturl"):
00063                 self.assertTrue(hasattr(open_url, attr), "object returned from "
00064                                 "urlopen lacks the %s attribute" % attr)
00065             self.assertTrue(open_url.read(), "calling 'read' failed")

Here is the call graph for this function:

Definition at line 101 of file test_urllibnet.py.

00101 
00102     def test_fileno(self):
00103         if sys.platform in ('win32',):
00104             # On Windows, socket handles are not file descriptors; this
00105             # test can't pass on Windows.
00106             return
00107         # Make sure fd returned by fileno is valid.
00108         with self.urlopen("http://www.python.org/", timeout=None) as open_url:
00109             fd = open_url.fileno()
00110             with os.fdopen(fd, encoding='utf-8') as f:
00111                 self.assertTrue(f.read(), "reading from file created using fd "
00112                                           "returned by fileno failed")

Here is the call graph for this function:

Definition at line 90 of file test_urllibnet.py.

00090 
00091     def test_getcode(self):
00092         # test getcode() with the fancy opener to get 404 error codes
00093         URL = "http://www.python.org/XXXinvalidXXX"
00094         with support.transient_internet(URL):
00095             open_url = urllib.request.FancyURLopener().open(URL)
00096             try:
00097                 code = open_url.getcode()
00098             finally:
00099                 open_url.close()
00100             self.assertEqual(code, 404)

Here is the call graph for this function:

Definition at line 83 of file test_urllibnet.py.

00083 
00084     def test_geturl(self):
00085         # Make sure same URL as opened is returned by geturl.
00086         URL = "http://www.python.org/"
00087         with self.urlopen(URL) as open_url:
00088             gotten_url = open_url.geturl()
00089             self.assertEqual(gotten_url, URL)

Here is the call graph for this function:

Definition at line 74 of file test_urllibnet.py.

00074 
00075     def test_info(self):
00076         # Test 'info'.
00077         with self.urlopen("http://www.python.org/") as open_url:
00078             info_obj = open_url.info()
00079             self.assertIsInstance(info_obj, email.message.Message,
00080                                   "object returned by 'info' is not an "
00081                                   "instance of email.message.Message")
00082             self.assertEqual(info_obj.get_content_subtype(), "html")

Here is the call graph for this function:

Definition at line 66 of file test_urllibnet.py.

00066 
00067     def test_readlines(self):
00068         # Test both readline and readlines.
00069         with self.urlopen("http://www.python.org/") as open_url:
00070             self.assertIsInstance(open_url.readline(), bytes,
00071                                   "readline did not return a string")
00072             self.assertIsInstance(open_url.readlines(), list,
00073                                   "readlines did not return a list")

Here is the call graph for this function:

def test.test_urllibnet.urlopenNetworkTests.urlopen (   self,
  args,
  kwargs 
)

Definition at line 48 of file test_urllibnet.py.

00048 
00049     def urlopen(self, *args, **kwargs):
00050         resource = args[0]
00051         with support.transient_internet(resource):
00052             r = urllib.request.urlopen(*args, **kwargs)
00053             try:
00054                 yield r
00055             finally:
00056                 r.close()

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following file: