]> granicus.if.org Git - python/commitdiff
Avoid failing in test_robotparser when mueblesmoraleda.com is flaky and
authorAntoine Pitrou <solipsis@pitrou.net>
Fri, 8 Jul 2011 17:40:15 +0000 (19:40 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Fri, 8 Jul 2011 17:40:15 +0000 (19:40 +0200)
an overzealous DNS service (e.g. OpenDNS) redirects to a placeholder
Web site.

Lib/test/test_robotparser.py
Misc/NEWS

index 3376a8a3cb4b79ee55e6c91f8097b822c2bfaa52..b3d4a46056bb0d03d1d218c43b9185ee7daaea8b 100644 (file)
@@ -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')
index f7d12fc1d01ab679ca5df9522213f6670b1412ff..9607a4dc79ace64b50d8deeadc8082d7bc052f5c 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -92,6 +92,10 @@ Build
 Tests
 -----
 
+- Avoid failing in test_robotparser when mueblesmoraleda.com is flaky and
+  an overzealous DNS service (e.g. OpenDNS) redirects to a placeholder
+  Web site.
+
 - Avoid failing in test_urllibnet.test_bad_address when some overzealous
   DNS service (e.g. OpenDNS) resolves a non-existent domain name.  The test
   is now skipped instead.