Files
bonobo/tests/util/test_collections.py

31 lines
632 B
Python

from bonobo.util import sortedlist, ensure_tuple
from bonobo.util.collections import tuplize
def test_sortedlist():
l = sortedlist()
l.insort(2)
l.insort(1)
l.insort(3)
l.insort(2)
assert l == [1, 2, 2, 3]
def test_ensure_tuple():
assert ensure_tuple('a') == ('a', )
assert ensure_tuple(('a', )) == ('a', )
assert ensure_tuple(()) is ()
def test_tuplize():
tuplized_lambda = tuplize(lambda: [1, 2, 3])
assert tuplized_lambda() == (1, 2, 3)
@tuplize
def some_generator():
yield 'c'
yield 'b'
yield 'a'
assert some_generator() == ('c', 'b', 'a')