From 0607b7331f9fcdc43d5782d4b3a36d4a2fac544f Mon Sep 17 00:00:00 2001 From: meejah Date: Wed, 27 Jun 2018 03:04:58 -0600 Subject: [PATCH] fix tests by overriding/patching reactor.stop in tests --- src/allmydata/test/cli/test_daemonize.py | 4 ++++ src/allmydata/test/cli/test_start.py | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/allmydata/test/cli/test_daemonize.py b/src/allmydata/test/cli/test_daemonize.py index 3853054e4..51d39b395 100644 --- a/src/allmydata/test/cli/test_daemonize.py +++ b/src/allmydata/test/cli/test_daemonize.py @@ -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) diff --git a/src/allmydata/test/cli/test_start.py b/src/allmydata/test/cli/test_start.py index c2dd8c834..01c8a1c60 100644 --- a/src/allmydata/test/cli/test_start.py +++ b/src/allmydata/test/cli/test_start.py @@ -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')