Avoid failing in test_robotparser when mueblesmoraleda.com is flaky and

an overzealous DNS service (e.g. OpenDNS) redirects to a placeholder
Web site.
This commit is contained in:
Antoine Pitrou 2011-07-08 19:44:55 +02:00
commit 4a183b47f3
2 changed files with 21 additions and 2 deletions

View File

@ -1,7 +1,8 @@
import io import io
import unittest import unittest
import urllib.robotparser import urllib.robotparser
from urllib.error import URLError from urllib.error import URLError, HTTPError
from urllib.request import urlopen
from test import support from test import support
class RobotTestCase(unittest.TestCase): class RobotTestCase(unittest.TestCase):
@ -237,13 +238,27 @@ class NetworkTestCase(unittest.TestCase):
support.requires('network') support.requires('network')
with support.transient_internet('mueblesmoraleda.com'): with support.transient_internet('mueblesmoraleda.com'):
url = 'http://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 = urllib.robotparser.RobotFileParser()
parser.set_url(url) parser.set_url(url)
try: try:
parser.read() parser.read()
except URLError: except URLError:
self.skipTest('%s is unavailable' % url) 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): def testPythonOrg(self):
support.requires('network') support.requires('network')

View File

@ -1004,6 +1004,10 @@ Extension Modules
Tests 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 - Avoid failing in test_urllibnet.test_bad_address when some overzealous
DNS service (e.g. OpenDNS) resolves a non-existent domain name. The test DNS service (e.g. OpenDNS) resolves a non-existent domain name. The test
is now skipped instead. is now skipped instead.