From d87bfa9eb2046fe9a6395039e29074e27b1ad26e Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Wed, 6 Feb 2008 16:41:04 -0700 Subject: [PATCH] test_util: add full coverage for allmydata.util.deferredutil --- src/allmydata/test/test_util.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/allmydata/test/test_util.py b/src/allmydata/test/test_util.py index b59e47a2..116fcbcc 100644 --- a/src/allmydata/test/test_util.py +++ b/src/allmydata/test/test_util.py @@ -3,9 +3,11 @@ def foo(): pass # keep the line number constant import os from twisted.trial import unittest +from twisted.internet import defer +from twisted.python import failure from allmydata.util import bencode, idlib, humanreadable, mathutil -from allmydata.util import assertutil, fileutil, testutil +from allmydata.util import assertutil, fileutil, testutil, deferredutil class IDLib(unittest.TestCase): @@ -396,3 +398,32 @@ class PollMixinTests(unittest.TestCase): return None # success d.addCallbacks(_suc, _err) return d + +class DeferredUtilTests(unittest.TestCase): + def test_success(self): + d1, d2 = defer.Deferred(), defer.Deferred() + good = [] + bad = [] + dlss = deferredutil.DeferredListShouldSucceed([d1,d2]) + dlss.addCallbacks(good.append, bad.append) + d1.callback(1) + d2.callback(2) + self.failUnlessEqual(good, [[1,2]]) + self.failUnlessEqual(bad, []) + + def test_failure(self): + d1, d2 = defer.Deferred(), defer.Deferred() + good = [] + bad = [] + dlss = deferredutil.DeferredListShouldSucceed([d1,d2]) + dlss.addCallbacks(good.append, bad.append) + d1.addErrback(lambda _ignore: None) + d2.addErrback(lambda _ignore: None) + d1.callback(1) + d2.errback(RuntimeError()) + self.failUnlessEqual(good, []) + self.failUnlessEqual(len(bad), 1) + f = bad[0] + self.failUnless(isinstance(f, failure.Failure)) + self.failUnless(f.check(RuntimeError)) + -- 2.45.2