Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
033ae055
Commit
033ae055
authored
Apr 29, 2003
by
Brett Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added tests for urlretrieve. Also made sure urlopen tests cleaned up properly after themselves.
parent
94609b66
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
8 deletions
+48
-8
Lib/test/test_urllib.py
Lib/test/test_urllib.py
+48
-8
No files found.
Lib/test/test_urllib.py
View file @
033ae055
...
...
@@ -35,6 +35,7 @@ class urlopen_FileTests(unittest.TestCase):
def
tearDown
(
self
):
"""Shut down the open object"""
self
.
returned_obj
.
close
()
os
.
remove
(
test_support
.
TESTFN
)
def
test_interface
(
self
):
# Make sure object returned by urlopen() has the specified methods
...
...
@@ -87,16 +88,54 @@ class urlopen_FileTests(unittest.TestCase):
for
line
in
self
.
returned_obj
.
__iter__
():
self
.
assertEqual
(
line
,
self
.
text
)
class
urlretrieve_Tests
(
unittest
.
TestCase
):
class
urlretrieve_
File
Tests
(
unittest
.
TestCase
):
"""Test urllib.urlretrieve() on local files"""
pass
class
_urlopener_Tests
(
unittest
.
TestCase
):
"""Make sure urlopen() and urlretrieve() use the class assigned to
_urlopener"""
#XXX: Maybe create a custom class here that takes in a list and modifies
# it to signal that it was called?
pass
def
setUp
(
self
):
# Create a temporary file.
self
.
text
=
'testing urllib.urlretrieve'
FILE
=
file
(
test_support
.
TESTFN
,
'wb'
)
FILE
.
write
(
self
.
text
)
FILE
.
close
()
def
tearDown
(
self
):
# Delete the temporary file.
os
.
remove
(
test_support
.
TESTFN
)
def
test_basic
(
self
):
# Make sure that a local file just gets its own location returned and
# a headers value is returned.
result
=
urllib
.
urlretrieve
(
"file:%s"
%
test_support
.
TESTFN
)
self
.
assertEqual
(
result
[
0
],
test_support
.
TESTFN
)
self
.
assert_
(
isinstance
(
result
[
1
],
mimetools
.
Message
),
"did not get a mimetools.Message instance as second "
"returned value"
)
def
test_copy
(
self
):
# Test that setting the filename argument works.
second_temp
=
"%s.2"
%
test_support
.
TESTFN
result
=
urllib
.
urlretrieve
(
"file:%s"
%
test_support
.
TESTFN
,
second_temp
)
self
.
assertEqual
(
second_temp
,
result
[
0
])
self
.
assert_
(
os
.
path
.
exists
(
second_temp
),
"copy of the file was not "
"made"
)
FILE
=
file
(
second_temp
,
'rb'
)
try
:
text
=
FILE
.
read
()
finally
:
FILE
.
close
()
self
.
assertEqual
(
self
.
text
,
text
)
def
test_reporthook
(
self
):
# Make sure that the reporthook works.
def
hooktester
(
count
,
block_size
,
total_size
,
count_holder
=
[
0
]):
self
.
assert_
(
isinstance
(
count
,
int
))
self
.
assert_
(
isinstance
(
block_size
,
int
))
self
.
assert_
(
isinstance
(
total_size
,
int
))
self
.
assertEqual
(
count
,
count_holder
[
0
])
count_holder
[
0
]
=
count_holder
[
0
]
+
1
second_temp
=
"%s.2"
%
test_support
.
TESTFN
urllib
.
urlretrieve
(
test_support
.
TESTFN
,
second_temp
,
hooktester
)
os
.
remove
(
second_temp
)
class
QuotingTests
(
unittest
.
TestCase
):
"""Tests for urllib.quote() and urllib.quote_plus()
...
...
@@ -371,6 +410,7 @@ class Pathname_Tests(unittest.TestCase):
def test_main():
test_suite = unittest.TestSuite()
test_suite.addTest(unittest.makeSuite(urlopen_FileTests))
test_suite.addTest(unittest.makeSuite(urlretrieve_FileTests))
test_suite.addTest(unittest.makeSuite(QuotingTests))
test_suite.addTest(unittest.makeSuite(UnquotingTests))
test_suite.addTest(unittest.makeSuite(urlencode_Tests))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment