Back to index

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

List of all members.

Public Member Functions

def urlretrieve
def test_basic
def test_specified_path
def test_header
def test_data_header

Detailed Description

Tests urllib.request.urlretrieve using the network.

Definition at line 136 of file test_urllibnet.py.


Member Function Documentation

Definition at line 149 of file test_urllibnet.py.

00149 
00150     def test_basic(self):
00151         # Test basic functionality.
00152         with self.urlretrieve("http://www.python.org/") as (file_location, info):
00153             self.assertTrue(os.path.exists(file_location), "file location returned by"
00154                             " urlretrieve is not a valid path")
00155             with open(file_location, encoding='utf-8') as f:
00156                 self.assertTrue(f.read(), "reading from the file location returned"
00157                                 " by urlretrieve failed")

Here is the call graph for this function:

Definition at line 173 of file test_urllibnet.py.

00173 
00174     def test_data_header(self):
00175         logo = "http://www.python.org/community/logos/python-logo-master-v3-TM.png"
00176         with self.urlretrieve(logo) as (file_location, fileheaders):
00177             datevalue = fileheaders.get('Date')
00178             dateformat = '%a, %d %b %Y %H:%M:%S GMT'
00179             try:
00180                 time.strptime(datevalue, dateformat)
00181             except ValueError:
00182                 self.fail('Date value not in %r format', dateformat)
00183 

Here is the call graph for this function:

Definition at line 167 of file test_urllibnet.py.

00167 
00168     def test_header(self):
00169         # Make sure header returned as 2nd value from urlretrieve is good.
00170         with self.urlretrieve("http://www.python.org/") as (file_location, info):
00171             self.assertIsInstance(info, email.message.Message,
00172                                   "info is not an instance of email.message.Message")

Here is the call graph for this function:

Definition at line 158 of file test_urllibnet.py.

00158 
00159     def test_specified_path(self):
00160         # Make sure that specifying the location of the file to write to works.
00161         with self.urlretrieve("http://www.python.org/",
00162                               support.TESTFN) as (file_location, info):
00163             self.assertEqual(file_location, support.TESTFN)
00164             self.assertTrue(os.path.exists(file_location))
00165             with open(file_location, encoding='utf-8') as f:
00166                 self.assertTrue(f.read(), "reading from temporary file failed")

Here is the call graph for this function:

Definition at line 140 of file test_urllibnet.py.

00140 
00141     def urlretrieve(self, *args):
00142         resource = args[0]
00143         with support.transient_internet(resource):
00144             file_location, info = urllib.request.urlretrieve(*args)
00145             try:
00146                 yield file_location, info
00147             finally:
00148                 support.unlink(file_location)

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: