def run_fetcher_tests(server): exc_fetchers = [] for klass, library_name in [ (fetchers.Urllib2Fetcher, 'urllib2'), (fetchers.CurlHTTPFetcher, 'pycurl'), (fetchers.HTTPLib2Fetcher, 'httplib2'), ]: try: exc_fetchers.append(klass()) except RuntimeError as why: if str(why).startswith('Cannot find %s library' % (library_name, )): try: __import__(library_name) except ImportError: raise unittest.SkipTest( 'Skipping tests for %r fetcher because ' 'the library did not import.' % (library_name, )) else: assert False, ('%s present but not detected' % (library_name, )) else: raise non_exc_fetchers = [] for f in exc_fetchers: non_exc_fetchers.append(fetchers.ExceptionWrappingFetcher(f)) for f in exc_fetchers: test_fetcher(f, True, server) for f in non_exc_fetchers: test_fetcher(f, False, server)
class TestSilencedUrllib2Fetcher(TestUrllib2Fetcher): """Test silenced `Urllib2Fetcher` class.""" fetcher = fetchers.ExceptionWrappingFetcher(fetchers.Urllib2Fetcher()) invalid_url_error = fetchers.HTTPFetchingError
try: __import__(library_name) except ImportError: warnings.warn('Skipping tests for %r fetcher because ' 'the library did not import.' % (library_name, )) pass else: assert False, ('%s present but not detected' % (library_name, )) else: raise non_exc_fetchers = [] for f in exc_fetchers: non_exc_fetchers.append(fetchers.ExceptionWrappingFetcher(f)) for f in exc_fetchers: test_fetcher(f, True, server) for f in non_exc_fetchers: test_fetcher(f, False, server) from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer class FetcherTestHandler(BaseHTTPRequestHandler): cases = { '/success': (200, None), '/301redirect': (301, '/success'),