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
43408ae4
Commit
43408ae4
authored
Sep 18, 2016
by
Berker Peksag
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #28151: Use pythontest.net in test_robotparser
parent
d614d687
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
7 deletions
+36
-7
Lib/test/test_robotparser.py
Lib/test/test_robotparser.py
+36
-7
No files found.
Lib/test/test_robotparser.py
View file @
43408ae4
import
io
import
os
import
unittest
import
urllib.robotparser
from
collections
import
namedtuple
...
...
@@ -272,14 +273,42 @@ class PasswordProtectedSiteTestCase(unittest.TestCase):
class
NetworkTestCase
(
unittest
.
TestCase
):
def
testPythonOrg
(
self
):
base_url
=
'http://www.pythontest.net/'
robots_txt
=
'{}elsewhere/robots.txt'
.
format
(
base_url
)
@
classmethod
def
setUpClass
(
cls
):
support
.
requires
(
'network'
)
with
support
.
transient_internet
(
'www.python.org'
):
parser
=
urllib
.
robotparser
.
RobotFileParser
(
"http://www.python.org/robots.txt"
)
parser
.
read
()
self
.
assertTrue
(
parser
.
can_fetch
(
"*"
,
"http://www.python.org/robots.txt"
))
with
support
.
transient_internet
(
cls
.
base_url
):
cls
.
parser
=
urllib
.
robotparser
.
RobotFileParser
(
cls
.
robots_txt
)
cls
.
parser
.
read
()
def
url
(
self
,
path
):
return
'{}{}{}'
.
format
(
self
.
base_url
,
path
,
'/'
if
not
os
.
path
.
splitext
(
path
)[
1
]
else
''
)
def
test_basic
(
self
):
self
.
assertFalse
(
self
.
parser
.
disallow_all
)
self
.
assertFalse
(
self
.
parser
.
allow_all
)
self
.
assertGreater
(
self
.
parser
.
mtime
(),
0
)
self
.
assertFalse
(
self
.
parser
.
crawl_delay
(
'*'
))
self
.
assertFalse
(
self
.
parser
.
request_rate
(
'*'
))
def
test_can_fetch
(
self
):
self
.
assertTrue
(
self
.
parser
.
can_fetch
(
'*'
,
self
.
url
(
'elsewhere'
)))
self
.
assertFalse
(
self
.
parser
.
can_fetch
(
'Nutch'
,
self
.
base_url
))
self
.
assertFalse
(
self
.
parser
.
can_fetch
(
'Nutch'
,
self
.
url
(
'brian'
)))
self
.
assertFalse
(
self
.
parser
.
can_fetch
(
'Nutch'
,
self
.
url
(
'webstats'
)))
self
.
assertFalse
(
self
.
parser
.
can_fetch
(
'*'
,
self
.
url
(
'webstats'
)))
self
.
assertTrue
(
self
.
parser
.
can_fetch
(
'*'
,
self
.
base_url
))
def
test_read_404
(
self
):
parser
=
urllib
.
robotparser
.
RobotFileParser
(
self
.
url
(
'i-robot.txt'
))
parser
.
read
()
self
.
assertTrue
(
parser
.
allow_all
)
self
.
assertFalse
(
parser
.
disallow_all
)
self
.
assertEqual
(
parser
.
mtime
(),
0
)
if
__name__
==
'__main__'
:
unittest
.
main
()
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