Backport some robotparser test and skip the test if the external resource is not available.

This commit is contained in:
Florent Xicluna 2010-04-02 17:26:42 +00:00
parent d54e699cba
commit f37592fda1
1 changed files with 18 additions and 5 deletions

View File

@ -203,19 +203,32 @@ RobotTest(13, doc, good, bad, agent="googlebot")
class TestCase(unittest.TestCase): class NetworkTestCase(unittest.TestCase):
def runTest(self):
def testPasswordProtectedSite(self):
test_support.requires('network') test_support.requires('network')
# whole site is password-protected. # XXX it depends on an external resource which could be unavailable
url = 'http://mueblesmoraleda.com' url = 'http://mueblesmoraleda.com'
parser = robotparser.RobotFileParser() parser = robotparser.RobotFileParser()
parser.set_url(url) parser.set_url(url)
parser.read() 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("*", url+"/robots.txt"), False)
def testPythonOrg(self):
test_support.requires('network')
parser = robotparser.RobotFileParser(
"http://www.python.org/robots.txt")
parser.read()
self.assertTrue(parser.can_fetch("*",
"http://www.python.org/robots.txt"))
def test_main(): def test_main():
test_support.run_unittest(tests) test_support.run_unittest(tests)
TestCase().run() test_support.run_unittest(NetworkTestCase)
if __name__=='__main__': if __name__=='__main__':
test_support.verbose = 1 test_support.verbose = 1