util/spans.py: __nonzero__ cannot return a long either. for #1154

This commit is contained in:
Brian Warner 2010-08-05 10:46:18 -07:00
parent cd8d41584e
commit 43c5032105
2 changed files with 20 additions and 2 deletions

View File

@ -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)

View File

@ -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