Ejemplo n.º 1
0
 def test_reset_at_begin(self):
     i = utils.ResetableIterator([1, 2, 3])
     iterator = iter(i)
     i.reset()
     i.reset()
     self.assertEqual(1, next(iterator))
     self.assertEqual(2, next(iterator))
     self.assertEqual(3, next(iterator))
Ejemplo n.º 2
0
    def test_no_reset_new_iterator(self):
        i = utils.ResetableIterator([1, 2, 3])
        iterator = iter(i)
        self.assertEqual(1, next(iterator))
        self.assertEqual(2, next(iterator))

        iterator2 = iter(i)
        self.assertEqual(3, next(iterator2))
Ejemplo n.º 3
0
    def test_reset_after_end(self):
        i = utils.ResetableIterator([1, 2, 3])
        iterator = iter(i)
        self.assertEqual(1, next(iterator))
        self.assertEqual(2, next(iterator))
        self.assertEqual(3, next(iterator))
        self.assertRaises(StopIteration, next, iterator)

        i.reset()
        # Previous iter() has stopped
        iterator = iter(i)
        self.assertEqual(1, next(iterator))
        self.assertEqual(2, next(iterator))
        self.assertEqual(3, next(iterator))
Ejemplo n.º 4
0
    def test_reset_shorter(self):
        i = utils.ResetableIterator([1, 2, 3, 4, 5])
        iterator = iter(i)
        self.assertEqual(1, next(iterator))
        self.assertEqual(2, next(iterator))
        self.assertEqual(3, next(iterator))
        self.assertEqual(4, next(iterator))

        i.reset()
        self.assertEqual(1, next(iterator))
        self.assertEqual(2, next(iterator))

        i.reset()
        self.assertEqual(1, next(iterator))
        self.assertEqual(2, next(iterator))
        self.assertEqual(3, next(iterator))
        self.assertEqual(4, next(iterator))
Ejemplo n.º 5
0
 def test_infinite(self):
     i = utils.ResetableIterator(itertools.cycle([1, 2, 3]))
     iterator = iter(i)
     values = [next(iterator) for _i in range(10)]
     self.assertEqual([1, 2, 3, 1, 2, 3, 1, 2, 3, 1], values)
Ejemplo n.º 6
0
 def test_no_reset(self):
     i = utils.ResetableIterator([1, 2, 3])
     self.assertEqual([1, 2, 3], list(i))