From 1e6fc4601ecc1f8228bbd1230821db5e03f692d7 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sat, 26 Sep 2015 17:59:39 -0700 Subject: [PATCH] tests: split common code out --- src/wormhole/test/common.py | 23 +++++++++++++++++++++++ src/wormhole/test/test_twisted.py | 24 +----------------------- 2 files changed, 24 insertions(+), 23 deletions(-) create mode 100644 src/wormhole/test/common.py diff --git a/src/wormhole/test/common.py b/src/wormhole/test/common.py new file mode 100644 index 0000000..98b2987 --- /dev/null +++ b/src/wormhole/test/common.py @@ -0,0 +1,23 @@ +from twisted.application import service +from ..twisted.util import allocate_ports +from ..servers.relay import RelayServer +from .. import __version__ + +class ServerBase: + def setUp(self): + self.sp = service.MultiService() + self.sp.startService() + d = allocate_ports() + def _got_ports(ports): + relayport, transitport = ports + s = RelayServer("tcp:%d:interface=127.0.0.1" % relayport, + "tcp:%s:interface=127.0.0.1" % transitport, + __version__) + s.setServiceParent(self.sp) + self.relayurl = "http://127.0.0.1:%d/wormhole-relay/" % relayport + self.transit = "tcp:127.0.0.1:%d" % transitport + d.addCallback(_got_ports) + return d + + def tearDown(self): + return self.sp.stopService() diff --git a/src/wormhole/test/test_twisted.py b/src/wormhole/test/test_twisted.py index 8e267fc..f459853 100644 --- a/src/wormhole/test/test_twisted.py +++ b/src/wormhole/test/test_twisted.py @@ -2,35 +2,13 @@ import json from twisted.trial import unittest from twisted.internet import defer from twisted.internet.threads import deferToThread -from twisted.application import service -from ..servers.relay import RelayServer from ..twisted.transcribe import Wormhole, UsageError -from ..twisted.util import allocate_ports from ..blocking.transcribe import Wormhole as BlockingWormhole -from .. import __version__ +from .common import ServerBase #from twisted.python import log #import sys #log.startLogging(sys.stdout) -class ServerBase: - def setUp(self): - self.sp = service.MultiService() - self.sp.startService() - d = allocate_ports() - def _got_ports(ports): - relayport, transitport = ports - s = RelayServer("tcp:%d:interface=127.0.0.1" % relayport, - "tcp:%s:interface=127.0.0.1" % transitport, - __version__) - s.setServiceParent(self.sp) - self.relayurl = "http://127.0.0.1:%d/wormhole-relay/" % relayport - self.transit = "tcp:127.0.0.1:%d" % transitport - d.addCallback(_got_ports) - return d - - def tearDown(self): - return self.sp.stopService() - class Basic(ServerBase, unittest.TestCase): def test_basic(self): appid = "appid"