mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-01-17 02:09:54 +00:00
Remove react monkey patching by supplying an alternate reactor
Let react run and do its thing. This gives us an even nicer way to check the exit code.
This commit is contained in:
parent
faf8da82dd
commit
240d5d1164
@ -8,7 +8,12 @@ from twisted.trial import unittest
|
|||||||
from twisted.python.monkey import MonkeyPatcher
|
from twisted.python.monkey import MonkeyPatcher
|
||||||
from twisted.internet import task
|
from twisted.internet import task
|
||||||
from twisted.python.filepath import FilePath
|
from twisted.python.filepath import FilePath
|
||||||
|
from twisted.internet.testing import (
|
||||||
|
MemoryReactor,
|
||||||
|
)
|
||||||
|
from twisted.internet.test.modulehelpers import (
|
||||||
|
AlternateReactor,
|
||||||
|
)
|
||||||
import allmydata
|
import allmydata
|
||||||
from allmydata.crypto import ed25519
|
from allmydata.crypto import ed25519
|
||||||
from allmydata.util import fileutil, hashutil, base32
|
from allmydata.util import fileutil, hashutil, base32
|
||||||
@ -508,6 +513,10 @@ class CLI(CLITestMixin, unittest.TestCase):
|
|||||||
self.failUnlessIn(normalize(file), filenames)
|
self.failUnlessIn(normalize(file), filenames)
|
||||||
|
|
||||||
def test_exception_catcher(self):
|
def test_exception_catcher(self):
|
||||||
|
"""
|
||||||
|
An exception that is otherwise unhandled during argument dispatch is
|
||||||
|
written to stderr and causes the process to exit with code 1.
|
||||||
|
"""
|
||||||
self.basedir = "cli/exception_catcher"
|
self.basedir = "cli/exception_catcher"
|
||||||
|
|
||||||
exc = Exception("canary")
|
exc = Exception("canary")
|
||||||
@ -517,26 +526,21 @@ class CLI(CLITestMixin, unittest.TestCase):
|
|||||||
|
|
||||||
stderr = StringIO()
|
stderr = StringIO()
|
||||||
|
|
||||||
def fake_react(f):
|
reactor = MemoryReactor()
|
||||||
reactor = Mock()
|
|
||||||
# normally this Deferred would be errbacked with SystemExit, but
|
|
||||||
# since we mocked out sys.exit, it will be fired with None. So
|
|
||||||
# it's safe to drop it on the floor.
|
|
||||||
f(reactor)
|
|
||||||
|
|
||||||
patcher = MonkeyPatcher((task, 'react', fake_react),
|
with AlternateReactor(reactor):
|
||||||
)
|
with self.assertRaises(SystemExit) as ctx:
|
||||||
patcher.runWithPatches(
|
runner.run(
|
||||||
lambda: runner.run(
|
configFactory=BrokenOptions,
|
||||||
configFactory=BrokenOptions,
|
argv=["tahoe"],
|
||||||
argv=["tahoe"],
|
stderr=stderr,
|
||||||
stderr=stderr,
|
)
|
||||||
),
|
|
||||||
)
|
self.assertTrue(reactor.hasRun)
|
||||||
|
self.assertFalse(reactor.running)
|
||||||
|
|
||||||
self.failUnlessIn(str(exc), stderr.getvalue())
|
self.failUnlessIn(str(exc), stderr.getvalue())
|
||||||
[exit_exc] = self.flushLoggedErrors(SystemExit)
|
self.assertEqual(1, ctx.exception.code)
|
||||||
self.assertEqual(1, exit_exc.value.code)
|
|
||||||
|
|
||||||
|
|
||||||
class Help(unittest.TestCase):
|
class Help(unittest.TestCase):
|
||||||
|
Loading…
Reference in New Issue
Block a user