Merge pull request #627 from tahoe-lafs/3111.test_invalid_section-fixes

Fixes for test_invalid_section

Fixes: ticket:3111
This commit is contained in:
Jean-Paul Calderone 2019-06-26 15:47:38 -04:00 committed by GitHub
commit c16924641c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 8 deletions

0
newsfragments/3111.minor Normal file
View File

View File

@ -105,6 +105,8 @@ the twistd-options.
class MyTwistdConfig(twistd.ServerOptions):
subCommands = [("DaemonizeTahoeNode", None, usage.Options, "node")]
stderr = sys.stderr
class DaemonizeTheRealService(Service, HookMixin):
"""
@ -122,6 +124,7 @@ class DaemonizeTheRealService(Service, HookMixin):
self._hooks = {
"running": None,
}
self.stderr = options.parent.stderr
def startService(self):
@ -143,7 +146,7 @@ class DaemonizeTheRealService(Service, HookMixin):
def handle_config_error(fail):
fail.trap(UnknownConfigError)
sys.stderr.write("\nConfiguration error:\n{}\n\n".format(fail.value))
self.stderr.write("\nConfiguration error:\n{}\n\n".format(fail.value))
reactor.stop()
return
@ -204,6 +207,8 @@ def daemonize(config):
twistd_args.append("DaemonizeTahoeNode") # point at our DaemonizeTahoeNodePlugin
twistd_config = MyTwistdConfig()
twistd_config.stdout = out
twistd_config.stderr = err
try:
twistd_config.parseOptions(twistd_args)
except usage.error as ue:

View File

@ -8,9 +8,14 @@ from allmydata.scripts import runner
from allmydata.scripts.tahoe_daemonize import identify_node_type
from allmydata.scripts.tahoe_daemonize import DaemonizeTahoeNodePlugin
from allmydata.scripts.tahoe_daemonize import DaemonizeOptions
from allmydata.scripts.tahoe_daemonize import MyTwistdConfig
class Util(unittest.TestCase):
def setUp(self):
self.twistd_options = MyTwistdConfig()
self.twistd_options.parseOptions(["DaemonizeTahoeNode"])
self.options = self.twistd_options.subOptions
def test_node_type_nothing(self):
tmpdir = self.mktemp()
@ -39,7 +44,7 @@ class Util(unittest.TestCase):
fn()
r.stop = lambda: None
r.callWhenRunning = call
service = plug.makeService(None)
service = plug.makeService(self.options)
service.parent = Mock()
service.startService()
@ -55,7 +60,7 @@ class Util(unittest.TestCase):
d.addErrback(lambda _: None) # ignore the error we'll trigger
r.callWhenRunning = call
r.stop = 'foo'
service = plug.makeService(None)
service = plug.makeService(self.options)
service.parent = Mock()
# we'll raise ValueError because there's no key-generator
# .. BUT we do this in an async function called via
@ -80,7 +85,7 @@ class Util(unittest.TestCase):
fn()
r.stop = lambda: None
r.callWhenRunning = call
service = plug.makeService(None)
service = plug.makeService(self.options)
service.parent = Mock()
with self.assertRaises(ValueError) as ctx:
service.startService()

View File

@ -1,5 +1,4 @@
import os
import sys
import shutil
import subprocess
from os.path import join
@ -255,10 +254,9 @@ class RunTests(unittest.TestCase):
])
i, o, e = StringIO(), StringIO(), StringIO()
with patch.object(sys, 'stdout', o), patch.object(sys, 'stderr', e):
runner.dispatch(config, i, o, e)
runner.dispatch(config, i, o, e)
output = o.getvalue()
output = e.getvalue()
# should print out the collected logs and an error-code
self.assertIn(
"invalid section",