mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-23 02:32:42 +00:00
Factor plugin helper behavior into its own fixture
This commit is contained in:
parent
25287870ee
commit
9608404b6e
@ -80,6 +80,37 @@ from .eliotutil import (
|
|||||||
|
|
||||||
TEST_RSA_KEY_SIZE = 522
|
TEST_RSA_KEY_SIZE = 522
|
||||||
|
|
||||||
|
|
||||||
|
class UseTestPlugins(object):
|
||||||
|
"""
|
||||||
|
A fixture which enables loading Twisted plugins from the Tahoe-LAFS test
|
||||||
|
suite.
|
||||||
|
"""
|
||||||
|
def setUp(self):
|
||||||
|
"""
|
||||||
|
Add the testing package ``plugins`` directory to the ``twisted.plugins``
|
||||||
|
aggregate package.
|
||||||
|
"""
|
||||||
|
import twisted.plugins
|
||||||
|
testplugins = FilePath(__file__).sibling("plugins")
|
||||||
|
twisted.plugins.__path__.insert(0, testplugins.path)
|
||||||
|
|
||||||
|
|
||||||
|
def cleanUp(self):
|
||||||
|
"""
|
||||||
|
Remove the testing package ``plugins`` directory from the
|
||||||
|
``twisted.plugins`` aggregate package.
|
||||||
|
"""
|
||||||
|
import twisted.plugins
|
||||||
|
testplugins = FilePath(__file__).sibling("plugins")
|
||||||
|
twisted.plugins.__path__.remove(testplugins.path)
|
||||||
|
|
||||||
|
|
||||||
|
def getDetails(self):
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@implementer(IPlugin, IStreamServerEndpointStringParser)
|
@implementer(IPlugin, IStreamServerEndpointStringParser)
|
||||||
class AdoptedServerPort(object):
|
class AdoptedServerPort(object):
|
||||||
"""
|
"""
|
||||||
@ -135,23 +166,17 @@ class SameProcessStreamEndpointAssigner(object):
|
|||||||
"""
|
"""
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self._cleanups = []
|
self._cleanups = []
|
||||||
|
# Make sure the `adopt-socket` endpoint is recognized. We do this
|
||||||
|
# instead of providing a dropin because we don't want to make this
|
||||||
|
# endpoint available to random other applications.
|
||||||
|
f = UseTestPlugins()
|
||||||
|
f.setUp()
|
||||||
|
self._cleanups.append(f.cleanUp)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
for c in self._cleanups:
|
for c in self._cleanups:
|
||||||
c()
|
c()
|
||||||
|
|
||||||
def _patch_plugins(self):
|
|
||||||
"""
|
|
||||||
Add the testing package ``plugins`` directory to the ``twisted.plugins``
|
|
||||||
aggregate package. Arrange for it to be removed again when the
|
|
||||||
fixture is torn down.
|
|
||||||
"""
|
|
||||||
import twisted.plugins
|
|
||||||
testplugins = FilePath(__file__).sibling("plugins")
|
|
||||||
twisted.plugins.__path__.insert(0, testplugins.path)
|
|
||||||
self._cleanups.append(lambda: twisted.plugins.__path__.remove(testplugins.path))
|
|
||||||
|
|
||||||
|
|
||||||
def assign(self, reactor):
|
def assign(self, reactor):
|
||||||
"""
|
"""
|
||||||
Make a new streaming server endpoint and return its string description.
|
Make a new streaming server endpoint and return its string description.
|
||||||
@ -183,10 +208,6 @@ class SameProcessStreamEndpointAssigner(object):
|
|||||||
host, port = s.getsockname()
|
host, port = s.getsockname()
|
||||||
location_hint = "tcp:%s:%d" % (host, port)
|
location_hint = "tcp:%s:%d" % (host, port)
|
||||||
port_endpoint = "adopt-socket:fd=%d" % (s.fileno(),)
|
port_endpoint = "adopt-socket:fd=%d" % (s.fileno(),)
|
||||||
# Make sure `adopt-socket` is recognized. We do this instead of
|
|
||||||
# providing a dropin because we don't want to make this endpoint
|
|
||||||
# available to random other applications.
|
|
||||||
self._patch_plugins()
|
|
||||||
else:
|
else:
|
||||||
# On other platforms, we blindly guess and hope we get lucky.
|
# On other platforms, we blindly guess and hope we get lucky.
|
||||||
portnum = iputil.allocate_tcp_port()
|
portnum = iputil.allocate_tcp_port()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user