From 429c5cd962e3fff7ac0f455433bea8b057c5c9d3 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Mon, 28 Sep 2015 16:52:12 -0700 Subject: [PATCH] tests: clean up pairs-of-Deferreds patterns --- src/wormhole/test/test_blocking.py | 15 ++++++--------- src/wormhole/test/test_twisted.py | 15 ++++++--------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/wormhole/test/test_blocking.py b/src/wormhole/test/test_blocking.py index c1a4c37..6e0554f 100644 --- a/src/wormhole/test/test_blocking.py +++ b/src/wormhole/test/test_blocking.py @@ -16,9 +16,8 @@ class Blocking(ServerBase, unittest.TestCase): d = deferToThread(w1.get_code) def _got_code(code): w2.set_code(code) - d1 = deferToThread(w1.get_data, b"data1") - d2 = deferToThread(w2.get_data, b"data2") - return gatherResults([d1,d2], True) + return gatherResults([deferToThread(w1.get_data, b"data1"), + deferToThread(w2.get_data, b"data2")], True) d.addCallback(_got_code) def _done(dl): (dataX, dataY) = dl @@ -33,9 +32,8 @@ class Blocking(ServerBase, unittest.TestCase): w2 = BlockingWormhole(appid, self.relayurl) w1.set_code("123-purple-elephant") w2.set_code("123-purple-elephant") - d1 = deferToThread(w1.get_data, b"data1") - d2 = deferToThread(w2.get_data, b"data2") - d = gatherResults([d1,d2], True) + d = gatherResults([deferToThread(w1.get_data, b"data1"), + deferToThread(w2.get_data, b"data2")], True) def _done(dl): (dataX, dataY) = dl self.assertEqual(dataX, b"data2") @@ -114,9 +112,8 @@ class Blocking(ServerBase, unittest.TestCase): unpacked = json.loads(s) # this is supposed to be JSON self.assertEqual(type(unpacked), dict) new_w1 = BlockingWormhole.from_serialized(s) - d1 = deferToThread(new_w1.get_data, b"data1") - d2 = deferToThread(w2.get_data, b"data2") - return gatherResults([d1,d2], True) + return gatherResults([deferToThread(new_w1.get_data, b"data1"), + deferToThread(w2.get_data, b"data2")], True) d.addCallback(_got_code) def _done(dl): (dataX, dataY) = dl diff --git a/src/wormhole/test/test_twisted.py b/src/wormhole/test/test_twisted.py index cfa375c..676a2d0 100644 --- a/src/wormhole/test/test_twisted.py +++ b/src/wormhole/test/test_twisted.py @@ -12,9 +12,8 @@ class Basic(ServerBase, unittest.TestCase): d = w1.get_code() def _got_code(code): w2.set_code(code) - d1 = w1.get_data(b"data1") - d2 = w2.get_data(b"data2") - return gatherResults([d1,d2], True) + return gatherResults([w1.get_data(b"data1"), + w2.get_data(b"data2")], True) d.addCallback(_got_code) def _done(dl): (dataX, dataY) = dl @@ -29,9 +28,8 @@ class Basic(ServerBase, unittest.TestCase): w2 = Wormhole(appid, self.relayurl) w1.set_code("123-purple-elephant") w2.set_code("123-purple-elephant") - d1 = w1.get_data(b"data1") - d2 = w2.get_data(b"data2") - d = gatherResults([d1,d2], True) + d = gatherResults([w1.get_data(b"data1"), + w2.get_data(b"data2")], True) def _done(dl): (dataX, dataY) = dl self.assertEqual(dataX, b"data2") @@ -106,9 +104,8 @@ class Basic(ServerBase, unittest.TestCase): unpacked = json.loads(s) # this is supposed to be JSON self.assertEqual(type(unpacked), dict) new_w1 = Wormhole.from_serialized(s) - d1 = new_w1.get_data(b"data1") - d2 = w2.get_data(b"data2") - return gatherResults([d1,d2], True) + return gatherResults([new_w1.get_data(b"data1"), + w2.get_data(b"data2")], True) d.addCallback(_got_code) def _done(dl): (dataX, dataY) = dl