fix tests by overriding/patching reactor.stop in tests

This commit is contained in:
meejah 2018-06-27 03:04:58 -06:00
parent 423208f391
commit 0607b7331f
2 changed files with 9 additions and 1 deletions

View File

@ -37,6 +37,7 @@ class Util(unittest.TestCase):
with patch('twisted.internet.reactor') as r:
def call(fn, *args, **kw):
fn()
r.stop = lambda: None
r.callWhenRunning = call
service = plug.makeService(None)
service.parent = Mock()
@ -52,6 +53,7 @@ class Util(unittest.TestCase):
def call(fn, *args, **kw):
fn()
r.callWhenRunning = call
r.stop = lambda: None
service = plug.makeService(None)
service.parent = Mock()
with self.assertRaises(ValueError) as ctx:
@ -68,6 +70,7 @@ class Util(unittest.TestCase):
with patch('twisted.internet.reactor') as r:
def call(fn, *args, **kw):
fn()
r.stop = lambda: None
r.callWhenRunning = call
service = plug.makeService(None)
service.parent = Mock()
@ -97,6 +100,7 @@ class RunDaemonizeTests(unittest.TestCase):
self._working = os.path.abspath('.')
d = super(RunDaemonizeTests, self).setUp()
self._reactor = patch('twisted.internet.reactor')
self._reactor.stop = lambda: None
self._twistd = patch('allmydata.scripts.tahoe_daemonize.twistd')
self.node_dir = self.mktemp()
os.mkdir(self.node_dir)

View File

@ -218,7 +218,11 @@ class RunTests(unittest.TestCase):
os.mkdir(self.node_dir)
return d
def test_run_invalid_config(self):
@patch('twisted.internet.reactor')
def test_run_invalid_config(self, reactor):
def cwr(fn, *args, **kw):
fn()
reactor.callWhenRunning = cwr
with open(os.path.join(self.node_dir, "client.tac"), "w") as f:
f.write('test')