@@ -43,7 +43,7 @@ def tearDown(self):
43
43
socket .setdefaulttimeout (None )
44
44
45
45
def testURLread (self ):
46
- f = _open_with_retry (urllib .urlopen , "http://www.example.com/" )
46
+ f = _open_with_retry (urllib .urlopen , test_support . TEST_HTTP_URL )
47
47
x = f .read ()
48
48
49
49
class urlopenNetworkTests (unittest .TestCase ):
@@ -66,7 +66,7 @@ def urlopen(self, *args):
66
66
67
67
def test_basic (self ):
68
68
# Simple test expected to pass.
69
- open_url = self .urlopen ("http://www.example.com/" )
69
+ open_url = self .urlopen (test_support . TEST_HTTP_URL )
70
70
for attr in ("read" , "readline" , "readlines" , "fileno" , "close" ,
71
71
"info" , "geturl" ):
72
72
self .assertTrue (hasattr (open_url , attr ), "object returned from "
@@ -78,7 +78,7 @@ def test_basic(self):
78
78
79
79
def test_readlines (self ):
80
80
# Test both readline and readlines.
81
- open_url = self .urlopen ("http://www.example.com/" )
81
+ open_url = self .urlopen (test_support . TEST_HTTP_URL )
82
82
try :
83
83
self .assertIsInstance (open_url .readline (), basestring ,
84
84
"readline did not return a string" )
@@ -89,7 +89,7 @@ def test_readlines(self):
89
89
90
90
def test_info (self ):
91
91
# Test 'info'.
92
- open_url = self .urlopen ("http://www.example.com/" )
92
+ open_url = self .urlopen (test_support . TEST_HTTP_URL )
93
93
try :
94
94
info_obj = open_url .info ()
95
95
finally :
@@ -101,13 +101,12 @@ def test_info(self):
101
101
102
102
def test_geturl (self ):
103
103
# Make sure same URL as opened is returned by geturl.
104
- URL = "http://www.example.com/"
105
- open_url = self .urlopen (URL )
104
+ open_url = self .urlopen (test_support .TEST_HTTP_URL )
106
105
try :
107
106
gotten_url = open_url .geturl ()
108
107
finally :
109
108
open_url .close ()
110
- self .assertEqual (gotten_url , URL )
109
+ self .assertEqual (gotten_url , test_support . TEST_HTTP_URL )
111
110
112
111
def test_getcode (self ):
113
112
# test getcode() with the fancy opener to get 404 error codes
@@ -123,12 +122,13 @@ def test_getcode(self):
123
122
@unittest .skipUnless (hasattr (os , 'fdopen' ), 'os.fdopen not available' )
124
123
def test_fileno (self ):
125
124
# Make sure fd returned by fileno is valid.
126
- open_url = self .urlopen ("http://www.example.com/" )
125
+ open_url = self .urlopen (test_support . TEST_HTTP_URL )
127
126
fd = open_url .fileno ()
128
127
FILE = os .fdopen (fd )
129
128
try :
130
- self .assertTrue (FILE .read (), "reading from file created using fd "
131
- "returned by fileno failed" )
129
+ self .assertTrue (FILE .read (),
130
+ "reading from file created using fd "
131
+ "returned by fileno failed" )
132
132
finally :
133
133
FILE .close ()
134
134
@@ -161,7 +161,7 @@ def urlretrieve(self, *args):
161
161
162
162
def test_basic (self ):
163
163
# Test basic functionality.
164
- file_location ,info = self .urlretrieve ("http://www.example.com/" )
164
+ file_location ,info = self .urlretrieve (test_support . TEST_HTTP_URL )
165
165
self .assertTrue (os .path .exists (file_location ), "file location returned by"
166
166
" urlretrieve is not a valid path" )
167
167
FILE = file (file_location )
@@ -174,7 +174,7 @@ def test_basic(self):
174
174
175
175
def test_specified_path (self ):
176
176
# Make sure that specifying the location of the file to write to works.
177
- file_location ,info = self .urlretrieve ("http://www.example.com/" ,
177
+ file_location ,info = self .urlretrieve (test_support . TEST_HTTP_URL ,
178
178
test_support .TESTFN )
179
179
self .assertEqual (file_location , test_support .TESTFN )
180
180
self .assertTrue (os .path .exists (file_location ))
@@ -187,13 +187,13 @@ def test_specified_path(self):
187
187
188
188
def test_header (self ):
189
189
# Make sure header returned as 2nd value from urlretrieve is good.
190
- file_location , header = self .urlretrieve ("http://www.example.com/" )
190
+ file_location , header = self .urlretrieve (test_support . TEST_HTTP_URL )
191
191
os .unlink (file_location )
192
192
self .assertIsInstance (header , mimetools .Message ,
193
193
"header is not an instance of mimetools.Message" )
194
194
195
195
def test_data_header (self ):
196
- logo = "http://www.example.com/"
196
+ logo = test_support . TEST_HTTP_URL
197
197
file_location , fileheaders = self .urlretrieve (logo )
198
198
os .unlink (file_location )
199
199
datevalue = fileheaders .getheader ('Date' )
0 commit comments