def test_wrappedByDefault(self): """Make sure that the default fetcher instance wraps exceptions by default""" default_fetcher = fetchers.getDefaultFetcher() self.failUnless(isinstance(default_fetcher, fetchers.ExceptionWrappingFetcher), default_fetcher) self.failUnlessRaises(fetchers.HTTPFetchingError, fetchers.fetch, 'http://invalid.janrain.com/')
def test_wrappedByDefault(self): """Make sure that the default fetcher instance wraps exceptions by default""" default_fetcher = fetchers.getDefaultFetcher() self.failUnless( isinstance(default_fetcher, fetchers.ExceptionWrappingFetcher), default_fetcher) self.failUnlessRaises(fetchers.HTTPFetchingError, fetchers.fetch, 'http://invalid.janrain.com/')
def test_notWrapped(self): """Make sure that if we set a non-wrapped fetcher as default, it will not wrap exceptions.""" # A fetcher that will raise an exception when it encounters a # host that will not resolve fetcher = fetchers.Urllib2Fetcher() fetchers.setDefaultFetcher(fetcher, wrap_exceptions=False) self.failIf(isinstance(fetchers.getDefaultFetcher(), fetchers.ExceptionWrappingFetcher)) try: fetchers.fetch('http://invalid.janrain.com/') except fetchers.HTTPFetchingError: self.fail('Should not be wrapping exception') except: exc = sys.exc_info()[1] self.failUnless(isinstance(exc, urllib2.URLError), exc) pass else: self.fail('Should have raised an exception')
def test_notWrapped(self): """Make sure that if we set a non-wrapped fetcher as default, it will not wrap exceptions.""" # A fetcher that will raise an exception when it encounters a # host that will not resolve fetcher = fetchers.Urllib2Fetcher() fetchers.setDefaultFetcher(fetcher, wrap_exceptions=False) self.failIf( isinstance(fetchers.getDefaultFetcher(), fetchers.ExceptionWrappingFetcher)) try: fetchers.fetch('http://invalid.janrain.com/') except fetchers.HTTPFetchingError: self.fail('Should not be wrapping exception') except: exc = sys.exc_info()[1] self.failUnless(isinstance(exc, urllib2.URLError), exc) pass else: self.fail('Should have raised an exception')
def setUp(self): self.oldfetcher = fetchers.getDefaultFetcher() fetchers.setDefaultFetcher(self.MockFetcher())
def test_setDefault(self): """Make sure the getDefaultFetcher returns the object set for setDefaultFetcher""" sentinel = object() fetchers.setDefaultFetcher(sentinel, wrap_exceptions=False) self.failUnless(fetchers.getDefaultFetcher() is sentinel)
def test_getDefaultNotNone(self): """Make sure that None is never returned as a default fetcher""" self.failUnless(fetchers.getDefaultFetcher() is not None) fetchers.setDefaultFetcher(None) self.failUnless(fetchers.getDefaultFetcher() is not None)