From: Brian Warner Date: Mon, 23 Feb 2009 00:27:22 +0000 (-0700) Subject: stop using RuntimeError in unit tests, for #639 X-Git-Tag: allmydata-tahoe-1.4.0~142 X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/bar.txt?a=commitdiff_plain;h=5c3d7d8e733faf53941d4e4f4f4b72a86dd2995a;p=tahoe-lafs%2Ftahoe-lafs.git stop using RuntimeError in unit tests, for #639 --- diff --git a/src/allmydata/test/test_upload.py b/src/allmydata/test/test_upload.py index d1c7531c..a0bc7984 100644 --- a/src/allmydata/test/test_upload.py +++ b/src/allmydata/test/test_upload.py @@ -182,6 +182,9 @@ class FakeClient: def get_cancel_secret(self): return "" +class GotTooFarError(Exception): + pass + class GiganticUploadable(upload.FileHandle): def __init__(self, size): self._size = size @@ -197,7 +200,7 @@ class GiganticUploadable(upload.FileHandle): self._fp += length if self._fp > 1000000: # terminate the test early. - raise RuntimeError("we shouldn't be allowed to get this far") + raise GotTooFarError("we shouldn't be allowed to get this far") return defer.succeed(["\x00" * length]) def close(self): pass diff --git a/src/allmydata/test/test_util.py b/src/allmydata/test/test_util.py index 8d979667..246b2b98 100644 --- a/src/allmydata/test/test_util.py +++ b/src/allmydata/test/test_util.py @@ -51,17 +51,17 @@ class HumanReadable(unittest.TestCase): self.failUnlessEqual(hr([1,2]), "[1, 2]") self.failUnlessEqual(hr({1:2}), "{1:2}") try: - raise RuntimeError + raise ValueError except Exception, e: self.failUnless( - hr(e) == "" # python-2.4 - or hr(e) == "RuntimeError()") # python-2.5 + hr(e) == "" # python-2.4 + or hr(e) == "ValueError()") # python-2.5 try: - raise RuntimeError("oops") + raise ValueError("oops") except Exception, e: self.failUnless( - hr(e) == "" # python-2.4 - or hr(e) == "RuntimeError('oops',)") # python-2.5 + hr(e) == "" # python-2.4 + or hr(e) == "ValueError('oops',)") # python-2.5 try: raise NoArgumentException except Exception, e: @@ -531,12 +531,12 @@ class DeferredUtilTests(unittest.TestCase): d1.addErrback(lambda _ignore: None) d2.addErrback(lambda _ignore: None) d1.callback(1) - d2.errback(RuntimeError()) + d2.errback(ValueError()) self.failUnlessEqual(good, []) self.failUnlessEqual(len(bad), 1) f = bad[0] self.failUnless(isinstance(f, failure.Failure)) - self.failUnless(f.check(RuntimeError)) + self.failUnless(f.check(ValueError)) class HashUtilTests(unittest.TestCase): @@ -694,7 +694,7 @@ class Limiter(unittest.TestCase): return d def bad_job(self, i, foo): - raise RuntimeError("bad_job %d" % i) + raise ValueError("bad_job %d" % i) def test_limiter(self): self.calls = [] @@ -740,7 +740,7 @@ class Limiter(unittest.TestCase): def _good(res): self.fail("should have failed, not got %s" % (res,)) def _err(f): - f.trap(RuntimeError) + f.trap(ValueError) self.failUnless("bad_job 21" in str(f)) d2.addCallbacks(_good, _err) return d2 diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 9aa5929c..accaa5aa 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -2973,7 +2973,7 @@ class Grid(GridTestMixin, WebErrorMixin, unittest.TestCase): sf = ShareFile(fn) num_leases = len(list(sf.iter_leases())) else: - raise RuntimeError("can't get leases on %s" % u) + raise ValueError("can't count leases on %s" % u) lease_counts.append( (fn, num_leases) ) return lease_counts