def test_comparison(self): """ L{FirstError} instances compare equal to each other if and only if their failure and index compare equal. L{FirstError} instances do not compare equal to instances of other types. """ try: 1 / 0 except: firstFailure = failure.Failure() one = defer.FirstError(firstFailure, 13) anotherOne = defer.FirstError(firstFailure, 13) try: raise ValueError("bar") except: secondFailure = failure.Failure() another = defer.FirstError(secondFailure, 9) self.assertTrue(one == anotherOne) self.assertFalse(one == another) self.assertTrue(one != another) self.assertFalse(one != anotherOne) self.assertFalse(one == 10)
def _dlistIgnoreSomeErrors(ls): res = [] for success, value in ls: if success: res.append(value) if res: return res else: # there is nothing but errors # return first error, other errors will be logged by Deferred.__del__ raise defer.FirstError(ls[0][1], 0)
def test_indexingFirstError(self): """ L{FirstError} behaves a little like a tuple, for backwards compatibility. Test that it can actually be indexed to retrieve information about the failure. """ subFailure = object() index = object() firstError = defer.FirstError(subFailure, index) self.assertIdentical(firstError[0], firstError.subFailure) self.assertIdentical(firstError[1], firstError.index)
def test_str(self): """ The str of a L{FirstError} instance includes the str of the sub-failure and the index which corresponds to the L{FirstError}. """ exc = ValueError("some text") try: raise exc except: f = failure.Failure() error = defer.FirstError(f, 5) self.assertEqual(str(error), "FirstError[#5, %s]" % (str(f), ))