From: Brian Warner Date: Thu, 5 Aug 2010 17:46:18 +0000 (-0700) Subject: util/spans.py: __nonzero__ cannot return a long either. for #1154 X-Git-Tag: allmydata-tahoe-1.8.0b2~9 X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/flags?a=commitdiff_plain;h=43c5032105288a58910756d210403ebf49e37323;p=tahoe-lafs%2Ftahoe-lafs.git util/spans.py: __nonzero__ cannot return a long either. for #1154 --- diff --git a/src/allmydata/test/test_util.py b/src/allmydata/test/test_util.py index bac353ff..0b7b24f2 100644 --- a/src/allmydata/test/test_util.py +++ b/src/allmydata/test/test_util.py @@ -1666,6 +1666,9 @@ class ByteSpans(unittest.TestCase): s1 = Spans(3, 4) # 3,4,5,6 self._check1(s1) + s1 = Spans(3L, 4L) # 3,4,5,6 + self._check1(s1) + s2 = Spans(s1) self._check1(s2) @@ -1702,6 +1705,15 @@ class ByteSpans(unittest.TestCase): self.failIf((7,1) in s) self.failUnlessEqual(list(s.each()), [3,4,5,6]) + def test_large(self): + s = Spans(4, 2**65) # don't do this with a SimpleSpans + self.failUnlessEqual(list(s), [(4, 2**65)]) + self.failUnless(s) + self.failUnlessEqual(s.len(), 2**65) + self.failIf((0,1) in s) + self.failUnless((4,2) in s) + self.failUnless((2**65,2) in s) + def test_math(self): s1 = Spans(0, 10) # 0,1,2,3,4,5,6,7,8,9 s2 = Spans(5, 3) # 5,6,7 @@ -1980,6 +1992,12 @@ class StringSpans(unittest.TestCase): ds.add(3, "ea") self.failUnlessEqual(ds.get(2, 4), "fear") + ds = klass() + ds.add(2L, "four") + ds.add(3L, "ea") + self.failUnlessEqual(ds.get(2L, 4L), "fear") + + def do_scan(self, klass): # do a test with gaps and spans of size 1 and 2 # left=(1,11) * right=(1,11) * gapsize=(1,2) diff --git a/src/allmydata/util/spans.py b/src/allmydata/util/spans.py index fcdd577e..34c65e1e 100644 --- a/src/allmydata/util/spans.py +++ b/src/allmydata/util/spans.py @@ -154,7 +154,7 @@ class Spans: yield s def __nonzero__(self): # this gets us bool() - return self.len() + return bool(self.len()) def len(self): # guess what! python doesn't allow __len__ to return a long, only an @@ -233,7 +233,7 @@ class DataSpans: self.add(start, data) def __nonzero__(self): # this gets us bool() - return self.len() + return bool(self.len()) def len(self): # return number of bytes we're holding