Coverage for lino/utils/cycler.py : 88%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: UTF-8 -*- # Copyright 2013-2014 by Luc Saffre. # License: BSD, see LICENSE for more details.
Turns a list of items into an endless loop. Useful when generating demo fixtures.
>>> from lino.utils import Cycler >>> def myfunc(): ... yield "a" ... yield "b" ... yield "c"
>>> c = Cycler(myfunc()) >>> s = "" >>> for i in range(10): ... s += c.pop() >>> print s abcabcabca
An empty Cycler or a Cycler on an empty list will endlessly pop None values:
>>> c = Cycler() >>> print c.pop(), c.pop(), c.pop() None None None
>>> c = Cycler([]) >>> print c.pop(), c.pop(), c.pop() None None None
>>> c = Cycler(None) >>> print c.pop(), c.pop(), c.pop() None None None """
""" If there is exactly one argument, then this must be an iterable and will be used as the list of items to cycle on. If there is more than one positional argument, then these arguments themselves will be the list of items. """
else: else:
self.current = 0
import doctest doctest.testmod()
_test() |