diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2011-07-08 19:40:15 +0200 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2011-07-08 19:40:15 +0200 |
commit | 2960308c0c4e2a669e19dcb1a0d20184571f5a29 (patch) | |
tree | 5c61a00f254061869e0d49a8beab1db1350cd45d /Lib/test/test_robotparser.py | |
parent | a4d58d26a187a73b66253c888ccea048f45fec0d (diff) | |
download | cpython-git-2960308c0c4e2a669e19dcb1a0d20184571f5a29.tar.gz |
Avoid failing in test_robotparser when mueblesmoraleda.com is flaky and
an overzealous DNS service (e.g. OpenDNS) redirects to a placeholder
Web site.
Diffstat (limited to 'Lib/test/test_robotparser.py')
-rw-r--r-- | Lib/test/test_robotparser.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/Lib/test/test_robotparser.py b/Lib/test/test_robotparser.py index 3376a8a3cb..b3d4a46056 100644 --- a/Lib/test/test_robotparser.py +++ b/Lib/test/test_robotparser.py @@ -1,5 +1,6 @@ import unittest, StringIO, robotparser from test import test_support +from urllib2 import urlopen, HTTPError class RobotTestCase(unittest.TestCase): def __init__(self, index, parser, url, good, agent): @@ -234,13 +235,27 @@ class NetworkTestCase(unittest.TestCase): test_support.requires('network') with test_support.transient_internet('mueblesmoraleda.com'): url = 'http://mueblesmoraleda.com' + robots_url = url + "/robots.txt" + # First check the URL is usable for our purposes, since the + # test site is a bit flaky. + try: + urlopen(robots_url) + except HTTPError as e: + if e.code not in {401, 403}: + self.skipTest( + "%r should return a 401 or 403 HTTP error, not %r" + % (robots_url, e.code)) + else: + self.skipTest( + "%r should return a 401 or 403 HTTP error, not succeed" + % (robots_url)) parser = robotparser.RobotFileParser() parser.set_url(url) try: parser.read() except IOError: self.skipTest('%s is unavailable' % url) - self.assertEqual(parser.can_fetch("*", url+"/robots.txt"), False) + self.assertEqual(parser.can_fetch("*", robots_url), False) def testPythonOrg(self): test_support.requires('network') |