From 5ae1c2d0205481a0e0ff035a72a6c8f394d2cad6 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 28 Sep 2015 16:44:00 -0700 Subject: [PATCH] tests: switch to defer.gatherResults --- src/wormhole/test/test_blocking.py | 23 +++++++---------------- src/wormhole/test/test_twisted.py | 23 +++++++---------------- 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/src/wormhole/test/test_blocking.py b/src/wormhole/test/test_blocking.py index 2a53cd3..c3ab7b9 100644 --- a/src/wormhole/test/test_blocking.py +++ b/src/wormhole/test/test_blocking.py @@ -1,6 +1,6 @@ import json from twisted.trial import unittest -from twisted.internet import defer +from twisted.internet.defer import gatherResults from twisted.internet.threads import deferToThread from ..blocking.transcribe import Wormhole as BlockingWormhole, UsageError from .common import ServerBase @@ -18,13 +18,10 @@ class Blocking(ServerBase, unittest.TestCase): w2.set_code(code) d1 = deferToThread(w1.get_data, b"data1") d2 = deferToThread(w2.get_data, b"data2") - return defer.DeferredList([d1,d2], fireOnOneErrback=False) + return gatherResults([d1,d2], True) d.addCallback(_got_code) def _done(dl): - ((success1, dataX), (success2, dataY)) = dl - r1,r2 = dl - self.assertTrue(success1, dataX) - self.assertTrue(success2, dataY) + (dataX, dataY) = dl self.assertEqual(dataX, b"data2") self.assertEqual(dataY, b"data1") d.addCallback(_done) @@ -38,12 +35,9 @@ class Blocking(ServerBase, unittest.TestCase): w2.set_code("123-purple-elephant") d1 = deferToThread(w1.get_data, b"data1") d2 = deferToThread(w2.get_data, b"data2") - d = defer.DeferredList([d1,d2], fireOnOneErrback=False) + d = gatherResults([d1,d2], True) def _done(dl): - ((success1, dataX), (success2, dataY)) = dl - r1,r2 = dl - self.assertTrue(success1, dataX) - self.assertTrue(success2, dataY) + (dataX, dataY) = dl self.assertEqual(dataX, b"data2") self.assertEqual(dataY, b"data1") d.addCallback(_done) @@ -81,13 +75,10 @@ class Blocking(ServerBase, unittest.TestCase): new_w1 = BlockingWormhole.from_serialized(s) d1 = deferToThread(new_w1.get_data, b"data1") d2 = deferToThread(w2.get_data, b"data2") - return defer.DeferredList([d1,d2], fireOnOneErrback=False) + return gatherResults([d1,d2], True) d.addCallback(_got_code) def _done(dl): - ((success1, dataX), (success2, dataY)) = dl - r1,r2 = dl - self.assertTrue(success1, dataX) - self.assertTrue(success2, dataY) + (dataX, dataY) = dl self.assertEqual(dataX, b"data2") self.assertEqual(dataY, b"data1") self.assertRaises(UsageError, w2.serialize) # too late diff --git a/src/wormhole/test/test_twisted.py b/src/wormhole/test/test_twisted.py index 70137d4..f0c6680 100644 --- a/src/wormhole/test/test_twisted.py +++ b/src/wormhole/test/test_twisted.py @@ -1,6 +1,6 @@ import sys, json from twisted.trial import unittest -from twisted.internet import defer +from twisted.internet.defer import gatherResults from ..twisted.transcribe import Wormhole, UsageError from .common import ServerBase @@ -14,13 +14,10 @@ class Basic(ServerBase, unittest.TestCase): w2.set_code(code) d1 = w1.get_data(b"data1") d2 = w2.get_data(b"data2") - return defer.DeferredList([d1,d2], fireOnOneErrback=False) + return gatherResults([d1,d2], True) d.addCallback(_got_code) def _done(dl): - ((success1, dataX), (success2, dataY)) = dl - r1,r2 = dl - self.assertTrue(success1, dataX) - self.assertTrue(success2, dataY) + (dataX, dataY) = dl self.assertEqual(dataX, b"data2") self.assertEqual(dataY, b"data1") d.addCallback(_done) @@ -34,12 +31,9 @@ class Basic(ServerBase, unittest.TestCase): w2.set_code("123-purple-elephant") d1 = w1.get_data(b"data1") d2 = w2.get_data(b"data2") - d = defer.DeferredList([d1,d2], fireOnOneErrback=False) + d = gatherResults([d1,d2], True) def _done(dl): - ((success1, dataX), (success2, dataY)) = dl - r1,r2 = dl - self.assertTrue(success1, dataX) - self.assertTrue(success2, dataY) + (dataX, dataY) = dl self.assertEqual(dataX, b"data2") self.assertEqual(dataY, b"data1") d.addCallback(_done) @@ -75,13 +69,10 @@ class Basic(ServerBase, unittest.TestCase): new_w1 = Wormhole.from_serialized(s) d1 = new_w1.get_data(b"data1") d2 = w2.get_data(b"data2") - return defer.DeferredList([d1,d2], fireOnOneErrback=False) + return gatherResults([d1,d2], True) d.addCallback(_got_code) def _done(dl): - ((success1, dataX), (success2, dataY)) = dl - r1,r2 = dl - self.assertTrue(success1, dataX) - self.assertTrue(success2, dataY) + (dataX, dataY) = dl self.assertEqual(dataX, b"data2") self.assertEqual(dataY, b"data1") self.assertRaises(UsageError, w2.serialize) # too late