Ignore:
Timestamp:
Mar 19, 2014, 11:31:01 PM (11 years ago)
Author:
dmik
Message:

python: Merge vendor 2.7.6 to trunk.

Location:
python/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • python/trunk

  • python/trunk/Lib/test/test_urllibnet.py

    r2 r391  
    88import sys
    99import os
    10 import mimetools
     10import time
     11
     12mimetools = test_support.import_module("mimetools", deprecated=True)
    1113
    1214
     
    6163        for attr in ("read", "readline", "readlines", "fileno", "close",
    6264                     "info", "geturl"):
    63             self.assert_(hasattr(open_url, attr), "object returned from "
     65            self.assertTrue(hasattr(open_url, attr), "object returned from "
    6466                            "urlopen lacks the %s attribute" % attr)
    6567        try:
    66             self.assert_(open_url.read(), "calling 'read' failed")
     68            self.assertTrue(open_url.read(), "calling 'read' failed")
    6769        finally:
    6870            open_url.close()
     
    7274        open_url = self.urlopen("http://www.python.org/")
    7375        try:
    74             self.assert_(isinstance(open_url.readline(), basestring),
    75                          "readline did not return a string")
    76             self.assert_(isinstance(open_url.readlines(), list),
    77                          "readlines did not return a list")
     76            self.assertIsInstance(open_url.readline(), basestring,
     77                                  "readline did not return a string")
     78            self.assertIsInstance(open_url.readlines(), list,
     79                                  "readlines did not return a list")
    7880        finally:
    7981            open_url.close()
     
    8688        finally:
    8789            open_url.close()
    88             self.assert_(isinstance(info_obj, mimetools.Message),
    89                          "object returned by 'info' is not an instance of "
    90                          "mimetools.Message")
     90            self.assertIsInstance(info_obj, mimetools.Message,
     91                                  "object returned by 'info' is not an "
     92                                  "instance of mimetools.Message")
    9193            self.assertEqual(info_obj.getsubtype(), "html")
    9294
     
    122124        FILE = os.fdopen(fd)
    123125        try:
    124             self.assert_(FILE.read(), "reading from file created using fd "
     126            self.assertTrue(FILE.read(), "reading from file created using fd "
    125127                                      "returned by fileno failed")
    126128        finally:
     
    130132        # Make sure proper exception is raised when connecting to a bogus
    131133        # address.
     134        bogus_domain = "sadflkjsasf.i.nvali.d"
     135        try:
     136            socket.gethostbyname(bogus_domain)
     137        except socket.gaierror:
     138            pass
     139        else:
     140            # This happens with some overzealous DNS providers such as OpenDNS
     141            self.skipTest("%r should not resolve for test to work" % bogus_domain)
    132142        self.assertRaises(IOError,
    133143                          # SF patch 809915:  In Sep 2003, VeriSign started
     
    149159        # Test basic functionality.
    150160        file_location,info = self.urlretrieve("http://www.python.org/")
    151         self.assert_(os.path.exists(file_location), "file location returned by"
     161        self.assertTrue(os.path.exists(file_location), "file location returned by"
    152162                        " urlretrieve is not a valid path")
    153163        FILE = file(file_location)
    154164        try:
    155             self.assert_(FILE.read(), "reading from the file location returned"
     165            self.assertTrue(FILE.read(), "reading from the file location returned"
    156166                         " by urlretrieve failed")
    157167        finally:
     
    164174                                              test_support.TESTFN)
    165175        self.assertEqual(file_location, test_support.TESTFN)
    166         self.assert_(os.path.exists(file_location))
     176        self.assertTrue(os.path.exists(file_location))
    167177        FILE = file(file_location)
    168178        try:
    169             self.assert_(FILE.read(), "reading from temporary file failed")
     179            self.assertTrue(FILE.read(), "reading from temporary file failed")
    170180        finally:
    171181            FILE.close()
     
    176186        file_location, header = self.urlretrieve("http://www.python.org/")
    177187        os.unlink(file_location)
    178         self.assert_(isinstance(header, mimetools.Message),
    179                      "header is not an instance of mimetools.Message")
     188        self.assertIsInstance(header, mimetools.Message,
     189                              "header is not an instance of mimetools.Message")
     190
     191    def test_data_header(self):
     192        logo = "http://www.python.org/community/logos/python-logo-master-v3-TM.png"
     193        file_location, fileheaders = self.urlretrieve(logo)
     194        os.unlink(file_location)
     195        datevalue = fileheaders.getheader('Date')
     196        dateformat = '%a, %d %b %Y %H:%M:%S GMT'
     197        try:
     198            time.strptime(datevalue, dateformat)
     199        except ValueError:
     200            self.fail('Date value not in %r format', dateformat)
    180201
    181202
     
    183204def test_main():
    184205    test_support.requires('network')
    185     from warnings import filterwarnings, catch_warnings
    186     with catch_warnings():
    187         filterwarnings('ignore', '.*urllib\.urlopen.*Python 3.0',
    188                         DeprecationWarning)
     206    with test_support.check_py3k_warnings(
     207            ("urllib.urlopen.. has been removed", DeprecationWarning)):
    189208        test_support.run_unittest(URLTimeoutTest,
    190209                                  urlopenNetworkTests,
Note: See TracChangeset for help on using the changeset viewer.