import uuid
from pillowtop.feed.interface import ChangeFeed, Change


class MockChangeFeed(ChangeFeed):
    """
    Mock change feed used in tests. Assumes the "since" argument is just an index into
    whatever queue is passed in.
    """

    def __init__(self, queue):
        self._queue = queue

    def iter_changes(self, since, forever=False):
        if forever:
            raise ValueError('Forever option not supported for mock feed!')
        else:
            for val in self._queue[since:]:
                yield val

    def get_latest_change_id(self):
        return len(self._queue)

    def get_current_offsets(self):
        return {'test': self.get_latest_change_id()}

    def get_checkpoint_value(self):
        return str(self.get_latest_change_id())


class RandomChangeFeed(ChangeFeed):
    """
    A change feed that generates random changes, used in tests. Accepts in a total number of
    changes, as well as an (optional) `change_generator` function which should take in a sequence
    ID and return a Change object
    """

    def __init__(self, count, change_generator=None):
        self._count = count
        self._change_generator = change_generator or random_change

    def iter_changes(self, since, forever=False):
        if forever:
            raise ValueError('Forever option not supported for random feed!')
        else:
            while since < self._count:
                yield self._change_generator(since)
                since += 1

    def get_latest_change_id(self):
        return self._count

    def get_current_offsets(self):
        return {'test': self.get_latest_change_id()}

    def get_checkpoint_value(self):
        return str(self.get_latest_change_id())


def random_change(sequence_id):
    return Change(
        id=uuid.uuid4().hex,
        sequence_id=sequence_id,
        document=None,
        deleted=False,
    )

@@ -336,32 +336,60 @@
 forever=False):%0A
+        self._since = since%0A
         if forev
@@ -384,32 +384,32 @@
     if forever:%0A
-
             rais
@@ -551,16 +551,49 @@
 ield val
+%0A                self._since += 1
 %0A%0A    de
@@ -829,16 +829,91 @@
 _id())%0A%0A
+    def get_processed_offsets(self):%0A        return %7B'test': self._since%7D%0A%0A
 %0Aclass R
@@ -1331,16 +1331,43 @@
 m_change
+%0A        self._since = None
 %0A%0A    de
@@ -1402,32 +1402,60 @@
 forever=False):%0A
+        self._since = since%0A
         if forev
@@ -1568,16 +1568,22 @@
   while 
+self._
 since %3C 
@@ -1640,16 +1640,22 @@
 nerator(
+self._
 since)%0A 
@@ -1669,16 +1669,22 @@
         
+self._
 since +=
@@ -1868,32 +1868,32 @@
 nt_value(self):%0A
-
         return s
@@ -1925,16 +1925,91 @@
 _id())%0A%0A
+    def get_processed_offsets(self):%0A        return %7B'test': self._since%7D%0A%0A
 %0Adef ran

implement get_processed_offsets for test change feeds