Permalink
Browse files

Updated slice_iterator to conform to python iterator contract. Update…

…d tests.
  • Loading branch information...
1 parent 1763807 commit a0f9d13da8a4da2ee4398762b0866beec0262afc @voidptr voidptr committed Jul 14, 2010
Showing with 24 additions and 11 deletions.
  1. +10 −1 Pyrex/caper.pyx
  2. +14 −10 Pyrex/test_misc.py
View
@@ -266,9 +266,18 @@ cdef class slice_iterator:
self.current = start
self.seqname = seqname
- def next(self):
+ def __iter__(self):
+ return self
+
+ def __repr__(self):
+ return "slice_iterator('%s', %d, %d)" % (self.seqname, self.start, self.current)
+
+ def __next__(self):
self.thisiterator.Next()
self.current = self.thisiterator.GetIndex()
+ if self.current == -1:
+ raise StopIteration
+ return (self.current, self.get_reads())
def get_reads(self):
cdef c_reads_at_indexes * reads
View
@@ -37,18 +37,22 @@ def test_get_reads_at_2(self):
def test_get_reads_int_2(self):
reads = self.engine.get_intersect(contig, 2)
- assert 0, list(reads)
- test_get_reads_int_2.failing = True
+ assert len(reads) == 1, list(reads)
+# assert 0, list(reads)
+# test_get_reads_int_2.failing = True
def test_get_reads_slice(self):
- reads = self.engine.get_slice(contig, 0, 2)
- assert 0, list(reads)
- test_get_reads_slice.failing = True
-
+ reads = self.engine.get_slice(contig, 0, 4)
+ assert len(reads) == 3, list(reads)
+ #assert 0, list(reads)
+# test_get_reads_slice.failing = True
+
def test_get_reads_slice_iterator(self):
- reads = self.engine.get_slice_iterator(contig, 0)
- assert 0, list(reads)
- test_get_reads_slice_iterator.failing = True
+ iterator = self.engine.get_slice_iterator(contig, 0)
+ reads = iterator.get_reads()
+ assert len(reads) == 0
+# assert 0, list(reads)
+# test_get_reads_slice_iterator.failing = True
def test_get_iterator(self):
x = [ index for (index, item) in self.engine.get_iterator(contig, 0) ]
@@ -57,4 +61,4 @@ def test_get_iterator(self):
if __name__ == '__main__':
import nose
nose.main()
-
+

0 comments on commit a0f9d13

Please sign in to comment.