Changeset 391 for python/trunk/Lib/test/test_urllibnet.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/test/test_urllibnet.py
r2 r391 8 8 import sys 9 9 import os 10 import mimetools 10 import time 11 12 mimetools = test_support.import_module("mimetools", deprecated=True) 11 13 12 14 … … 61 63 for attr in ("read", "readline", "readlines", "fileno", "close", 62 64 "info", "geturl"): 63 self.assert _(hasattr(open_url, attr), "object returned from "65 self.assertTrue(hasattr(open_url, attr), "object returned from " 64 66 "urlopen lacks the %s attribute" % attr) 65 67 try: 66 self.assert _(open_url.read(), "calling 'read' failed")68 self.assertTrue(open_url.read(), "calling 'read' failed") 67 69 finally: 68 70 open_url.close() … … 72 74 open_url = self.urlopen("http://www.python.org/") 73 75 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") 78 80 finally: 79 81 open_url.close() … … 86 88 finally: 87 89 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") 91 93 self.assertEqual(info_obj.getsubtype(), "html") 92 94 … … 122 124 FILE = os.fdopen(fd) 123 125 try: 124 self.assert _(FILE.read(), "reading from file created using fd "126 self.assertTrue(FILE.read(), "reading from file created using fd " 125 127 "returned by fileno failed") 126 128 finally: … … 130 132 # Make sure proper exception is raised when connecting to a bogus 131 133 # 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) 132 142 self.assertRaises(IOError, 133 143 # SF patch 809915: In Sep 2003, VeriSign started … … 149 159 # Test basic functionality. 150 160 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" 152 162 " urlretrieve is not a valid path") 153 163 FILE = file(file_location) 154 164 try: 155 self.assert _(FILE.read(), "reading from the file location returned"165 self.assertTrue(FILE.read(), "reading from the file location returned" 156 166 " by urlretrieve failed") 157 167 finally: … … 164 174 test_support.TESTFN) 165 175 self.assertEqual(file_location, test_support.TESTFN) 166 self.assert _(os.path.exists(file_location))176 self.assertTrue(os.path.exists(file_location)) 167 177 FILE = file(file_location) 168 178 try: 169 self.assert _(FILE.read(), "reading from temporary file failed")179 self.assertTrue(FILE.read(), "reading from temporary file failed") 170 180 finally: 171 181 FILE.close() … … 176 186 file_location, header = self.urlretrieve("http://www.python.org/") 177 187 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) 180 201 181 202 … … 183 204 def test_main(): 184 205 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)): 189 208 test_support.run_unittest(URLTimeoutTest, 190 209 urlopenNetworkTests,
Note:
See TracChangeset
for help on using the changeset viewer.