From: Brian Warner Date: Tue, 22 Apr 2008 23:47:15 +0000 (-0700) Subject: testutil: factor stall() out into a common location X-Git-Tag: allmydata-tahoe-1.1.0~193 X-Git-Url: https://git.rkrishnan.org/class-simplejson.JSONEncoder-index.html?a=commitdiff_plain;h=81ab1ec7852fa564506f4b2432c7f4a8634c5c5c;p=tahoe-lafs%2Ftahoe-lafs.git testutil: factor stall() out into a common location --- diff --git a/src/allmydata/test/test_client.py b/src/allmydata/test/test_client.py index 6c6c77bd..9bb889db 100644 --- a/src/allmydata/test/test_client.py +++ b/src/allmydata/test/test_client.py @@ -7,7 +7,7 @@ from twisted.python import log import allmydata from allmydata import client, introducer -from allmydata.util import base32 +from allmydata.util import base32, testutil from foolscap.eventual import flushEventualQueue class FakeIntroducerClient(introducer.IntroducerClient): @@ -145,7 +145,7 @@ def flush_but_dont_ignore(res): d.addCallback(_done) return d -class Run(unittest.TestCase): +class Run(unittest.TestCase, testutil.StallMixin): def setUp(self): self.sparent = service.MultiService() @@ -163,11 +163,6 @@ class Run(unittest.TestCase): open(os.path.join(basedir, "suicide_prevention_hotline"), "w") c = client.Client(basedir) - def stall(self, res=None, delay=1): - d = defer.Deferred() - reactor.callLater(delay, d.callback, res) - return d - def test_reloadable(self): basedir = "test_client.Run.test_reloadable" os.mkdir(basedir) diff --git a/src/allmydata/test/test_dirnode.py b/src/allmydata/test/test_dirnode.py index dafc67af..8522ea5a 100644 --- a/src/allmydata/test/test_dirnode.py +++ b/src/allmydata/test/test_dirnode.py @@ -64,7 +64,7 @@ class FakeClient: return d -class Dirnode(unittest.TestCase, testutil.ShouldFailMixin): +class Dirnode(unittest.TestCase, testutil.ShouldFailMixin, testutil.StallMixin): def setUp(self): self.client = FakeClient() @@ -162,11 +162,6 @@ class Dirnode(unittest.TestCase, testutil.ShouldFailMixin): def failUnlessGreaterOrEqualThan(self, a, b): self.failUnless(a >= b, "%r should be >= %r" % (a, b)) - def stall(self, res, delay=1.0): - d = defer.Deferred() - reactor.callLater(delay, d.callback, res) - return d - def test_create(self): self.expected_manifest = [] diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py index 8d46395c..8ea19858 100644 --- a/src/allmydata/test/test_system.py +++ b/src/allmydata/test/test_system.py @@ -50,7 +50,8 @@ class CountingDataUploadable(upload.Data): return upload.Data.read(self, length) -class SystemTest(testutil.SignalMixin, testutil.PollMixin, unittest.TestCase): +class SystemTest(testutil.SignalMixin, testutil.PollMixin, testutil.StallMixin, + unittest.TestCase): def setUp(self): self.sparent = service.MultiService() @@ -978,11 +979,6 @@ class SystemTest(testutil.SignalMixin, testutil.PollMixin, unittest.TestCase): log.msg(msg, **kwargs) return res - def stall(self, res, delay=1.0): - d = defer.Deferred() - reactor.callLater(delay, d.callback, res) - return d - def _do_publish_private(self, res): self.smalldata = "sssh, very secret stuff" ut = upload.Data(self.smalldata, convergence=None) diff --git a/src/allmydata/util/testutil.py b/src/allmydata/util/testutil.py index 21edb8f6..d62d905b 100644 --- a/src/allmydata/util/testutil.py +++ b/src/allmydata/util/testutil.py @@ -57,6 +57,12 @@ class PollMixin: if check_f(): lc.stop() +class StallMixin: + def stall(self, res=None, delay=1): + d = defer.Deferred() + reactor.callLater(delay, d.callback, res) + return d + class ShouldFailMixin: def shouldFail(self, expected_failure, which, substring,