[Python-checkins] cpython (3.2): Avoid failing in test_robotparser when mueblesmoraleda.com is flaky and
antoine.pitrou
python-checkins at python.org
Fri Jul 8 19:45:51 CEST 2011
http://hg.python.org/cpython/rev/6e72490bbff6
changeset: 71261:6e72490bbff6
branch: 3.2
parent: 71258:6adab7448272
user: Antoine Pitrou <solipsis at pitrou.net>
date: Fri Jul 08 19:43:51 2011 +0200
summary:
Avoid failing in test_robotparser when mueblesmoraleda.com is flaky and
an overzealous DNS service (e.g. OpenDNS) redirects to a placeholder
Web site.
files:
Lib/test/test_robotparser.py | 19 +++++++++++++++++--
Misc/NEWS | 4 ++++
2 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/Lib/test/test_robotparser.py b/Lib/test/test_robotparser.py
--- a/Lib/test/test_robotparser.py
+++ b/Lib/test/test_robotparser.py
@@ -1,7 +1,8 @@
import io
import unittest
import urllib.robotparser
-from urllib.error import URLError
+from urllib.error import URLError, HTTPError
+from urllib.request import urlopen
from test import support
class RobotTestCase(unittest.TestCase):
@@ -237,13 +238,27 @@
support.requires('network')
with 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 = urllib.robotparser.RobotFileParser()
parser.set_url(url)
try:
parser.read()
except URLError:
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):
support.requires('network')
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -47,6 +47,10 @@
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.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list