Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_lsplit():
assert lsplit(_ % 2, range(5)) == ([1, 3], [0, 2, 4])
# This behaviour moved to split_at()
with pytest.raises(TypeError): lsplit(2, range(5))
def test_pairwise():
assert list(pairwise(range(3))) == [(0, 1), (1, 2)]
def test_with_next():
assert list(with_next(range(3))) == [(0, 1), (1, 2), (2, None)]
def test_with_prev():
assert list(with_prev(range(3))) == [(0, None), (1, 0), (2, 1)]
def test_iterable():
assert iterable([])
assert iterable({})
assert iterable('abc')
assert iterable(iter([]))
assert iterable(x for x in range(10))
assert iterable(range(10))
assert not iterable(1)
def test_chunks():
assert lchunks(2, [0, 1, 2, 3, 4]) == [[0, 1], [2, 3], [4]]
assert lchunks(2, 1, [0, 1, 2, 3]) == [[0, 1], [1, 2], [2, 3], [3]]
assert lchunks(3, 1, iter(range(3))) == [[0, 1, 2], [1, 2], [2]]
def test_cat():
assert lcat('abcd') == list('abcd')
assert lcat(range(x) for x in range(3)) == [0, 0, 1]
def test_ilen():
assert ilen('xyz') == 3
assert ilen(range(10)) == 10
def _cut(drop_tail, n, step, seq=EMPTY):
if seq is EMPTY:
step, seq = n, step
# NOTE: range() is capable of slicing in python 3,
if isinstance(seq, Sequence) and (PY3 or not isinstance(seq, range)):
return _cut_seq(drop_tail, n, step, seq)
else:
return _cut_iter(drop_tail, n, step, seq)
try:
dest = next(it)
except StopIteration:
return None
cls = dest.__class__
if isinstance(dest, basestring):
return ''.join(colls)
elif isinstance(dest, Mapping):
result = dest.copy()
for d in it:
result.update(d)
return result
elif isinstance(dest, Set):
return dest.union(*it)
elif isinstance(dest, (Iterator, range)):
return chain.from_iterable(colls)
elif isinstance(dest, Iterable):
# NOTE: this could be reduce(concat, ...),
# more effective for low count
return cls(chain.from_iterable(colls))
else:
raise TypeError("Don't know how to join %s" % cls.__name__)