Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3)

Side by Side Diff: Lib/test/test_robotparser.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_reprlib.py ('k') | Lib/test/test_runpy.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import io 1 import io
2 import unittest 2 import unittest
3 import urllib.robotparser 3 import urllib.robotparser
4 from urllib.error import URLError, HTTPError 4 from urllib.error import URLError
5 from urllib.request import urlopen
6 from test import support 5 from test import support
7 6
8 class RobotTestCase(unittest.TestCase): 7 class RobotTestCase(unittest.TestCase):
9 def __init__(self, index, parser, url, good, agent): 8 def __init__(self, index, parser, url, good, agent):
10 unittest.TestCase.__init__(self) 9 unittest.TestCase.__init__(self)
11 if good: 10 if good:
12 self.str = "RobotTest(%d, good, %s)" % (index, url) 11 self.str = "RobotTest(%d, good, %s)" % (index, url)
13 else: 12 else:
14 self.str = "RobotTest(%d, bad, %s)" % (index, url) 13 self.str = "RobotTest(%d, bad, %s)" % (index, url)
15 self.parser = parser 14 self.parser = parser
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 230
232 RobotTest(15, doc, good, bad) 231 RobotTest(15, doc, good, bad)
233 232
234 233
235 class NetworkTestCase(unittest.TestCase): 234 class NetworkTestCase(unittest.TestCase):
236 235
237 def testPasswordProtectedSite(self): 236 def testPasswordProtectedSite(self):
238 support.requires('network') 237 support.requires('network')
239 with support.transient_internet('mueblesmoraleda.com'): 238 with support.transient_internet('mueblesmoraleda.com'):
240 url = 'http://mueblesmoraleda.com' 239 url = 'http://mueblesmoraleda.com'
241 robots_url = url + "/robots.txt"
242 # First check the URL is usable for our purposes, since the
243 # test site is a bit flaky.
244 try:
245 urlopen(robots_url)
246 except HTTPError as e:
247 if e.code not in {401, 403}:
248 self.skipTest(
249 "%r should return a 401 or 403 HTTP error, not %r"
250 % (robots_url, e.code))
251 else:
252 self.skipTest(
253 "%r should return a 401 or 403 HTTP error, not succeed"
254 % (robots_url))
255 parser = urllib.robotparser.RobotFileParser() 240 parser = urllib.robotparser.RobotFileParser()
256 parser.set_url(url) 241 parser.set_url(url)
257 try: 242 try:
258 parser.read() 243 parser.read()
259 except URLError: 244 except URLError:
260 self.skipTest('%s is unavailable' % url) 245 self.skipTest('%s is unavailable' % url)
261 self.assertEqual(parser.can_fetch("*", robots_url), False) 246 self.assertEqual(parser.can_fetch("*", url+"/robots.txt"), False)
262 247
263 def testPythonOrg(self): 248 def testPythonOrg(self):
264 support.requires('network') 249 support.requires('network')
265 with support.transient_internet('www.python.org'): 250 with support.transient_internet('www.python.org'):
266 parser = urllib.robotparser.RobotFileParser( 251 parser = urllib.robotparser.RobotFileParser(
267 "http://www.python.org/robots.txt") 252 "http://www.python.org/robots.txt")
268 parser.read() 253 parser.read()
269 self.assertTrue( 254 self.assertTrue(
270 parser.can_fetch("*", "http://www.python.org/robots.txt")) 255 parser.can_fetch("*", "http://www.python.org/robots.txt"))
271 256
272 def test_main(): 257 def test_main():
273 support.run_unittest(NetworkTestCase) 258 support.run_unittest(NetworkTestCase)
274 support.run_unittest(tests) 259 support.run_unittest(tests)
275 260
276 if __name__=='__main__': 261 if __name__=='__main__':
277 support.verbose = 1 262 support.verbose = 1
278 test_main() 263 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_reprlib.py ('k') | Lib/test/test_runpy.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+