back to OpenHands summary
Pytest Summary for test tests
status |
count |
passed |
62 |
failed |
600 |
skipped |
1 |
total |
663 |
collected |
663 |
Failed pytests:
test_more.py::ChunkedTests::test_strict_being_true_with_size_none
test_more.py::ChunkedTests::test_strict_being_true_with_size_none
self =
def test_strict_being_true_with_size_none(self):
"""Test when ``n`` has value ``None`` and the keyword strict is True
(raising an exception).
"""
def f():
return list(mi.chunked('ABCDE', None, strict=True))
> self.assertRaisesRegex(
ValueError, "n must not be None when using strict mode.", f
)
E AssertionError: ValueError not raised by f
tests/test_more.py:102: AssertionError
test_more.py::PeekableTests::test_empty
test_more.py::PeekableTests::test_empty
self =
def test_empty(self):
"""Tests prepending in front of an empty iterable"""
it = mi.peekable([])
it.prepend(10)
actual = list(it)
expected = [10]
> self.assertEqual(actual, expected)
E AssertionError: Lists differ: [] != [10]
E
E Second list contains 1 additional elements.
E First extra element 0:
E 10
E
E - []
E + [10]
tests/test_more.py:356: AssertionError
test_more.py::PeekableTests::test_multi_prepend
test_more.py::PeekableTests::test_multi_prepend
self =
def test_multi_prepend(self):
"""Tests prepending multiple items and getting them in proper order"""
it = mi.peekable(range(5))
actual = [next(it), next(it)]
it.prepend(10, 11, 12)
it.prepend(20, 21)
actual += list(it)
expected = [0, 1, 20, 21, 10, 11, 12, 2, 3, 4]
> self.assertEqual(actual, expected)
E AssertionError: Lists differ: [0, 1, 2, 3, 4] != [0, 1, 20, 21, 10, 11, 12, 2, 3, 4]
E
E First differing element 2:
E 2
E 20
E
E Second list contains 5 additional elements.
E First extra element 5:
E 11
E
E - [0, 1, 2, 3, 4]
E + [0, 1, 20, 21, 10, 11, 12, 2, 3, 4]
tests/test_more.py:348: AssertionError
test_more.py::PeekableTests::test_multi_prepend_peek
test_more.py::PeekableTests::test_multi_prepend_peek
self =
def test_multi_prepend_peek(self):
"""Tests prepending multiple elements and getting them in reverse order
while peeking"""
it = mi.peekable(range(5))
actual = [next(it), next(it)]
> self.assertEqual(it.peek(), 2)
E AssertionError: None != 2
tests/test_more.py:377: AssertionError
test_more.py::PeekableTests::test_peek_default
test_more.py::PeekableTests::test_peek_default
self =
def test_peek_default(self):
"""Make sure passing a default into ``peek()`` works."""
p = self.cls([])
> self.assertEqual(p.peek(7), 7)
E AssertionError: None != 7
tests/test_more.py:211: AssertionError
test_more.py::PeekableTests::test_prepend
test_more.py::PeekableTests::test_prepend
self =
def test_prepend(self):
"""Tests interspersed ``prepend()`` and ``next()`` calls"""
it = mi.peekable(range(2))
actual = []
# Test prepend() before next()
it.prepend(10)
actual += [next(it), next(it)]
# Test prepend() between next()s
it.prepend(11)
> actual += [next(it), next(it)]
tests/test_more.py:331:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self =
def __next__(self):
if self._cache:
return self._cache.popleft()
> return next(self._it)
E StopIteration
more_itertools/more.py:332: StopIteration
test_more.py::PeekableTests::test_prepend_after_stop
test_more.py::PeekableTests::test_prepend_after_stop
self =
def test_prepend_after_stop(self):
"""Test resuming iteration after a previous exhaustion"""
it = mi.peekable(range(3))
self.assertEqual(list(it), [0, 1, 2])
self.assertRaises(StopIteration, lambda: next(it))
it.prepend(10)
> self.assertEqual(next(it), 10)
tests/test_more.py:393:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self =
def __next__(self):
if self._cache:
return self._cache.popleft()
> return next(self._it)
E StopIteration
more_itertools/more.py:332: StopIteration
test_more.py::PeekableTests::test_prepend_indexing
test_more.py::PeekableTests::test_prepend_indexing
self =
def test_prepend_indexing(self):
"""Tests interaction between prepending and indexing"""
seq = list(range(20))
p = mi.peekable(seq)
p.prepend(30, 40, 50)
> self.assertEqual(p[0], 30)
E AssertionError: 0 != 30
tests/test_more.py:421: AssertionError
test_more.py::PeekableTests::test_prepend_iterable
test_more.py::PeekableTests::test_prepend_iterable
self =
def test_prepend_iterable(self):
"""Tests prepending from an iterable"""
it = mi.peekable(range(5))
# Don't directly use the range() object to avoid any range-specific
# optimizations
it.prepend(*(x for x in range(5)))
actual = list(it)
expected = list(chain(range(5), range(5)))
> self.assertEqual(actual, expected)
E AssertionError: Lists differ: [0, 1, 2, 3, 4] != [0, 1, 2, 3, 4, 0, 1, 2, 3, 4]
E
E Second list contains 5 additional elements.
E First extra element 5:
E 0
E
E - [0, 1, 2, 3, 4]
E + [0, 1, 2, 3, 4, 0, 1, 2, 3, 4]
tests/test_more.py:441: AssertionError
test_more.py::PeekableTests::test_prepend_many
test_more.py::PeekableTests::test_prepend_many
self =
def test_prepend_many(self):
"""Tests that prepending a huge number of elements works"""
it = mi.peekable(range(5))
# Don't directly use the range() object to avoid any range-specific
# optimizations
it.prepend(*(x for x in range(20000)))
actual = list(it)
expected = list(chain(range(20000), range(5)))
> self.assertEqual(actual, expected)
E AssertionError: Lists differ: [0, 1, 2, 3, 4] != [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, [128845 chars]3, 4]
E
E Second list contains 20000 additional elements.
E First extra element 5:
E 5
E
E Diff is 188938 characters long. Set self.maxDiff to None to see it.
tests/test_more.py:451: AssertionError
test_more.py::PeekableTests::test_prepend_reversed
test_more.py::PeekableTests::test_prepend_reversed
self =
def test_prepend_reversed(self):
"""Tests prepending from a reversed iterable"""
it = mi.peekable(range(3))
it.prepend(*reversed((10, 11, 12)))
actual = list(it)
expected = [12, 11, 10, 0, 1, 2]
> self.assertEqual(actual, expected)
E AssertionError: Lists differ: [0, 1, 2] != [12, 11, 10, 0, 1, 2]
E
E First differing element 0:
E 0
E 12
E
E Second list contains 3 additional elements.
E First extra element 3:
E 0
E
E - [0, 1, 2]
E + [12, 11, 10, 0, 1, 2]
tests/test_more.py:459: AssertionError
test_more.py::PeekableTests::test_prepend_slicing
test_more.py::PeekableTests::test_prepend_slicing
self =
def test_prepend_slicing(self):
"""Tests interaction between prepending and slicing"""
seq = list(range(20))
p = mi.peekable(seq)
p.prepend(30, 40, 50)
pseq = [30, 40, 50] + seq # pseq for prepended_seq
# adapt the specific tests from test_slicing
> self.assertEqual(p[0], 30)
E AssertionError: 0 != 30
tests/test_more.py:405: AssertionError
test_more.py::PeekableTests::test_prepend_truthiness
test_more.py::PeekableTests::test_prepend_truthiness
self =
def test_prepend_truthiness(self):
"""Tests that ``__bool__()`` or ``__nonzero__()`` works properly
with ``prepend()``"""
it = mi.peekable(range(5))
self.assertTrue(it)
actual = list(it)
> self.assertFalse(it)
E AssertionError: is not false
tests/test_more.py:364: AssertionError
test_more.py::PeekableTests::test_simple_peeking
test_more.py::PeekableTests::test_simple_peeking
self =
def test_simple_peeking(self):
"""Make sure ``next`` and ``peek`` advance and don't advance the
iterator, respectively.
"""
p = self.cls(range(10))
self.assertEqual(next(p), 0)
> self.assertEqual(p.peek(), 1)
E AssertionError: None != 1
tests/test_more.py:231: AssertionError
test_more.py::PeekableTests::test_slicing
test_more.py::PeekableTests::test_slicing
self =
def test_slicing(self):
"""Slicing the peekable shouldn't advance the iterator."""
seq = list('abcdefghijkl')
p = mi.peekable(seq)
# Slicing the peekable should just be like slicing a re-iterable
> self.assertEqual(p[1:4], seq[1:4])
tests/test_more.py:271:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self =
index = slice(1, 4, None)
def __getitem__(self, index):
if isinstance(index, slice):
> return self._get_slice(index)
E AttributeError: 'peekable' object has no attribute '_get_slice'
more_itertools/more.py:336: AttributeError
test_more.py::PeekableTests::test_slicing_error
test_more.py::PeekableTests::test_slicing_error
self =
def test_slicing_error(self):
iterable = '01234567'
p = mi.peekable(iter(iterable))
# Prime the cache
p.peek()
old_cache = list(p._cache)
# Illegal slice
with self.assertRaises(ValueError):
> p[1:-1:0]
tests/test_more.py:312:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
def __getitem__(self, index):
if isinstance(index, slice):
> return self._get_slice(index)
E AttributeError: 'peekable' object has no attribute '_get_slice'
more_itertools/more.py:336: AttributeError
test_more.py::PeekableTests::test_slicing_reset
test_more.py::PeekableTests::test_slicing_reset
self =
def test_slicing_reset(self):
"""Test slicing on a fresh iterable each time"""
iterable = ['0', '1', '2', '3', '4', '5']
indexes = list(range(-4, len(iterable) + 4)) + [None]
steps = [1, 2, 3, 4, -1, -2, -3, 4]
for slice_args in product(indexes, indexes, steps):
it = iter(iterable)
p = mi.peekable(it)
next(p)
index = slice(*slice_args)
> actual = p[index]
tests/test_more.py:298:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self =
index = slice(-4, -4, 1)
def __getitem__(self, index):
if isinstance(index, slice):
> return self._get_slice(index)
E AttributeError: 'peekable' object has no attribute '_get_slice'
more_itertools/more.py:336: AttributeError
test_more.py::PeekableTests::test_truthiness
test_more.py::PeekableTests::test_truthiness
self =
def test_truthiness(self):
"""Make sure a ``peekable`` tests true iff there are items remaining in
the iterable.
"""
p = self.cls([])
> self.assertFalse(p)
E AssertionError: is not false
tests/test_more.py:219: AssertionError
test_more.py::ConsumerTests::test_consumer
test_more.py::ConsumerTests::test_consumer
self =
def test_consumer(self):
@mi.consumer
def eater():
while True:
x = yield # noqa
> e = eater()
E TypeError: 'NoneType' object is not callable
tests/test_more.py:471: TypeError
test_more.py::DistinctPermutationsTests::test_basic
test_more.py::DistinctPermutationsTests::test_basic
self =
def test_basic(self):
iterable = ['z', 'a', 'a', 'q', 'q', 'q', 'y']
> actual = list(mi.distinct_permutations(iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:478: TypeError
test_more.py::DistinctPermutationsTests::test_r
test_more.py::DistinctPermutationsTests::test_r
self =
def test_r(self):
for iterable, r in (
('mississippi', 0),
('mississippi', 1),
('mississippi', 6),
('mississippi', 7),
('mississippi', 12),
([0, 1, 1, 0], 0),
([0, 1, 1, 0], 1),
([0, 1, 1, 0], 2),
([0, 1, 1, 0], 3),
([0, 1, 1, 0], 4),
(['a'], 0),
(['a'], 1),
(['a'], 5),
([], 0),
([], 1),
([], 4),
):
with self.subTest(iterable=iterable, r=r):
expected = set(permutations(iterable, r))
> actual = list(mi.distinct_permutations(iter(iterable), r))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:503: TypeError
test_more.py::DistinctPermutationsTests::test_unhashable
test_more.py::DistinctPermutationsTests::test_unhashable
self =
def test_unhashable(self):
iterable = ([1], [1], 2)
> actual = list(mi.distinct_permutations(iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:528: TypeError
test_more.py::DistinctPermutationsTests::test_unsortable
test_more.py::DistinctPermutationsTests::test_unsortable
self =
def test_unsortable(self):
iterable = ['1', 2, 2, 3, 3, 3]
> actual = list(mi.distinct_permutations(iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:508: TypeError
test_more.py::DistinctPermutationsTests::test_unsortable_r
test_more.py::DistinctPermutationsTests::test_unsortable_r
self =
def test_unsortable_r(self):
iterable = ['1', 2, 2, 3, 3, 3]
for r in range(len(iterable) + 1):
with self.subTest(iterable=iterable, r=r):
> actual = list(mi.distinct_permutations(iterable, r=r))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:516: TypeError
test_more.py::DistinctPermutationsTests::test_unsorted_equivalent
test_more.py::DistinctPermutationsTests::test_unsorted_equivalent
self =
def test_unsorted_equivalent(self):
iterable = [1, True, '3']
> actual = list(mi.distinct_permutations(iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:522: TypeError
test_more.py::IlenTests::test_ilen
test_more.py::IlenTests::test_ilen
self =
def test_ilen(self):
"""Sanity-checks for ``ilen()``."""
# Non-empty
> self.assertEqual(
mi.ilen(filter(lambda x: x % 10 == 0, range(101))), 11
)
E AssertionError: None != 11
tests/test_more.py:537: AssertionError
test_more.py::MinMaxTests::test_basic
test_more.py::MinMaxTests::test_basic
self =
def test_basic(self):
for iterable, expected in (
# easy case
([0, 1, 2, 3], (0, 3)),
# min and max are not in the extremes + we have `int`s and `float`s
([3, 5.5, -1, 2], (-1, 5.5)),
# unordered collection
({3, 5.5, -1, 2}, (-1, 5.5)),
# with repetitions
([3, 5.5, float('-Inf'), 5.5], (float('-Inf'), 5.5)),
# other collections
('banana', ('a', 'n')),
({0: 1, 2: 100, 1: 10}, (0, 2)),
(range(3, 14), (3, 13)),
):
with self.subTest(iterable=iterable, expected=expected):
# check for expected results
> self.assertTupleEqual(mi.minmax(iterable), expected)
E AssertionError: First sequence is not a tuple: None
tests/test_more.py:566: AssertionError
test_more.py::MinMaxTests::test_default
test_more.py::MinMaxTests::test_default
self =
def test_default(self):
> with self.assertRaises(ValueError):
E AssertionError: ValueError not raised
tests/test_more.py:595: AssertionError
test_more.py::MinMaxTests::test_iterables
test_more.py::MinMaxTests::test_iterables
self =
def test_iterables(self):
> self.assertTupleEqual(mi.minmax(x for x in [0, 1, 2, 3]), (0, 3))
E AssertionError: First sequence is not a tuple: None
tests/test_more.py:577: AssertionError
test_more.py::MinMaxTests::test_key
test_more.py::MinMaxTests::test_key
self =
def test_key(self):
> self.assertTupleEqual(
mi.minmax({(), (1, 4, 2), 'abcde', range(4)}, key=len),
((), 'abcde'),
)
E AssertionError: First sequence is not a tuple: None
tests/test_more.py:586: AssertionError
test_more.py::MinMaxTests::test_unpacked
test_more.py::MinMaxTests::test_unpacked
self =
def test_unpacked(self):
> self.assertTupleEqual(mi.minmax(2, 3, 1), (1, 3))
E AssertionError: First sequence is not a tuple: None
tests/test_more.py:573: AssertionError
test_more.py::WithIterTests::test_with_iter
test_more.py::WithIterTests::test_with_iter
self =
def test_with_iter(self):
s = StringIO('One fish\nTwo fish')
> initial_words = [line.split()[0] for line in mi.with_iter(s)]
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:605: TypeError
test_more.py::OneTests::test_basic
test_more.py::OneTests::test_basic
self =
def test_basic(self):
it = iter(['item'])
> self.assertEqual(mi.one(it), 'item')
E AssertionError: None != 'item'
tests/test_more.py:616: AssertionError
test_more.py::OneTests::test_too_long
test_more.py::OneTests::test_too_long
self =
def test_too_long(self):
it = count()
> self.assertRaises(ValueError, lambda: mi.one(it)) # burn 0 and 1
E AssertionError: ValueError not raised by
tests/test_more.py:639: AssertionError
test_more.py::OneTests::test_too_long_default_message
test_more.py::OneTests::test_too_long_default_message
self =
def test_too_long_default_message(self):
it = count()
> self.assertRaisesRegex(
ValueError,
"Expected exactly one item in "
"iterable, but got 0, 1, and "
"perhaps more.",
lambda: mi.one(it),
)
E AssertionError: ValueError not raised by
tests/test_more.py:647: AssertionError
test_more.py::OneTests::test_too_short
test_more.py::OneTests::test_too_short
self =
def test_too_short(self):
it = iter([])
for too_short, exc_type in [
(None, ValueError),
(IndexError, IndexError),
]:
with self.subTest(too_short=too_short):
try:
mi.one(it, too_short=too_short)
except exc_type:
formatted_exc = format_exc()
self.assertIn('StopIteration', formatted_exc)
self.assertIn(
'The above exception was the direct cause',
formatted_exc,
)
else:
> self.fail()
E AssertionError: None
tests/test_more.py:635: AssertionError
test_more.py::IntersperseTest::test_even
test_more.py::IntersperseTest::test_even
self =
def test_even(self):
iterable = (x for x in '01')
self.assertEqual(
> list(mi.intersperse(None, iterable)), ['0', None, '1']
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:662: TypeError
test_more.py::IntersperseTest::test_n
test_more.py::IntersperseTest::test_n
self =
def test_n(self):
for n, element, expected in [
(1, '_', ['0', '_', '1', '_', '2', '_', '3', '_', '4', '_', '5']),
(2, '_', ['0', '1', '_', '2', '3', '_', '4', '5']),
(3, '_', ['0', '1', '2', '_', '3', '4', '5']),
(4, '_', ['0', '1', '2', '3', '_', '4', '5']),
(5, '_', ['0', '1', '2', '3', '4', '_', '5']),
(6, '_', ['0', '1', '2', '3', '4', '5']),
(7, '_', ['0', '1', '2', '3', '4', '5']),
(3, ['a', 'b'], ['0', '1', '2', ['a', 'b'], '3', '4', '5']),
]:
iterable = (x for x in '012345')
> actual = list(mi.intersperse(element, iterable, n=n))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:693: TypeError
test_more.py::IntersperseTest::test_n_zero
test_more.py::IntersperseTest::test_n_zero
self =
def test_n_zero(self):
> self.assertRaises(
ValueError, lambda: list(mi.intersperse('x', '012', n=0))
)
tests/test_more.py:697:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> ValueError, lambda: list(mi.intersperse('x', '012', n=0))
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:698: TypeError
test_more.py::IntersperseTest::test_nested
test_more.py::IntersperseTest::test_nested
self =
def test_nested(self):
element = ('a', 'b')
iterable = (x for x in '012')
> actual = list(mi.intersperse(element, iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:674: TypeError
test_more.py::IntersperseTest::test_not_iterable
test_more.py::IntersperseTest::test_not_iterable
self =
def test_not_iterable(self):
> self.assertRaises(TypeError, lambda: mi.intersperse('x', 1))
E AssertionError: TypeError not raised by
tests/test_more.py:679: AssertionError
test_more.py::IntersperseTest::test_odd
test_more.py::IntersperseTest::test_odd
self =
def test_odd(self):
iterable = (x for x in '012')
self.assertEqual(
> list(mi.intersperse(None, iterable)), ['0', None, '1', None, '2']
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:668: TypeError
test_more.py::UniqueToEachTests::test_all_unique
test_more.py::UniqueToEachTests::test_all_unique
self =
def test_all_unique(self):
"""When all the input iterables are unique the output should match
the input."""
iterables = [[1, 2], [3, 4, 5], [6, 7, 8]]
> self.assertEqual(mi.unique_to_each(*iterables), iterables)
E AssertionError: None != [[1, 2], [3, 4, 5], [6, 7, 8]]
tests/test_more.py:709: AssertionError
test_more.py::UniqueToEachTests::test_duplicates
test_more.py::UniqueToEachTests::test_duplicates
self =
def test_duplicates(self):
"""When there are duplicates in any of the input iterables that aren't
in the rest, those duplicates should be emitted."""
iterables = ["mississippi", "missouri"]
> self.assertEqual(
mi.unique_to_each(*iterables), [['p', 'p'], ['o', 'u', 'r']]
)
E AssertionError: None != [['p', 'p'], ['o', 'u', 'r']]
tests/test_more.py:715: AssertionError
test_more.py::UniqueToEachTests::test_mixed
test_more.py::UniqueToEachTests::test_mixed
self =
def test_mixed(self):
"""When the input iterables contain different types the function should
still behave properly"""
iterables = ['x', (i for i in range(3)), [1, 2, 3], tuple()]
> self.assertEqual(mi.unique_to_each(*iterables), [['x'], [0], [3], []])
E AssertionError: None != [['x'], [0], [3], []]
tests/test_more.py:723: AssertionError
test_more.py::WindowedTests::test_basic
test_more.py::WindowedTests::test_basic
self =
def test_basic(self):
iterable = [1, 2, 3, 4, 5]
for n, expected in (
(6, [(1, 2, 3, 4, 5, None)]),
(5, [(1, 2, 3, 4, 5)]),
(4, [(1, 2, 3, 4), (2, 3, 4, 5)]),
(3, [(1, 2, 3), (2, 3, 4), (3, 4, 5)]),
(2, [(1, 2), (2, 3), (3, 4), (4, 5)]),
(1, [(1,), (2,), (3,), (4,), (5,)]),
(0, [()]),
):
with self.subTest(n=n):
> actual = list(mi.windowed(iterable, n))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:740: TypeError
test_more.py::WindowedTests::test_empty_seq
test_more.py::WindowedTests::test_empty_seq
self =
def test_empty_seq(self):
> actual = list(mi.windowed([], 3))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:778: TypeError
test_more.py::WindowedTests::test_fillvalue
test_more.py::WindowedTests::test_fillvalue
self =
def test_fillvalue(self):
> actual = list(mi.windowed([1, 2, 3, 4, 5], 6, fillvalue='!'))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:744: TypeError
test_more.py::WindowedTests::test_fillvalue_step
test_more.py::WindowedTests::test_fillvalue_step
self =
def test_fillvalue_step(self):
> actual = list(mi.windowed([1, 2, 3, 4, 5], 3, fillvalue='!', step=3))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:769: TypeError
test_more.py::WindowedTests::test_invalid_step
test_more.py::WindowedTests::test_invalid_step
self =
def test_invalid_step(self):
# Step must be greater than or equal to 1
with self.assertRaises(ValueError):
> list(mi.windowed([1, 2, 3, 4, 5], 3, step=0))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:766: TypeError
test_more.py::WindowedTests::test_negative
test_more.py::WindowedTests::test_negative
self =
def test_negative(self):
with self.assertRaises(ValueError):
> list(mi.windowed([1, 2, 3, 4, 5], -1))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:775: TypeError
test_more.py::WindowedTests::test_step
test_more.py::WindowedTests::test_step
self =
def test_step(self):
iterable = [1, 2, 3, 4, 5, 6, 7]
for n, step, expected in [
(3, 2, [(1, 2, 3), (3, 4, 5), (5, 6, 7)]), # n > step
(3, 3, [(1, 2, 3), (4, 5, 6), (7, None, None)]), # n == step
(3, 4, [(1, 2, 3), (5, 6, 7)]), # lines up nicely
(3, 5, [(1, 2, 3), (6, 7, None)]), # off by one
(3, 6, [(1, 2, 3), (7, None, None)]), # off by two
(3, 7, [(1, 2, 3)]), # step past the end
(7, 8, [(1, 2, 3, 4, 5, 6, 7)]), # step > len(iterable)
]:
with self.subTest(n=n, step=step):
> actual = list(mi.windowed(iterable, n, step=step))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:760: TypeError
test_more.py::SubstringsTests::test_basic
test_more.py::SubstringsTests::test_basic
self =
def test_basic(self):
iterable = (x for x in range(4))
> actual = list(mi.substrings(iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:786: TypeError
test_more.py::SubstringsTests::test_empty
test_more.py::SubstringsTests::test_empty
self =
def test_empty(self):
iterable = iter([])
> actual = list(mi.substrings(iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:816: TypeError
test_more.py::SubstringsTests::test_order
test_more.py::SubstringsTests::test_order
self =
def test_order(self):
iterable = [2, 0, 1]
> actual = list(mi.substrings(iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:822: TypeError
test_more.py::SubstringsTests::test_strings
test_more.py::SubstringsTests::test_strings
self =
def test_strings(self):
iterable = 'abc'
> actual = list(mi.substrings(iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:803: TypeError
test_more.py::SubstringsIndexesTests::test_basic
test_more.py::SubstringsIndexesTests::test_basic
self =
def test_basic(self):
sequence = [x for x in range(4)]
> actual = list(mi.substrings_indexes(sequence))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:830: TypeError
test_more.py::SubstringsIndexesTests::test_empty
test_more.py::SubstringsIndexesTests::test_empty
self =
def test_empty(self):
sequence = []
> actual = list(mi.substrings_indexes(sequence))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:860: TypeError
test_more.py::SubstringsIndexesTests::test_order
test_more.py::SubstringsIndexesTests::test_order
self =
def test_order(self):
sequence = [2, 0, 1]
> actual = list(mi.substrings_indexes(sequence))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:866: TypeError
test_more.py::SubstringsIndexesTests::test_reverse
test_more.py::SubstringsIndexesTests::test_reverse
self =
def test_reverse(self):
sequence = [2, 0, 1]
> actual = list(mi.substrings_indexes(sequence, reverse=True))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:879: TypeError
test_more.py::SubstringsIndexesTests::test_strings
test_more.py::SubstringsIndexesTests::test_strings
self =
def test_strings(self):
sequence = 'abc'
> actual = list(mi.substrings_indexes(sequence))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:847: TypeError
test_more.py::BucketTests::test_basic
test_more.py::BucketTests::test_basic
self =
def test_basic(self):
iterable = [10, 20, 30, 11, 21, 31, 12, 22, 23, 33]
D = mi.bucket(iterable, key=lambda x: 10 * (x // 10))
# In-order access
> self.assertEqual(list(D[10]), [10, 11, 12])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:897: TypeError
test_more.py::BucketTests::test_in
test_more.py::BucketTests::test_in
self =
def test_in(self):
iterable = [10, 20, 30, 11, 21, 31, 12, 22, 23, 33]
D = mi.bucket(iterable, key=lambda x: 10 * (x // 10))
> self.assertIn(10, D)
tests/test_more.py:909:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = , value = 10
def __contains__(self, value):
if not self._validator(value):
return False
try:
> item = next(self[value])
E TypeError: 'NoneType' object is not an iterator
more_itertools/more.py:701: TypeError
test_more.py::BucketTests::test_list
test_more.py::BucketTests::test_list
self =
def test_list(self):
iterable = [10, 20, 30, 11, 21, 31, 12, 22, 23, 33]
D = mi.bucket(iterable, key=lambda x: 10 * (x // 10))
> self.assertEqual(list(D[10]), [10, 11, 12])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:930: TypeError
test_more.py::BucketTests::test_list_validator
test_more.py::BucketTests::test_list_validator
self =
def test_list_validator(self):
iterable = [10, 20, 30, 11, 21, 31, 12, 22, 23, 33]
key = lambda x: 10 * (x // 10)
validator = lambda x: x != 20
D = mi.bucket(iterable, key, validator=validator)
self.assertEqual(set(D), {10, 30})
> self.assertEqual(list(D[10]), [10, 11, 12])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:941: TypeError
test_more.py::BucketTests::test_validator
test_more.py::BucketTests::test_validator
self =
def test_validator(self):
iterable = count(0)
key = lambda x: int(str(x)[0]) # First digit of each number
validator = lambda x: 0 < x < 10 # No leading zeros
D = mi.bucket(iterable, key, validator=validator)
> self.assertEqual(mi.take(3, D[1]), [1, 10, 11])
tests/test_more.py:922:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
n = 3, iterable = None
def take(n, iterable):
"""Return first *n* items of the iterable as a list.
>>> take(3, range(10))
[0, 1, 2]
If there are fewer than *n* items in the iterable, all of them are
returned.
>>> take(10, range(3))
[0, 1, 2]
"""
> return list(islice(iterable, n))
E TypeError: 'NoneType' object is not iterable
more_itertools/recipes.py:71: TypeError
test_more.py::SpyTests::test_basic
test_more.py::SpyTests::test_basic
self =
def test_basic(self):
original_iterable = iter('abcdefg')
> head, new_iterable = mi.spy(original_iterable)
E TypeError: cannot unpack non-iterable NoneType object
tests/test_more.py:951: TypeError
test_more.py::SpyTests::test_immutable
test_more.py::SpyTests::test_immutable
self =
def test_immutable(self):
original_iterable = iter('abcdefg')
> head, new_iterable = mi.spy(original_iterable, 3)
E TypeError: cannot unpack non-iterable NoneType object
tests/test_more.py:981: TypeError
test_more.py::SpyTests::test_too_many
test_more.py::SpyTests::test_too_many
self =
def test_too_many(self):
original_iterable = iter('abc')
> head, new_iterable = mi.spy(original_iterable, 4)
E TypeError: cannot unpack non-iterable NoneType object
tests/test_more.py:969: TypeError
test_more.py::SpyTests::test_unpacking
test_more.py::SpyTests::test_unpacking
self =
def test_unpacking(self):
original_iterable = iter('abcdefg')
> (first, second, third), new_iterable = mi.spy(original_iterable, 3)
E TypeError: cannot unpack non-iterable NoneType object
tests/test_more.py:959: TypeError
test_more.py::SpyTests::test_zero
test_more.py::SpyTests::test_zero
self =
def test_zero(self):
original_iterable = iter('abc')
> head, new_iterable = mi.spy(original_iterable, 0)
E TypeError: cannot unpack non-iterable NoneType object
tests/test_more.py:975: TypeError
test_more.py::InterleaveTests::test_even
test_more.py::InterleaveTests::test_even
self =
def test_even(self):
> actual = list(mi.interleave([1, 4, 7], [2, 5, 8], [3, 6, 9]))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:991: TypeError
test_more.py::InterleaveTests::test_mixed_types
test_more.py::InterleaveTests::test_mixed_types
self =
def test_mixed_types(self):
it_list = ['a', 'b', 'c', 'd']
it_str = '12345'
it_inf = count()
> actual = list(mi.interleave(it_list, it_str, it_inf))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1004: TypeError
test_more.py::InterleaveTests::test_short
test_more.py::InterleaveTests::test_short
self =
def test_short(self):
> actual = list(mi.interleave([1, 4], [2, 5, 7], [3, 6, 8]))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:996: TypeError
test_more.py::InterleaveLongestTests::test_even
test_more.py::InterleaveLongestTests::test_even
self =
def test_even(self):
> actual = list(mi.interleave_longest([1, 4, 7], [2, 5, 8], [3, 6, 9]))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1011: TypeError
test_more.py::InterleaveLongestTests::test_mixed_types
test_more.py::InterleaveLongestTests::test_mixed_types
self =
def test_mixed_types(self):
it_list = ['a', 'b', 'c', 'd']
it_str = '12345'
it_gen = (x for x in range(3))
> actual = list(mi.interleave_longest(it_list, it_str, it_gen))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1024: TypeError
test_more.py::InterleaveLongestTests::test_short
test_more.py::InterleaveLongestTests::test_short
self =
def test_short(self):
> actual = list(mi.interleave_longest([1, 4], [2, 5, 7], [3, 6, 8]))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1016: TypeError
test_more.py::InterleaveEvenlyTests::test_argument_mismatch_raises
test_more.py::InterleaveEvenlyTests::test_argument_mismatch_raises
self =
def test_argument_mismatch_raises(self):
# pass mismatching number of iterables and lengths
iterables = [range(3)]
lengths = [3, 4]
with self.assertRaises(ValueError):
> list(mi.interleave_evenly(iterables, lengths=lengths))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1130: TypeError
test_more.py::InterleaveEvenlyTests::test_degenerate_empty
test_more.py::InterleaveEvenlyTests::test_degenerate_empty
self =
def test_degenerate_empty(self):
a = [1, 2, 3]
b = []
expected = [1, 2, 3]
> actual = list(mi.interleave_evenly([a, b]))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1068: TypeError
test_more.py::InterleaveEvenlyTests::test_degenerate_one
test_more.py::InterleaveEvenlyTests::test_degenerate_one
self =
def test_degenerate_one(self):
a = [0, 1, 2, 3, 4]
b = [5]
expected = [0, 1, 2, 5, 3, 4]
> actual = list(mi.interleave_evenly([a, b]))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1061: TypeError
test_more.py::InterleaveEvenlyTests::test_equal_lengths
test_more.py::InterleaveEvenlyTests::test_equal_lengths
self =
def test_equal_lengths(self):
# when lengths are equal, the relative order shouldn't change
a = [1, 2, 3]
b = [5, 6, 7]
> actual = list(mi.interleave_evenly([a, b]))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1034: TypeError
test_more.py::InterleaveEvenlyTests::test_manual_lengths
test_more.py::InterleaveEvenlyTests::test_manual_lengths
self =
def test_manual_lengths(self):
a = combinations(range(4), 2)
len_a = 4 * (4 - 1) // 2 # == 6
b = combinations(range(4), 3)
len_b = 4
expected = [
(0, 1),
(0, 1, 2),
(0, 2),
(0, 3),
(0, 1, 3),
(1, 2),
(0, 2, 3),
(1, 3),
(2, 3),
(1, 2, 3),
]
> actual = list(mi.interleave_evenly([a, b], lengths=[len_a, len_b]))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1116: TypeError
test_more.py::InterleaveEvenlyTests::test_many_iters
test_more.py::InterleaveEvenlyTests::test_many_iters
self =
def test_many_iters(self):
# smoke test with many iterables: create iterables with a random
# number of elements starting with a character ("a0", "a1", ...)
rng = Random(0)
iterables = []
for ch in ascii_letters:
length = rng.randint(0, 100)
iterable = [f"{ch}{i}" for i in range(length)]
iterables.append(iterable)
> interleaved = list(mi.interleave_evenly(iterables))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1089: TypeError
test_more.py::InterleaveEvenlyTests::test_no_length_raises
test_more.py::InterleaveEvenlyTests::test_no_length_raises
self =
def test_no_length_raises(self):
# combinations doesn't have __len__, should trigger ValueError
iterables = [range(5), combinations(range(5), 2)]
with self.assertRaises(ValueError):
> list(mi.interleave_evenly(iterables))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1123: TypeError
test_more.py::InterleaveEvenlyTests::test_not_proportional
test_more.py::InterleaveEvenlyTests::test_not_proportional
self =
def test_not_proportional(self):
a = [1, 2, 3, 4, 5, 6, 7]
b = [8, 9, 10]
expected = [1, 2, 8, 3, 4, 9, 5, 6, 10, 7]
> actual = list(mi.interleave_evenly([a, b]))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1054: TypeError
test_more.py::InterleaveEvenlyTests::test_proportional
test_more.py::InterleaveEvenlyTests::test_proportional
self =
def test_proportional(self):
# easy case where the iterables have proportional length
a = [1, 2, 3, 4]
b = [5, 6]
> actual = list(mi.interleave_evenly([a, b]))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1042: TypeError
test_more.py::InterleaveEvenlyTests::test_three_iters
test_more.py::InterleaveEvenlyTests::test_three_iters
self =
def test_three_iters(self):
a = ["a1", "a2", "a3", "a4", "a5"]
b = ["b1", "b2", "b3"]
c = ["c1"]
> actual = list(mi.interleave_evenly([a, b, c]))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1075: TypeError
test_more.py::TestCollapse::test_collapse
test_more.py::TestCollapse::test_collapse
self =
def test_collapse(self):
l = [[1], 2, [[3], 4], [[[5]]]]
> self.assertEqual(list(mi.collapse(l)), [1, 2, 3, 4, 5])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1138: TypeError
test_more.py::TestCollapse::test_collapse_flatten
test_more.py::TestCollapse::test_collapse_flatten
self =
def test_collapse_flatten(self):
l = [[1], [2], [[3], 4], [[[5]]]]
> self.assertEqual(list(mi.collapse(l, levels=1)), list(mi.flatten(l)))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1152: TypeError
test_more.py::TestCollapse::test_collapse_to_bytes
test_more.py::TestCollapse::test_collapse_to_bytes
self =
def test_collapse_to_bytes(self):
l = [[b"s1"], b"s2", [[b"s3"], b"s4"], [[[b"s5"]]]]
self.assertEqual(
> list(mi.collapse(l)), [b"s1", b"s2", b"s3", b"s4", b"s5"]
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1147: TypeError
test_more.py::TestCollapse::test_collapse_to_level
test_more.py::TestCollapse::test_collapse_to_level
self =
def test_collapse_to_level(self):
l = [[1], 2, [[3], 4], [[[5]]]]
> self.assertEqual(list(mi.collapse(l, levels=2)), [1, 2, 3, 4, [5]])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1156: TypeError
test_more.py::TestCollapse::test_collapse_to_list
test_more.py::TestCollapse::test_collapse_to_list
self =
def test_collapse_to_list(self):
l = (1, [2], (3, [4, (5,)], 'ab'))
> actual = list(mi.collapse(l, base_type=list))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1164: TypeError
test_more.py::TestCollapse::test_collapse_to_string
test_more.py::TestCollapse::test_collapse_to_string
self =
def test_collapse_to_string(self):
l = [["s1"], "s2", [["s3"], "s4"], [[["s5"]]]]
> self.assertEqual(list(mi.collapse(l)), ["s1", "s2", "s3", "s4", "s5"])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1142: TypeError
test_more.py::SideEffectTests::test_before_after
test_more.py::SideEffectTests::test_before_after
self =
def test_before_after(self):
f = StringIO()
collector = []
def func(item):
print(item, file=f)
collector.append(f.getvalue())
def it():
yield 'a'
yield 'b'
raise RuntimeError('kaboom')
before = lambda: print('HEADER', file=f)
after = f.close
try:
mi.consume(mi.side_effect(func, it(), before=before, after=after))
except RuntimeError:
pass
# The iterable should have been written to the file
> self.assertEqual(collector, ['HEADER\na\n', 'HEADER\na\nb\n'])
E AssertionError: Lists differ: [] != ['HEADER\na\n', 'HEADER\na\nb\n']
E
E Second list contains 2 additional elements.
E First extra element 0:
E 'HEADER\na\n'
E
E - []
E + ['HEADER\na\n', 'HEADER\na\nb\n']
tests/test_more.py:1216: AssertionError
test_more.py::SideEffectTests::test_before_fails
test_more.py::SideEffectTests::test_before_fails
self =
def test_before_fails(self):
f = StringIO()
func = lambda x: print(x, file=f)
def before():
raise RuntimeError('ouch')
try:
mi.consume(
mi.side_effect(func, 'abc', before=before, after=f.close)
)
except RuntimeError:
pass
# The file should be closed even though something bad happened in the
# before function
> self.assertTrue(f.closed)
E AssertionError: False is not true
tests/test_more.py:1237: AssertionError
test_more.py::SideEffectTests::test_chunked
test_more.py::SideEffectTests::test_chunked
self =
def test_chunked(self):
# The function increments the counter for each call
counter = [0]
def func(arg):
counter[0] += 1
> result = list(mi.side_effect(func, range(10), 2))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1190: TypeError
test_more.py::SideEffectTests::test_individual
test_more.py::SideEffectTests::test_individual
self =
def test_individual(self):
# The function increments the counter for each call
counter = [0]
def func(arg):
counter[0] += 1
> result = list(mi.side_effect(func, range(10)))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1179: TypeError
test_more.py::SlicedTests::test_even
test_more.py::SlicedTests::test_even
self =
def test_even(self):
"""Test when the length of the sequence is divisible by *n*"""
seq = 'ABCDEFGHI'
> self.assertEqual(list(mi.sliced(seq, 3)), ['ABC', 'DEF', 'GHI'])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1246: TypeError
test_more.py::SlicedTests::test_numpy_like_array
test_more.py::SlicedTests::test_numpy_like_array
self =
def test_numpy_like_array(self):
# Numpy arrays don't behave like Python lists - calling bool()
# on them doesn't return False for empty lists and True for non-empty
# ones. Emulate that behavior.
class FalseList(list):
def __getitem__(self, key):
ret = super().__getitem__(key)
if isinstance(key, slice):
return FalseList(ret)
return ret
def __bool__(self):
return False
seq = FalseList(range(9))
> actual = list(mi.sliced(seq, 3))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1281: TypeError
test_more.py::SlicedTests::test_odd
test_more.py::SlicedTests::test_odd
self =
def test_odd(self):
"""Test when the length of the sequence is not divisible by *n*"""
seq = 'ABCDEFGHI'
> self.assertEqual(list(mi.sliced(seq, 4)), ['ABCD', 'EFGH', 'I'])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1251: TypeError
test_more.py::SlicedTests::test_odd_and_strict
test_more.py::SlicedTests::test_odd_and_strict
self =
def test_odd_and_strict(self):
seq = [x for x in 'ABCDEFGHI']
with self.assertRaises(ValueError):
> list(mi.sliced(seq, 4, strict=True))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1263: TypeError
test_more.py::SplitAtTests::test_basic
test_more.py::SplitAtTests::test_basic
self =
def test_basic(self):
for iterable, separator in [
('a,bb,ccc,dddd', ','),
(',a,bb,ccc,dddd', ','),
('a,bb,ccc,dddd,', ','),
('a,bb,ccc,,dddd', ','),
('', ','),
(',', ','),
('a,bb,ccc,dddd', ';'),
]:
with self.subTest(iterable=iterable, separator=separator):
it = iter(iterable)
pred = lambda x: x == separator
> actual = [''.join(x) for x in mi.split_at(it, pred)]
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1300: TypeError
test_more.py::SplitAtTests::test_combination
test_more.py::SplitAtTests::test_combination
self =
def test_combination(self):
iterable = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
pred = lambda x: x % 3 == 0
> actual = list(
mi.split_at(iterable, pred, maxsplit=2, keep_separator=True)
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1335: TypeError
test_more.py::SplitAtTests::test_keep_separator
test_more.py::SplitAtTests::test_keep_separator
self =
def test_keep_separator(self):
separator = ','
pred = lambda x: x == separator
for iterable, expected in [
('a,bb,ccc', ['a', ',', 'bb', ',', 'ccc']),
(',a,bb,ccc', ['', ',', 'a', ',', 'bb', ',', 'ccc']),
('a,bb,ccc,', ['a', ',', 'bb', ',', 'ccc', ',', '']),
]:
with self.subTest(iterable=iterable):
it = iter(iterable)
result = mi.split_at(it, pred, keep_separator=True)
> actual = [''.join(x) for x in result]
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1329: TypeError
test_more.py::SplitAtTests::test_maxsplit
test_more.py::SplitAtTests::test_maxsplit
self =
def test_maxsplit(self):
iterable = 'a,bb,ccc,dddd'
separator = ','
pred = lambda x: x == separator
for maxsplit in range(-1, 4):
with self.subTest(maxsplit=maxsplit):
it = iter(iterable)
result = mi.split_at(it, pred, maxsplit=maxsplit)
> actual = [''.join(x) for x in result]
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1313: TypeError
test_more.py::SplitBeforeTest::test_empty_collection
test_more.py::SplitBeforeTest::test_empty_collection
self =
def test_empty_collection(self):
> actual = list(mi.split_before([], lambda c: bool(c)))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1361: TypeError
test_more.py::SplitBeforeTest::test_ends_with_sep
test_more.py::SplitBeforeTest::test_ends_with_sep
self =
def test_ends_with_sep(self):
> actual = list(mi.split_before('ooxoox', lambda c: c == 'x'))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1351: TypeError
test_more.py::SplitBeforeTest::test_max_split
test_more.py::SplitBeforeTest::test_max_split
self =
def test_max_split(self):
for args, expected in [
(
('a,b,c,d', lambda c: c == ',', -1),
[['a'], [',', 'b'], [',', 'c'], [',', 'd']],
),
(
('a,b,c,d', lambda c: c == ',', 0),
[['a', ',', 'b', ',', 'c', ',', 'd']],
),
(
('a,b,c,d', lambda c: c == ',', 1),
[['a'], [',', 'b', ',', 'c', ',', 'd']],
),
(
('a,b,c,d', lambda c: c == ',', 2),
[['a'], [',', 'b'], [',', 'c', ',', 'd']],
),
(
('a,b,c,d', lambda c: c == ',', 10),
[['a'], [',', 'b'], [',', 'c'], [',', 'd']],
),
(
('a,b,c,d', lambda c: c == '@', 2),
[['a', ',', 'b', ',', 'c', ',', 'd']],
),
(
('a,b,c,d', lambda c: c != ',', 2),
[['a', ','], ['b', ','], ['c', ',', 'd']],
),
]:
> actual = list(mi.split_before(*args))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1396: TypeError
test_more.py::SplitBeforeTest::test_no_sep
test_more.py::SplitBeforeTest::test_no_sep
self =
def test_no_sep(self):
> actual = list(mi.split_before('ooo', lambda c: c == 'x'))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1356: TypeError
test_more.py::SplitBeforeTest::test_starts_with_sep
test_more.py::SplitBeforeTest::test_starts_with_sep
self =
def test_starts_with_sep(self):
> actual = list(mi.split_before('xooxoo', lambda c: c == 'x'))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1346: TypeError
test_more.py::SplitAfterTest::test_ends_with_sep
test_more.py::SplitAfterTest::test_ends_with_sep
self =
def test_ends_with_sep(self):
> actual = list(mi.split_after('ooxoox', lambda c: c == 'x'))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1409: TypeError
test_more.py::SplitAfterTest::test_max_split
test_more.py::SplitAfterTest::test_max_split
self =
def test_max_split(self):
for args, expected in [
(
('a,b,c,d', lambda c: c == ',', -1),
[['a', ','], ['b', ','], ['c', ','], ['d']],
),
(
('a,b,c,d', lambda c: c == ',', 0),
[['a', ',', 'b', ',', 'c', ',', 'd']],
),
(
('a,b,c,d', lambda c: c == ',', 1),
[['a', ','], ['b', ',', 'c', ',', 'd']],
),
(
('a,b,c,d', lambda c: c == ',', 2),
[['a', ','], ['b', ','], ['c', ',', 'd']],
),
(
('a,b,c,d', lambda c: c == ',', 10),
[['a', ','], ['b', ','], ['c', ','], ['d']],
),
(
('a,b,c,d', lambda c: c == '@', 2),
[['a', ',', 'b', ',', 'c', ',', 'd']],
),
(
('a,b,c,d', lambda c: c != ',', 2),
[['a'], [',', 'b'], [',', 'c', ',', 'd']],
),
(
([1], lambda x: x == 1, 1),
[[1]],
),
]:
> actual = list(mi.split_after(*args))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1453: TypeError
test_more.py::SplitAfterTest::test_no_sep
test_more.py::SplitAfterTest::test_no_sep
self =
def test_no_sep(self):
> actual = list(mi.split_after('ooo', lambda c: c == 'x'))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1414: TypeError
test_more.py::SplitAfterTest::test_starts_with_sep
test_more.py::SplitAfterTest::test_starts_with_sep
self =
def test_starts_with_sep(self):
> actual = list(mi.split_after('xooxoo', lambda c: c == 'x'))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1404: TypeError
test_more.py::SplitWhenTests::test_after_emulation_ends_with_sep
test_more.py::SplitWhenTests::test_after_emulation_ends_with_sep
self =
def test_after_emulation_ends_with_sep(self):
> actual = list(self._split_when_after('ooxoox', lambda c: c == 'x'))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1491: TypeError
test_more.py::SplitWhenTests::test_after_emulation_no_sep
test_more.py::SplitWhenTests::test_after_emulation_no_sep
self =
def test_after_emulation_no_sep(self):
> actual = list(self._split_when_after('ooo', lambda c: c == 'x'))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1496: TypeError
test_more.py::SplitWhenTests::test_after_emulation_starts_with_sep
test_more.py::SplitWhenTests::test_after_emulation_starts_with_sep
self =
def test_after_emulation_starts_with_sep(self):
> actual = list(self._split_when_after('xooxoo', lambda c: c == 'x'))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1486: TypeError
test_more.py::SplitWhenTests::test_before_emulation_ends_with_sep
test_more.py::SplitWhenTests::test_before_emulation_ends_with_sep
self =
def test_before_emulation_ends_with_sep(self):
> actual = list(self._split_when_before('ooxoox', lambda c: c == 'x'))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1475: TypeError
test_more.py::SplitWhenTests::test_before_emulation_no_sep
test_more.py::SplitWhenTests::test_before_emulation_no_sep
self =
def test_before_emulation_no_sep(self):
> actual = list(self._split_when_before('ooo', lambda c: c == 'x'))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1480: TypeError
test_more.py::SplitWhenTests::test_before_emulation_starts_with_sep
test_more.py::SplitWhenTests::test_before_emulation_starts_with_sep
self =
def test_before_emulation_starts_with_sep(self):
> actual = list(self._split_when_before('xooxoo', lambda c: c == 'x'))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1470: TypeError
test_more.py::SplitWhenTests::test_empty_iterable
test_more.py::SplitWhenTests::test_empty_iterable
self =
def test_empty_iterable(self):
> actual = list(mi.split_when('', lambda a, b: a != b))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1502: TypeError
test_more.py::SplitWhenTests::test_max_split
test_more.py::SplitWhenTests::test_max_split
self =
def test_max_split(self):
for args, expected in [
(
('a,b,c,d', lambda a, _: a == ',', -1),
[['a', ','], ['b', ','], ['c', ','], ['d']],
),
(
('a,b,c,d', lambda a, _: a == ',', 0),
[['a', ',', 'b', ',', 'c', ',', 'd']],
),
(
('a,b,c,d', lambda _, b: b == ',', 1),
[['a'], [',', 'b', ',', 'c', ',', 'd']],
),
(
('a,b,c,d', lambda a, _: a == ',', 2),
[['a', ','], ['b', ','], ['c', ',', 'd']],
),
(
('0124376', lambda a, b: a > b, -1),
[['0', '1', '2', '4'], ['3', '7'], ['6']],
),
(
('0124376', lambda a, b: a > b, 0),
[['0', '1', '2', '4', '3', '7', '6']],
),
(
('0124376', lambda a, b: a > b, 1),
[['0', '1', '2', '4'], ['3', '7', '6']],
),
(
('0124376', lambda a, b: a > b, 2),
[['0', '1', '2', '4'], ['3', '7'], ['6']],
),
]:
> actual = list(mi.split_when(*args))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1556: TypeError
test_more.py::SplitWhenTests::test_one_element
test_more.py::SplitWhenTests::test_one_element
self =
def test_one_element(self):
> actual = list(mi.split_when('o', lambda a, b: a == b))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1507: TypeError
test_more.py::SplitWhenTests::test_one_element_is_first_item
test_more.py::SplitWhenTests::test_one_element_is_first_item
self =
def test_one_element_is_first_item(self):
> actual = list(self._split_when_after('x', lambda c: c == 'x'))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1517: TypeError
test_more.py::SplitWhenTests::test_one_element_is_second_item
test_more.py::SplitWhenTests::test_one_element_is_second_item
self =
def test_one_element_is_second_item(self):
> actual = list(self._split_when_before('x', lambda c: c == 'x'))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1512: TypeError
test_more.py::SplitIntoTests::test_bool_in_sizes
test_more.py::SplitIntoTests::test_bool_in_sizes
self =
def test_bool_in_sizes(self):
"""A bool object is present in ``sizes`` is treated as a 1 or 0 for
``True`` or ``False`` due to bool being an instance of int."""
iterable = [1, 2, 3, 4, 5, 6, 7, 8, 9]
sizes = [3, True, 2, False]
expected = [[1, 2, 3], [4], [5, 6], []]
> actual = list(mi.split_into(iterable, sizes))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1670: TypeError
test_more.py::SplitIntoTests::test_both_empty
test_more.py::SplitIntoTests::test_both_empty
self =
def test_both_empty(self):
"""Both ``sizes`` and ``iterable`` arguments are empty. An empty
generator is returned."""
iterable = []
sizes = []
expected = []
> actual = list(mi.split_into(iterable, sizes))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1661: TypeError
test_more.py::SplitIntoTests::test_generator_iterable_integrity
test_more.py::SplitIntoTests::test_generator_iterable_integrity
self =
def test_generator_iterable_integrity(self):
"""Check that if ``iterable`` is an iterator, it is consumed only by as
many items as the sum of ``sizes``."""
iterable = (i for i in range(10))
sizes = [2, 3]
expected = [[0, 1], [2, 3, 4]]
> actual = list(mi.split_into(iterable, sizes))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1697: TypeError
test_more.py::SplitIntoTests::test_generator_sizes_integrity
test_more.py::SplitIntoTests::test_generator_sizes_integrity
self =
def test_generator_sizes_integrity(self):
"""Check that if ``sizes`` is an iterator, it is consumed only until a
``None`` item is reached"""
iterable = [1, 2, 3, 4, 5, 6, 7, 8, 9]
sizes = (i for i in [1, 2, None, 3, 4])
expected = [[1], [2, 3], [4, 5, 6, 7, 8, 9]]
> actual = list(mi.split_into(iterable, sizes))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1711: TypeError
test_more.py::SplitIntoTests::test_invalid_in_sizes
test_more.py::SplitIntoTests::test_invalid_in_sizes
self =
def test_invalid_in_sizes(self):
"""A ValueError is raised if an object in ``sizes`` is neither ``None``
or an integer."""
iterable = [1, 2, 3, 4, 5, 6, 7, 8, 9]
sizes = [1, [], 3]
with self.assertRaises(ValueError):
> list(mi.split_into(iterable, sizes))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1679: TypeError
test_more.py::SplitIntoTests::test_invalid_in_sizes_after_none
test_more.py::SplitIntoTests::test_invalid_in_sizes_after_none
self =
def test_invalid_in_sizes_after_none(self):
"""A item in ``sizes`` that is invalid will not raise a TypeError if it
comes after a ``None`` item."""
iterable = [1, 2, 3, 4, 5, 6, 7, 8, 9]
sizes = [3, 4, None, []]
expected = [[1, 2, 3], [4, 5, 6, 7], [8, 9]]
> actual = list(mi.split_into(iterable, sizes))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1687: TypeError
test_more.py::SplitIntoTests::test_iterable_empty
test_more.py::SplitIntoTests::test_iterable_empty
self =
def test_iterable_empty(self):
"""``iterable`` argument is empty but ``sizes`` is not. An empty
list is returned for each item in ``sizes``."""
iterable = []
sizes = [2, 4, 2]
expected = [[], [], []]
> actual = list(mi.split_into(iterable, sizes))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1633: TypeError
test_more.py::SplitIntoTests::test_iterable_empty_using_none
test_more.py::SplitIntoTests::test_iterable_empty_using_none
self =
def test_iterable_empty_using_none(self):
"""``iterable`` argument is empty but ``sizes`` is not. An empty
list is returned for each item in ``sizes`` that is not after a
None item."""
iterable = []
sizes = [2, 4, None, 2]
expected = [[], [], []]
> actual = list(mi.split_into(iterable, sizes))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1643: TypeError
test_more.py::SplitIntoTests::test_iterable_just_right
test_more.py::SplitIntoTests::test_iterable_just_right
self =
def test_iterable_just_right(self):
"""Size of ``iterable`` equals the sum of ``sizes``."""
iterable = [1, 2, 3, 4, 5, 6, 7, 8, 9]
sizes = [2, 3, 4]
expected = [[1, 2], [3, 4, 5], [6, 7, 8, 9]]
> actual = list(mi.split_into(iterable, sizes))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1568: TypeError
test_more.py::SplitIntoTests::test_iterable_too_large
test_more.py::SplitIntoTests::test_iterable_too_large
self =
def test_iterable_too_large(self):
"""Size of ``iterable`` is larger than sum of ``sizes``. Not all
items of iterable are returned."""
iterable = [1, 2, 3, 4, 5, 6, 7, 8, 9]
sizes = [2, 3, 2]
expected = [[1, 2], [3, 4, 5], [6, 7]]
> actual = list(mi.split_into(iterable, sizes))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1595: TypeError
test_more.py::SplitIntoTests::test_iterable_too_small
test_more.py::SplitIntoTests::test_iterable_too_small
self =
def test_iterable_too_small(self):
"""Size of ``iterable`` is smaller than sum of ``sizes``. Last return
list is shorter as a result."""
iterable = [1, 2, 3, 4, 5, 6, 7]
sizes = [2, 3, 4]
expected = [[1, 2], [3, 4, 5], [6, 7]]
> actual = list(mi.split_into(iterable, sizes))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1577: TypeError
test_more.py::SplitIntoTests::test_iterable_too_small_extra
self =
def test_iterable_too_small_extra(self):
"""Size of ``iterable`` is smaller than sum of ``sizes``. Second last
return list is shorter and last return list is empty as a result."""
iterable = [1, 2, 3, 4, 5, 6, 7]
sizes = [2, 3, 4, 5]
expected = [[1, 2], [3, 4, 5], [6, 7], []]
> actual = list(mi.split_into(iterable, sizes))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1586: TypeError
test_more.py::SplitIntoTests::test_sizes_empty
test_more.py::SplitIntoTests::test_sizes_empty
self =
def test_sizes_empty(self):
"""``sizes`` argument is empty but ``iterable`` is not. An empty
generator is returned."""
iterable = [1, 2, 3, 4, 5, 6, 7, 8, 9]
sizes = []
expected = []
> actual = list(mi.split_into(iterable, sizes))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1652: TypeError
test_more.py::SplitIntoTests::test_using_none_mid_sizes
test_more.py::SplitIntoTests::test_using_none_mid_sizes
self =
def test_using_none_mid_sizes(self):
"""None is present in ``sizes`` but is not the last item. Last list
returned stretches to fit all remaining items of ``iterable`` but
all items in ``sizes`` after None are ignored."""
iterable = [1, 2, 3, 4, 5, 6, 7, 8, 9]
sizes = [2, 3, None, 4]
expected = [[1, 2], [3, 4, 5], [6, 7, 8, 9]]
> actual = list(mi.split_into(iterable, sizes))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1624: TypeError
test_more.py::SplitIntoTests::test_using_none_with_leftover
test_more.py::SplitIntoTests::test_using_none_with_leftover
self =
def test_using_none_with_leftover(self):
"""Last item of ``sizes`` is None when items still remain in
``iterable``. Last list returned stretches to fit all remaining items
of ``iterable``."""
iterable = [1, 2, 3, 4, 5, 6, 7, 8, 9]
sizes = [2, 3, None]
expected = [[1, 2], [3, 4, 5], [6, 7, 8, 9]]
> actual = list(mi.split_into(iterable, sizes))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1605: TypeError
test_more.py::SplitIntoTests::test_using_none_without_leftover
test_more.py::SplitIntoTests::test_using_none_without_leftover
self =
def test_using_none_without_leftover(self):
"""Last item of ``sizes`` is None when no items remain in
``iterable``. Last list returned is empty."""
iterable = [1, 2, 3, 4, 5, 6, 7, 8, 9]
sizes = [2, 3, 4, None]
expected = [[1, 2], [3, 4, 5], [6, 7, 8, 9], []]
> actual = list(mi.split_into(iterable, sizes))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1614: TypeError
test_more.py::PaddedTest::test_invalid_n
test_more.py::PaddedTest::test_invalid_n
self =
def test_invalid_n(self):
> self.assertRaises(ValueError, lambda: list(mi.padded([1, 2, 3], n=-1)))
tests/test_more.py:1734:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> self.assertRaises(ValueError, lambda: list(mi.padded([1, 2, 3], n=-1)))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1734: TypeError
test_more.py::PaddedTest::test_next_multiple
test_more.py::PaddedTest::test_next_multiple
self =
def test_next_multiple(self):
seq = [1, 2, 3, 4, 5, 6]
# No need for padding: len(seq) % n == 0
self.assertEqual(
> list(mi.padded(seq, n=3, next_multiple=True)), [1, 2, 3, 4, 5, 6]
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1759: TypeError
test_more.py::PaddedTest::test_no_n
test_more.py::PaddedTest::test_no_n
self =
def test_no_n(self):
seq = [1, 2, 3]
# No fillvalue
> self.assertEqual(mi.take(5, mi.padded(seq)), [1, 2, 3, None, None])
tests/test_more.py:1726:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
n = 5, iterable = None
def take(n, iterable):
"""Return first *n* items of the iterable as a list.
>>> take(3, range(10))
[0, 1, 2]
If there are fewer than *n* items in the iterable, all of them are
returned.
>>> take(10, range(3))
[0, 1, 2]
"""
> return list(islice(iterable, n))
E TypeError: 'NoneType' object is not iterable
more_itertools/recipes.py:71: TypeError
test_more.py::PaddedTest::test_valid_n
test_more.py::PaddedTest::test_valid_n
self =
def test_valid_n(self):
seq = [1, 2, 3, 4, 5]
# No need for padding: len(seq) <= n
> self.assertEqual(list(mi.padded(seq, n=4)), [1, 2, 3, 4, 5])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1741: TypeError
test_more.py::RepeatEachTests::test_basic
test_more.py::RepeatEachTests::test_basic
self =
def test_basic(self):
> actual = list(mi.repeat_each('ABC', 3))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1795: TypeError
test_more.py::RepeatEachTests::test_default
test_more.py::RepeatEachTests::test_default
self =
def test_default(self):
> actual = list(mi.repeat_each('ABC'))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1790: TypeError
test_more.py::RepeatEachTests::test_empty
test_more.py::RepeatEachTests::test_empty
self =
def test_empty(self):
> actual = list(mi.repeat_each(''))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1800: TypeError
test_more.py::RepeatEachTests::test_infinite_input
self =
def test_infinite_input(self):
repeater = mi.repeat_each(cycle('AB'))
> actual = mi.take(6, repeater)
tests/test_more.py:1816:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
n = 6, iterable = None
def take(n, iterable):
"""Return first *n* items of the iterable as a list.
>>> take(3, range(10))
[0, 1, 2]
If there are fewer than *n* items in the iterable, all of them are
returned.
>>> take(10, range(3))
[0, 1, 2]
"""
> return list(islice(iterable, n))
E TypeError: 'NoneType' object is not iterable
more_itertools/recipes.py:71: TypeError
test_more.py::RepeatEachTests::test_negative_repeat
test_more.py::RepeatEachTests::test_negative_repeat
self =
def test_negative_repeat(self):
> actual = list(mi.repeat_each('ABC', -1))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1810: TypeError
test_more.py::RepeatEachTests::test_no_repeat
test_more.py::RepeatEachTests::test_no_repeat
self =
def test_no_repeat(self):
> actual = list(mi.repeat_each('ABC', 0))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1805: TypeError
test_more.py::RepeatLastTests::test_basic
test_more.py::RepeatLastTests::test_basic
self =
def test_basic(self):
slice_length = 10
iterable = (str(x) for x in range(5))
> actual = mi.take(slice_length, mi.repeat_last(iterable))
tests/test_more.py:1840:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
n = 10, iterable = None
def take(n, iterable):
"""Return first *n* items of the iterable as a list.
>>> take(3, range(10))
[0, 1, 2]
If there are fewer than *n* items in the iterable, all of them are
returned.
>>> take(10, range(3))
[0, 1, 2]
"""
> return list(islice(iterable, n))
E TypeError: 'NoneType' object is not iterable
more_itertools/recipes.py:71: TypeError
test_more.py::RepeatLastTests::test_default_value
test_more.py::RepeatLastTests::test_default_value
self =
def test_default_value(self):
slice_length = 3
iterable = iter([])
default = '3'
> actual = mi.take(slice_length, mi.repeat_last(iterable, default))
tests/test_more.py:1833:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
n = 3, iterable = None
def take(n, iterable):
"""Return first *n* items of the iterable as a list.
>>> take(3, range(10))
[0, 1, 2]
If there are fewer than *n* items in the iterable, all of them are
returned.
>>> take(10, range(3))
[0, 1, 2]
"""
> return list(islice(iterable, n))
E TypeError: 'NoneType' object is not iterable
more_itertools/recipes.py:71: TypeError
test_more.py::RepeatLastTests::test_empty_iterable
test_more.py::RepeatLastTests::test_empty_iterable
self =
def test_empty_iterable(self):
slice_length = 3
iterable = iter([])
> actual = mi.take(slice_length, mi.repeat_last(iterable))
tests/test_more.py:1825:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
n = 3, iterable = None
def take(n, iterable):
"""Return first *n* items of the iterable as a list.
>>> take(3, range(10))
[0, 1, 2]
If there are fewer than *n* items in the iterable, all of them are
returned.
>>> take(10, range(3))
[0, 1, 2]
"""
> return list(islice(iterable, n))
E TypeError: 'NoneType' object is not iterable
more_itertools/recipes.py:71: TypeError
test_more.py::DistributeTest::test_basic
test_more.py::DistributeTest::test_basic
self =
def test_basic(self):
iterable = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for n, expected in [
(1, [iterable]),
(2, [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10]]),
(3, [[1, 4, 7, 10], [2, 5, 8], [3, 6, 9]]),
(10, [[n] for n in range(1, 10 + 1)]),
]:
self.assertEqual(
> [list(x) for x in mi.distribute(n, iterable)], expected
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1862: TypeError
test_more.py::DistributeTest::test_invalid_n
test_more.py::DistributeTest::test_invalid_n
self =
def test_invalid_n(self):
> self.assertRaises(ValueError, lambda: mi.distribute(-1, [1, 2, 3]))
E AssertionError: ValueError not raised by
tests/test_more.py:1849: AssertionError
test_more.py::DistributeTest::test_large_n
test_more.py::DistributeTest::test_large_n
self =
def test_large_n(self):
iterable = [1, 2, 3, 4]
self.assertEqual(
> [list(x) for x in mi.distribute(6, iterable)],
[[1], [2], [3], [4], [], []],
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1868: TypeError
test_more.py::StaggerTest::test_default
test_more.py::StaggerTest::test_default
self =
def test_default(self):
iterable = [0, 1, 2, 3]
> actual = list(mi.stagger(iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1878: TypeError
test_more.py::StaggerTest::test_longest
test_more.py::StaggerTest::test_longest
self =
def test_longest(self):
iterable = [0, 1, 2, 3]
for offsets, expected in [
(
(-1, 0, 1),
[('', 0, 1), (0, 1, 2), (1, 2, 3), (2, 3, ''), (3, '', '')],
),
((-2, -1), [('', ''), ('', 0), (0, 1), (1, 2), (2, 3), (3, '')]),
((1, 2), [(1, 2), (2, 3), (3, '')]),
]:
all_groups = mi.stagger(
iterable, offsets=offsets, fillvalue='', longest=True
)
> self.assertEqual(list(all_groups), expected)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1905: TypeError
test_more.py::StaggerTest::test_offsets
test_more.py::StaggerTest::test_offsets
self =
def test_offsets(self):
iterable = [0, 1, 2, 3]
for offsets, expected in [
((-2, 0, 2), [('', 0, 2), ('', 1, 3)]),
((-2, -1), [('', ''), ('', 0), (0, 1), (1, 2), (2, 3)]),
((1, 2), [(1, 2), (2, 3)]),
]:
all_groups = mi.stagger(iterable, offsets=offsets, fillvalue='')
> self.assertEqual(list(all_groups), expected)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1890: TypeError
test_more.py::ZipEqualTest::test_deprecation
test_more.py::ZipEqualTest::test_deprecation
self =
@skipIf(version_info[:2] < (3, 10), 'zip_equal deprecated for 3.10+')
def test_deprecation(self):
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter('always')
self.assertEqual(
> list(mi.zip_equal([1, 2], [3, 4])), [(1, 3), (2, 4)]
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1914: TypeError
test_more.py::ZipEqualTest::test_equal
test_more.py::ZipEqualTest::test_equal
self =
def test_equal(self):
lists = [0, 1, 2], [2, 3, 4]
for iterables in [lists, map(iter, lists)]:
> actual = list(mi.zip_equal(*iterables))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1924: TypeError
test_more.py::ZipEqualTest::test_unequal_lists
test_more.py::ZipEqualTest::test_unequal_lists
self =
def test_unequal_lists(self):
two_items = [0, 1]
three_items = [2, 3, 4]
four_items = [5, 6, 7, 8]
# the mismatch is at index 1
try:
> list(mi.zip_equal(two_items, three_items, four_items))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1935: TypeError
test_more.py::ZipOffsetTest::test_longest
test_more.py::ZipOffsetTest::test_longest
self =
def test_longest(self):
a_1 = [0, 1, 2, 3]
a_2 = [0, 1, 2, 3, 4, 5]
a_3 = [0, 1, 2, 3, 4, 5, 6, 7]
> actual = list(
mi.zip_offset(a_1, a_2, a_3, offsets=(-1, 0, 1), longest=True)
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1981: TypeError
test_more.py::ZipOffsetTest::test_mismatch
test_more.py::ZipOffsetTest::test_mismatch
self =
def test_mismatch(self):
iterables = [0, 1, 2], [2, 3, 4]
offsets = (-1, 0, 1)
> self.assertRaises(
ValueError,
lambda: list(mi.zip_offset(*iterables, offsets=offsets)),
)
tests/test_more.py:1998:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> lambda: list(mi.zip_offset(*iterables, offsets=offsets)),
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2000: TypeError
test_more.py::ZipOffsetTest::test_shortest
test_more.py::ZipOffsetTest::test_shortest
self =
def test_shortest(self):
a_1 = [0, 1, 2, 3]
a_2 = [0, 1, 2, 3, 4, 5]
a_3 = [0, 1, 2, 3, 4, 5, 6, 7]
> actual = list(
mi.zip_offset(a_1, a_2, a_3, offsets=(-1, 0, 1), fillvalue='')
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:1971: TypeError
test_more.py::UnzipTests::test_empty_iterable
test_more.py::UnzipTests::test_empty_iterable
self =
def test_empty_iterable(self):
> self.assertEqual(list(mi.unzip([])), [])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2008: TypeError
test_more.py::UnzipTests::test_improperly_zipped
test_more.py::UnzipTests::test_improperly_zipped
self =
def test_improperly_zipped(self):
zipped = iter([(1, 2, 3), (4, 5), (6,)])
> xs, ys, zs = mi.unzip(zipped)
E TypeError: cannot unpack non-iterable NoneType object
tests/test_more.py:2029: TypeError
test_more.py::UnzipTests::test_increasingly_zipped
test_more.py::UnzipTests::test_increasingly_zipped
self =
def test_increasingly_zipped(self):
zipped = iter([(1, 2), (3, 4, 5), (6, 7, 8, 9)])
unzipped = mi.unzip(zipped)
# from the docstring:
# len(first tuple) is the number of iterables zipped
> self.assertEqual(len(unzipped), 2)
E TypeError: object of type 'NoneType' has no len()
tests/test_more.py:2039: TypeError
test_more.py::UnzipTests::test_length_one_iterable
test_more.py::UnzipTests::test_length_one_iterable
self =
def test_length_one_iterable(self):
> xs, ys, zs = mi.unzip(zip([1], [2], [3]))
E TypeError: cannot unpack non-iterable NoneType object
tests/test_more.py:2014: TypeError
test_more.py::UnzipTests::test_normal_case
test_more.py::UnzipTests::test_normal_case
self =
def test_normal_case(self):
xs, ys, zs = range(10), range(1, 11), range(2, 12)
zipped = zip(xs, ys, zs)
> xs, ys, zs = mi.unzip(zipped)
E TypeError: cannot unpack non-iterable NoneType object
tests/test_more.py:2022: TypeError
test_more.py::SortTogetherTest::test_invalid_key_list
test_more.py::SortTogetherTest::test_invalid_key_list
self =
def test_invalid_key_list(self):
"""tests `key_list` for indexes not available in `iterables`"""
iterables = [
['GA', 'GA', 'GA', 'CT', 'CT', 'CT'],
['May', 'Aug.', 'May', 'June', 'July', 'July'],
[97, 20, 100, 70, 100, 20],
]
> self.assertRaises(
IndexError, lambda: mi.sort_together(iterables, key_list=(5,))
)
E AssertionError: IndexError not raised by
tests/test_more.py:2100: AssertionError
test_more.py::SortTogetherTest::test_key_function
test_more.py::SortTogetherTest::test_key_function
self =
def test_key_function(self):
"""tests `key` function, including interaction with `key_list`"""
iterables = [
['GA', 'GA', 'GA', 'CT', 'CT', 'CT'],
['May', 'Aug.', 'May', 'June', 'July', 'July'],
[97, 20, 100, 70, 100, 20],
]
> self.assertEqual(
mi.sort_together(iterables, key=lambda x: x),
[
('CT', 'CT', 'CT', 'GA', 'GA', 'GA'),
('June', 'July', 'July', 'May', 'Aug.', 'May'),
(70, 100, 20, 97, 20, 100),
],
)
E AssertionError: None != [('CT', 'CT', 'CT', 'GA', 'GA', 'GA'), ('[68 chars]100)]
tests/test_more.py:2111: AssertionError
test_more.py::SortTogetherTest::test_key_list
test_more.py::SortTogetherTest::test_key_list
self =
def test_key_list(self):
"""tests `key_list` including default, iterables include duplicates"""
iterables = [
['GA', 'GA', 'GA', 'CT', 'CT', 'CT'],
['May', 'Aug.', 'May', 'June', 'July', 'July'],
[97, 20, 100, 70, 100, 20],
]
> self.assertEqual(
mi.sort_together(iterables),
[
('CT', 'CT', 'CT', 'GA', 'GA', 'GA'),
('June', 'July', 'July', 'May', 'Aug.', 'May'),
(70, 100, 20, 97, 20, 100),
],
)
E AssertionError: None != [('CT', 'CT', 'CT', 'GA', 'GA', 'GA'), ('[68 chars]100)]
tests/test_more.py:2056: AssertionError
test_more.py::SortTogetherTest::test_reverse
test_more.py::SortTogetherTest::test_reverse
self =
def test_reverse(self):
"""tests `reverse` to ensure a reverse sort for `key_list` iterables"""
iterables = [
['GA', 'GA', 'GA', 'CT', 'CT', 'CT'],
['May', 'Aug.', 'May', 'June', 'July', 'July'],
[97, 20, 100, 70, 100, 20],
]
> self.assertEqual(
mi.sort_together(iterables, key_list=(0, 1, 2), reverse=True),
[
('GA', 'GA', 'GA', 'CT', 'CT', 'CT'),
('May', 'May', 'Aug.', 'June', 'July', 'July'),
(100, 97, 20, 70, 100, 20),
],
)
E AssertionError: None != [('GA', 'GA', 'GA', 'CT', 'CT', 'CT'), ('[68 chars] 20)]
tests/test_more.py:2150: AssertionError
test_more.py::SortTogetherTest::test_strict
test_more.py::SortTogetherTest::test_strict
self =
def test_strict(self):
# Test for list of lists or tuples
> self.assertRaises(
mi.UnequalIterablesError,
lambda: mi.sort_together(
[(4, 3, 2, 1), ('a', 'b', 'c')], strict=True
),
)
E AssertionError: UnequalIterablesError not raised by
tests/test_more.py:2178: AssertionError
test_more.py::SortTogetherTest::test_uneven_iterables
test_more.py::SortTogetherTest::test_uneven_iterables
self =
def test_uneven_iterables(self):
"""tests trimming of iterables to the shortest length before sorting"""
iterables = [
['GA', 'GA', 'GA', 'CT', 'CT', 'CT', 'MA'],
['May', 'Aug.', 'May', 'June', 'July', 'July'],
[97, 20, 100, 70, 100, 20, 0],
]
> self.assertEqual(
mi.sort_together(iterables),
[
('CT', 'CT', 'CT', 'GA', 'GA', 'GA'),
('June', 'July', 'July', 'May', 'Aug.', 'May'),
(70, 100, 20, 97, 20, 100),
],
)
E AssertionError: None != [('CT', 'CT', 'CT', 'GA', 'GA', 'GA'), ('[68 chars]100)]
tests/test_more.py:2167: AssertionError
test_more.py::DivideTest::test_basic
test_more.py::DivideTest::test_basic
self =
def test_basic(self):
iterable = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for n, expected in [
(1, [iterable]),
(2, [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]),
(3, [[1, 2, 3, 4], [5, 6, 7], [8, 9, 10]]),
(10, [[n] for n in range(1, 10 + 1)]),
]:
self.assertEqual(
> [list(x) for x in mi.divide(n, iterable)], expected
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2217: TypeError
test_more.py::DivideTest::test_invalid_n
test_more.py::DivideTest::test_invalid_n
self =
def test_invalid_n(self):
> self.assertRaises(ValueError, lambda: mi.divide(-1, [1, 2, 3]))
E AssertionError: ValueError not raised by
tests/test_more.py:2204: AssertionError
test_more.py::DivideTest::test_large_n
test_more.py::DivideTest::test_large_n
self =
def test_large_n(self):
self.assertEqual(
> [list(x) for x in mi.divide(6, iter(range(1, 4 + 1)))],
[[1], [2], [3], [4], [], []],
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2222: TypeError
test_more.py::TestAlwaysIterable::test_base_type
test_more.py::TestAlwaysIterable::test_base_type
self =
def test_base_type(self):
dict_obj = {'a': 1, 'b': 2}
str_obj = '123'
# Default: dicts are iterable like they normally are
> default_actual = list(mi.always_iterable(dict_obj))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2244: TypeError
test_more.py::TestAlwaysIterable::test_generator
test_more.py::TestAlwaysIterable::test_generator
self =
def test_generator(self):
def _gen():
yield 0
yield 1
> self.assertEqual(list(mi.always_iterable(_gen())), [0, 1])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2282: TypeError
test_more.py::TestAlwaysIterable::test_iterables
test_more.py::TestAlwaysIterable::test_iterables
self =
def test_iterables(self):
> self.assertEqual(list(mi.always_iterable([0, 1])), [0, 1])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2265: TypeError
test_more.py::TestAlwaysIterable::test_none
test_more.py::TestAlwaysIterable::test_none
self =
def test_none(self):
> self.assertEqual(list(mi.always_iterable(None)), [])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2275: TypeError
test_more.py::TestAlwaysIterable::test_single
test_more.py::TestAlwaysIterable::test_single
self =
def test_single(self):
> self.assertEqual(list(mi.always_iterable(1)), [1])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2231: TypeError
test_more.py::TestAlwaysIterable::test_strings
test_more.py::TestAlwaysIterable::test_strings
self =
def test_strings(self):
for obj in ['foo', b'bar', 'baz']:
> actual = list(mi.always_iterable(obj))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2235: TypeError
test_more.py::AdjacentTests::test_call_once
test_more.py::AdjacentTests::test_call_once
self =
def test_call_once(self):
"""Test that the predicate is only called once per item."""
already_seen = set()
iterable = range(10)
def predicate(item):
self.assertNotIn(item, already_seen)
already_seen.add(item)
return True
> actual = list(mi.adjacent(predicate, iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2417: TypeError
test_more.py::AdjacentTests::test_consecutive_true
test_more.py::AdjacentTests::test_consecutive_true
self =
def test_consecutive_true(self):
"""Test that when the predicate matches multiple consecutive elements
it doesn't repeat elements in the output"""
> actual = list(mi.adjacent(lambda x: x % 5 < 2, range(10)))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2319: TypeError
test_more.py::AdjacentTests::test_distance
test_more.py::AdjacentTests::test_distance
self =
def test_distance(self):
> actual = list(mi.adjacent(lambda x: x % 5 == 0, range(10), distance=2))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2335: TypeError
test_more.py::AdjacentTests::test_empty_iterable
test_more.py::AdjacentTests::test_empty_iterable
self =
def test_empty_iterable(self):
> actual = list(mi.adjacent(lambda x: x % 5 == 0, []))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2303: TypeError
test_more.py::AdjacentTests::test_grouping
test_more.py::AdjacentTests::test_grouping
self =
def test_grouping(self):
"""Test interaction of adjacent() with groupby_transform()"""
iterable = mi.adjacent(lambda x: x % 5 == 0, range(10))
grouper = mi.groupby_transform(iterable, itemgetter(0), itemgetter(1))
> actual = [(k, list(g)) for k, g in grouper]
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2398: TypeError
test_more.py::AdjacentTests::test_large_distance
test_more.py::AdjacentTests::test_large_distance
self =
def test_large_distance(self):
"""Test distance larger than the length of the iterable"""
iterable = range(10)
> actual = list(mi.adjacent(lambda x: x % 5 == 4, iterable, distance=20))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2368: TypeError
test_more.py::AdjacentTests::test_length_one
test_more.py::AdjacentTests::test_length_one
self =
def test_length_one(self):
> actual = list(mi.adjacent(lambda x: x % 5 == 0, [0]))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2308: TypeError
test_more.py::AdjacentTests::test_negative_distance
test_more.py::AdjacentTests::test_negative_distance
self =
def test_negative_distance(self):
"""Test that adjacent() raises an error with negative distance"""
pred = lambda x: x
> self.assertRaises(
ValueError, lambda: mi.adjacent(pred, range(1000), -1)
)
E AssertionError: ValueError not raised by
tests/test_more.py:2387: AssertionError
test_more.py::AdjacentTests::test_typical
test_more.py::AdjacentTests::test_typical
self =
def test_typical(self):
> actual = list(mi.adjacent(lambda x: x % 5 == 0, range(10)))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2287: TypeError
test_more.py::AdjacentTests::test_zero_distance
test_more.py::AdjacentTests::test_zero_distance
self =
def test_zero_distance(self):
"""Test that adjacent() reduces to zip+map when distance is 0"""
iterable = range(1000)
predicate = lambda x: x % 4 == 2
actual = mi.adjacent(predicate, iterable, 0)
expected = zip(map(predicate, iterable), iterable)
> self.assertTrue(all(a == e for a, e in zip(actual, expected)))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2382: TypeError
test_more.py::GroupByTransformTests::test_default_funcs
self =
def test_default_funcs(self):
iterable = [(x // 5, x) for x in range(1000)]
actual = mi.groupby_transform(iterable)
expected = groupby(iterable)
> self.assertAllGroupsEqual(actual, expected)
tests/test_more.py:2436:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self =
groupby1 = None, groupby2 =
def assertAllGroupsEqual(self, groupby1, groupby2):
> for a, b in zip(groupby1, groupby2):
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2424: TypeError
test_more.py::GroupByTransformTests::test_no_valuefunc
self =
def test_no_valuefunc(self):
iterable = range(1000)
def key(x):
return x // 5
actual = mi.groupby_transform(iterable, key, valuefunc=None)
expected = groupby(iterable, key)
> self.assertAllGroupsEqual(actual, expected)
tests/test_more.py:2473:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self =
groupby1 = None, groupby2 =
def assertAllGroupsEqual(self, groupby1, groupby2):
> for a, b in zip(groupby1, groupby2):
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2424: TypeError
test_more.py::GroupByTransformTests::test_reducefunc
self =
def test_reducefunc(self):
iterable = range(50)
keyfunc = lambda k: 10 * (k // 10)
valuefunc = lambda v: v + 1
reducefunc = sum
> actual = list(
mi.groupby_transform(
iterable,
keyfunc=keyfunc,
valuefunc=valuefunc,
reducefunc=reducefunc,
)
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2484: TypeError
test_more.py::GroupByTransformTests::test_valuefunc
self =
def test_valuefunc(self):
iterable = [(int(x / 5), int(x / 3), x) for x in range(10)]
# Test the standard usage of grouping one iterable using another's keys
grouper = mi.groupby_transform(
iterable, keyfunc=itemgetter(0), valuefunc=itemgetter(-1)
)
> actual = [(k, list(g)) for k, g in grouper]
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:2445: TypeError
test_more.py::NumericRangeTests::test_basic
test_more.py::NumericRangeTests::test_basic
self =
def test_basic(self):
for args, expected in [
((4,), [0, 1, 2, 3]),
((4.0,), [0.0, 1.0, 2.0, 3.0]),
((1.0, 4), [1.0, 2.0, 3.0]),
((1, 4.0), [1.0, 2.0, 3.0]),
((1.0, 5), [1.0, 2.0, 3.0, 4.0]),
((0, 20, 5), [0, 5, 10, 15]),
((0, 20, 5.0), [0.0, 5.0, 10.0, 15.0]),
((0, 10, 3), [0, 3, 6, 9]),
((0, 10, 3.0), [0.0, 3.0, 6.0, 9.0]),
((0, -5, -1), [0, -1, -2, -3, -4]),
((0.0, -5, -1), [0.0, -1.0, -2.0, -3.0, -4.0]),
((1, 2, Fraction(1, 2)), [Fraction(1, 1), Fraction(3, 2)]),
((0,), []),
((0.0,), []),
((1, 0), []),
((1.0, 0.0), []),
((0.1, 0.30000000000000001, 0.2), [0.1]), # IEE 754 !
(
(
Decimal("0.1"),
Decimal("0.30000000000000001"),
Decimal("0.2"),
),
[Decimal("0.1"), Decimal("0.3")],
), # okay with Decimal
(
(
Fraction(1, 10),
Fraction(30000000000000001, 100000000000000000),
Fraction(2, 10),
),
[Fraction(1, 10), Fraction(3, 10)],
), # okay with Fraction
((Fraction(2, 1),), [Fraction(0, 1), Fraction(1, 1)]),
((Decimal('2.0'),), [Decimal('0.0'), Decimal('1.0')]),
(
(
datetime(2019, 3, 29, 12, 34, 56),
datetime(2019, 3, 29, 12, 37, 55),
timedelta(minutes=1),
),
[
datetime(2019, 3, 29, 12, 34, 56),
datetime(2019, 3, 29, 12, 35, 56),
datetime(2019, 3, 29, 12, 36, 56),
],
),
]:
> actual = list(mi.numeric_range(*args))
tests/test_more.py:2547:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = numeric_range(0, 4)
def __len__(self):
> return self._len
E AttributeError: 'numeric_range' object has no attribute '_len'
more_itertools/more.py:1523: AttributeError
test_more.py::NumericRangeTests::test_eq
test_more.py::NumericRangeTests::test_eq
self =
def test_eq(self):
for args1, args2 in [
((0, 5, 2), (0, 6, 2)),
((1.0, 9.9, 1.5), (1.0, 8.6, 1.5)),
((8.5, 0.0, -1.5), (8.5, 0.7, -1.5)),
((7.0, 0.0, 1.0), (17.0, 7.0, 0.5)),
(
(Decimal("1.0"), Decimal("9.9"), Decimal("1.5")),
(Decimal("1.0"), Decimal("8.6"), Decimal("1.5")),
),
(
(Fraction(1, 1), Fraction(10, 1), Fraction(3, 2)),
(Fraction(1, 1), Fraction(9, 1), Fraction(3, 2)),
),
(
(
datetime(2019, 3, 29),
datetime(2019, 3, 30),
timedelta(hours=10),
),
(
datetime(2019, 3, 29),
datetime(2019, 3, 30, 1),
timedelta(hours=10),
),
),
]:
> self.assertEqual(
mi.numeric_range(*args1), mi.numeric_range(*args2)
)
tests/test_more.py:2680:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = numeric_range(0, 5, 2), other = numeric_range(0, 6, 2)
def __eq__(self, other):
if isinstance(other, numeric_range):
empty_self = not bool(self)
empty_other = not bool(other)
if empty_self or empty_other:
return empty_self and empty_other
else:
> return self._start == other._start and self._step == other._step and (self._get_by_index(-1) == other._get_by_index(-1))
E AttributeError: 'numeric_range' object has no attribute '_get_by_index'
more_itertools/more.py:1484: AttributeError
test_more.py::NumericRangeTests::test_get_item_by_index
test_more.py::NumericRangeTests::test_get_item_by_index
self =
def test_get_item_by_index(self):
for args, index, expected in [
((1, 6), 2, 3),
((1.0, 6.0, 1.5), 0, 1.0),
((1.0, 6.0, 1.5), 1, 2.5),
((1.0, 6.0, 1.5), 2, 4.0),
((1.0, 6.0, 1.5), 3, 5.5),
((1.0, 6.0, 1.5), -1, 5.5),
((1.0, 6.0, 1.5), -2, 4.0),
(
(Decimal("1.0"), Decimal("9.0"), Decimal("1.5")),
-1,
Decimal("8.5"),
),
(
(Fraction(1, 1), Fraction(10, 1), Fraction(3, 2)),
2,
Fraction(4, 1),
),
(
(
datetime(2019, 3, 29),
datetime(2019, 3, 30),
timedelta(hours=10),
),
1,
datetime(2019, 3, 29, 10),
),
]:
> self.assertEqual(expected, mi.numeric_range(*args)[index])
tests/test_more.py:2750:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = numeric_range(1, 6), key = 2
def __getitem__(self, key):
if isinstance(key, int):
> return self._get_by_index(key)
E AttributeError: 'numeric_range' object has no attribute '_get_by_index'
more_itertools/more.py:1490: AttributeError
test_more.py::NumericRangeTests::test_get_item_by_slice
test_more.py::NumericRangeTests::test_get_item_by_slice
self =
def test_get_item_by_slice(self):
for args, sl, expected_args in [
((1.0, 9.0, 1.5), slice(None, None, None), (1.0, 9.0, 1.5)),
((1.0, 9.0, 1.5), slice(None, 1, None), (1.0, 2.5, 1.5)),
((1.0, 9.0, 1.5), slice(None, None, 2), (1.0, 9.0, 3.0)),
((1.0, 9.0, 1.5), slice(None, 2, None), (1.0, 4.0, 1.5)),
((1.0, 9.0, 1.5), slice(1, 2, None), (2.5, 4.0, 1.5)),
((1.0, 9.0, 1.5), slice(1, -1, None), (2.5, 8.5, 1.5)),
((1.0, 9.0, 1.5), slice(10, None, 3), (9.0, 9.0, 4.5)),
((1.0, 9.0, 1.5), slice(-10, None, 3), (1.0, 9.0, 4.5)),
((1.0, 9.0, 1.5), slice(None, -10, 3), (1.0, 1.0, 4.5)),
((1.0, 9.0, 1.5), slice(None, 10, 3), (1.0, 9.0, 4.5)),
(
(Decimal("1.0"), Decimal("9.0"), Decimal("1.5")),
slice(1, -1, None),
(Decimal("2.5"), Decimal("8.5"), Decimal("1.5")),
),
(
(Fraction(1, 1), Fraction(5, 1), Fraction(3, 2)),
slice(1, -1, None),
(Fraction(5, 2), Fraction(4, 1), Fraction(3, 2)),
),
(
(
datetime(2019, 3, 29),
datetime(2019, 3, 30),
timedelta(hours=10),
),
slice(1, -1, None),
(
datetime(2019, 3, 29, 10),
datetime(2019, 3, 29, 20),
timedelta(hours=10),
),
),
]:
> self.assertEqual(
mi.numeric_range(*expected_args), mi.numeric_range(*args)[sl]
)
tests/test_more.py:2807:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = numeric_range(1.0, 9.0, 1.5), other = numeric_range(1.0, 9.0, 1.5)
def __eq__(self, other):
if isinstance(other, numeric_range):
empty_self = not bool(self)
empty_other = not bool(other)
if empty_self or empty_other:
return empty_self and empty_other
else:
> return self._start == other._start and self._step == other._step and (self._get_by_index(-1) == other._get_by_index(-1))
E AttributeError: 'numeric_range' object has no attribute '_get_by_index'
more_itertools/more.py:1484: AttributeError
test_more.py::NumericRangeTests::test_hash
test_more.py::NumericRangeTests::test_hash
self =
def test_hash(self):
for args, expected in [
((1.0, 6.0, 1.5), hash((1.0, 5.5, 1.5))),
((1.0, 7.0, 1.5), hash((1.0, 5.5, 1.5))),
((1.0, 7.5, 1.5), hash((1.0, 7.0, 1.5))),
((1.0, 1.5, 1.5), hash((1.0, 1.0, 1.5))),
((1.5, 1.0, 1.5), hash(range(0, 0))),
((1.5, 1.5, 1.5), hash(range(0, 0))),
(
(Decimal("1.0"), Decimal("9.0"), Decimal("1.5")),
hash((Decimal("1.0"), Decimal("8.5"), Decimal("1.5"))),
),
(
(Fraction(1, 1), Fraction(5, 1), Fraction(3, 2)),
hash((Fraction(1, 1), Fraction(4, 1), Fraction(3, 2))),
),
(
(
datetime(2019, 3, 29),
datetime(2019, 3, 30),
timedelta(hours=10),
),
hash(
(
datetime(2019, 3, 29),
datetime(2019, 3, 29, 20),
timedelta(hours=10),
)
),
),
]:
> self.assertEqual(expected, hash(mi.numeric_range(*args)))
tests/test_more.py:2842:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = numeric_range(1.0, 6.0, 1.5)
def __hash__(self):
if self:
> return hash((self._start, self._get_by_index(-1), self._step))
E AttributeError: 'numeric_range' object has no attribute '_get_by_index'
more_itertools/more.py:1511: AttributeError
test_more.py::NumericRangeTests::test_index
test_more.py::NumericRangeTests::test_index
self =
def test_index(self):
for args, v, i in [
((7.0,), 0.0, 0),
((7.0,), 6.0, 6),
((7.0, 0.0, -1.0), 7.0, 0),
((7.0, 0.0, -1.0), 1.0, 6),
(
(Decimal("1.0"), Decimal("5.0"), Decimal("1.5")),
Decimal('4.0'),
2,
),
(
(Fraction(1, 1), Fraction(5, 1), Fraction(3, 2)),
Fraction(5, 2),
1,
),
(
(
datetime(2019, 3, 29),
datetime(2019, 3, 30),
timedelta(hours=10),
),
datetime(2019, 3, 29, 20),
2,
),
]:
> self.assertEqual(i, mi.numeric_range(*args).index(v))
tests/test_more.py:3000:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
:1057: in index
???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = numeric_range(0.0, 7.0), key = 0
def __getitem__(self, key):
if isinstance(key, int):
> return self._get_by_index(key)
E AttributeError: 'numeric_range' object has no attribute '_get_by_index'
more_itertools/more.py:1490: AttributeError
test_more.py::NumericRangeTests::test_iter_twice
test_more.py::NumericRangeTests::test_iter_twice
self =
def test_iter_twice(self):
r1 = mi.numeric_range(1.0, 9.9, 1.5)
r2 = mi.numeric_range(8.5, 0.0, -1.5)
> self.assertEqual([1.0, 2.5, 4.0, 5.5, 7.0, 8.5], list(r1))
tests/test_more.py:2847:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = numeric_range(1.0, 9.9, 1.5)
def __len__(self):
> return self._len
E AttributeError: 'numeric_range' object has no attribute '_len'
more_itertools/more.py:1523: AttributeError
test_more.py::NumericRangeTests::test_len
test_more.py::NumericRangeTests::test_len
self =
def test_len(self):
for args, expected in [
((1.0, 7.0, 1.5), 4),
((1.0, 7.01, 1.5), 5),
((7.0, 1.0, -1.5), 4),
((7.01, 1.0, -1.5), 5),
((0.1, 0.30000000000000001, 0.2), 1), # IEE 754 !
(
(
Decimal("0.1"),
Decimal("0.30000000000000001"),
Decimal("0.2"),
),
2,
), # works with Decimal
((Decimal("1.0"), Decimal("9.0"), Decimal("1.5")), 6),
((Fraction(1, 1), Fraction(5, 1), Fraction(3, 2)), 3),
(
(
datetime(2019, 3, 29),
datetime(2019, 3, 30),
timedelta(hours=10),
),
3,
),
]:
> self.assertEqual(expected, len(mi.numeric_range(*args)))
tests/test_more.py:2878:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = numeric_range(1.0, 7.0, 1.5)
def __len__(self):
> return self._len
E AttributeError: 'numeric_range' object has no attribute '_len'
more_itertools/more.py:1523: AttributeError
test_more.py::NumericRangeTests::test_pickle
test_more.py::NumericRangeTests::test_pickle
self =
def test_pickle(self):
for args in [
(7.0,),
(5.0, 7.0),
(5.0, 7.0, 3.0),
(7.0, 5.0),
(7.0, 5.0, 4.0),
(7.0, 5.0, -1.0),
(Decimal("1.0"), Decimal("5.0"), Decimal("1.5")),
(Fraction(1, 1), Fraction(5, 1), Fraction(3, 2)),
(datetime(2019, 3, 29), datetime(2019, 3, 30)),
]:
r = mi.numeric_range(*args)
self.assertTrue(dumps(r)) # assert not empty
> self.assertEqual(r, loads(dumps(r)))
tests/test_more.py:3057:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = numeric_range(0.0, 7.0), other = numeric_range(0.0, 7.0)
def __eq__(self, other):
if isinstance(other, numeric_range):
empty_self = not bool(self)
empty_other = not bool(other)
if empty_self or empty_other:
return empty_self and empty_other
else:
> return self._start == other._start and self._step == other._step and (self._get_by_index(-1) == other._get_by_index(-1))
E AttributeError: 'numeric_range' object has no attribute '_get_by_index'
more_itertools/more.py:1484: AttributeError
test_more.py::NumericRangeTests::test_reversed
test_more.py::NumericRangeTests::test_reversed
self =
def test_reversed(self):
for args, expected in [
((7.0,), [6.0, 5.0, 4.0, 3.0, 2.0, 1.0, 0.0]),
((1.0, 7.0), [6.0, 5.0, 4.0, 3.0, 2.0, 1.0]),
((7.0, 1.0, -1.5), [2.5, 4.0, 5.5, 7.0]),
((7.0, 0.9, -1.5), [1.0, 2.5, 4.0, 5.5, 7.0]),
(
(Decimal("1.0"), Decimal("5.0"), Decimal("1.5")),
[Decimal('4.0'), Decimal('2.5'), Decimal('1.0')],
),
(
(Fraction(1, 1), Fraction(5, 1), Fraction(3, 2)),
[Fraction(4, 1), Fraction(5, 2), Fraction(1, 1)],
),
(
(
datetime(2019, 3, 29),
datetime(2019, 3, 30),
timedelta(hours=10),
),
[
datetime(2019, 3, 29, 20),
datetime(2019, 3, 29, 10),
datetime(2019, 3, 29),
],
),
]:
> self.assertEqual(expected, list(reversed(mi.numeric_range(*args))))
tests/test_more.py:2943:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = numeric_range(0.0, 7.0)
def __reversed__(self):
> return iter(numeric_range(self._get_by_index(-1), self._start - self._step, -self._step))
E AttributeError: 'numeric_range' object has no attribute '_get_by_index'
more_itertools/more.py:1535: AttributeError
test_more.py::CountCycleTests::test_basic
test_more.py::CountCycleTests::test_basic
self =
def test_basic(self):
expected = [
(0, 'a'),
(0, 'b'),
(0, 'c'),
(1, 'a'),
(1, 'b'),
(1, 'c'),
(2, 'a'),
(2, 'b'),
(2, 'c'),
]
for actual in [
> mi.take(9, mi.count_cycle('abc')), # n=None
list(mi.count_cycle('abc', 3)), # n=3
]:
tests/test_more.py:3074:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
n = 9, iterable = None
def take(n, iterable):
"""Return first *n* items of the iterable as a list.
>>> take(3, range(10))
[0, 1, 2]
If there are fewer than *n* items in the iterable, all of them are
returned.
>>> take(10, range(3))
[0, 1, 2]
"""
> return list(islice(iterable, n))
E TypeError: 'NoneType' object is not iterable
more_itertools/recipes.py:71: TypeError
test_more.py::CountCycleTests::test_empty
test_more.py::CountCycleTests::test_empty
self =
def test_empty(self):
> self.assertEqual(list(mi.count_cycle('')), [])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3080: TypeError
test_more.py::CountCycleTests::test_negative
test_more.py::CountCycleTests::test_negative
self =
def test_negative(self):
> self.assertEqual(list(mi.count_cycle('abc', -3)), [])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3084: TypeError
test_more.py::MarkEndsTests::test_basic
test_more.py::MarkEndsTests::test_basic
self =
def test_basic(self):
for size, expected in [
(0, []),
(1, [(True, True, '0')]),
(2, [(True, False, '0'), (False, True, '1')]),
(3, [(True, False, '0'), (False, False, '1'), (False, True, '2')]),
(
4,
[
(True, False, '0'),
(False, False, '1'),
(False, False, '2'),
(False, True, '3'),
],
),
]:
with self.subTest(size=size):
iterable = map(str, range(size))
> actual = list(mi.mark_ends(iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3106: TypeError
test_more.py::LocateTests::test_custom_pred
test_more.py::LocateTests::test_custom_pred
self =
def test_custom_pred(self):
iterable = ['0', 1, 1, '0', 1, '0', '0']
pred = lambda x: x == '0'
> actual = list(mi.locate(iterable, pred))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3126: TypeError
test_more.py::LocateTests::test_default_pred
test_more.py::LocateTests::test_default_pred
self =
def test_default_pred(self):
iterable = [0, 1, 1, 0, 1, 0, 0]
> actual = list(mi.locate(iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3113: TypeError
test_more.py::LocateTests::test_no_matches
test_more.py::LocateTests::test_no_matches
self =
def test_no_matches(self):
iterable = [0, 0, 0]
> actual = list(mi.locate(iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3119: TypeError
test_more.py::LocateTests::test_window_size
test_more.py::LocateTests::test_window_size
self =
def test_window_size(self):
iterable = ['0', 1, 1, '0', 1, '0', '0']
pred = lambda *args: args == ('0', 1)
> actual = list(mi.locate(iterable, pred, window_size=2))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3133: TypeError
test_more.py::LocateTests::test_window_size_large
test_more.py::LocateTests::test_window_size_large
self =
def test_window_size_large(self):
iterable = [1, 2, 3, 4]
pred = lambda a, b, c, d, e: True
> actual = list(mi.locate(iterable, pred, window_size=5))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3140: TypeError
test_more.py::LocateTests::test_window_size_zero
test_more.py::LocateTests::test_window_size_zero
self =
def test_window_size_zero(self):
iterable = [1, 2, 3, 4]
pred = lambda: True
with self.assertRaises(ValueError):
> list(mi.locate(iterable, pred, window_size=0))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3148: TypeError
test_more.py::StripFunctionTests::test_hashable
test_more.py::StripFunctionTests::test_hashable
self =
def test_hashable(self):
iterable = list('www.example.com')
pred = lambda x: x in set('cmowz.')
> self.assertEqual(list(mi.lstrip(iterable, pred)), list('example.com'))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3156: TypeError
test_more.py::StripFunctionTests::test_math
test_more.py::StripFunctionTests::test_math
self =
def test_math(self):
iterable = [0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2]
pred = lambda x: x <= 2
> self.assertEqual(list(mi.lstrip(iterable, pred)), iterable[3:])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3177: TypeError
test_more.py::StripFunctionTests::test_not_hashable
test_more.py::StripFunctionTests::test_not_hashable
self =
def test_not_hashable(self):
iterable = [
list('http://'),
list('www'),
list('.example'),
list('.com'),
]
pred = lambda x: x in [list('http://'), list('www'), list('.com')]
> self.assertEqual(list(mi.lstrip(iterable, pred)), iterable[2:])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3169: TypeError
test_more.py::IsliceExtendedTests::test_all
test_more.py::IsliceExtendedTests::test_all
self =
def test_all(self):
iterable = ['0', '1', '2', '3', '4', '5']
indexes = [*range(-4, 10), None]
steps = [1, 2, 3, 4, -1, -2, -3, -4]
for slice_args in product(indexes, indexes, steps):
with self.subTest(slice_args=slice_args):
> actual = list(mi.islice_extended(iterable, *slice_args))
tests/test_more.py:3189:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self =
iterable = ['0', '1', '2', '3', '4', '5'], args = (-4, -4, 1)
it =
def __init__(self, iterable, *args):
it = iter(iterable)
if args:
> self._iterable = _islice_helper(it, slice(*args))
E NameError: name '_islice_helper' is not defined
more_itertools/more.py:1697: NameError
test_more.py::IsliceExtendedTests::test_slicing
test_more.py::IsliceExtendedTests::test_slicing
self =
def test_slicing(self):
iterable = map(str, count())
> first_slice = mi.islice_extended(iterable)[10:]
tests/test_more.py:3199:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self =
key = slice(10, None, None)
def __getitem__(self, key):
if isinstance(key, slice):
> return islice_extended(_islice_helper(self._iterable, key))
E NameError: name '_islice_helper' is not defined
more_itertools/more.py:1709: NameError
test_more.py::IsliceExtendedTests::test_slicing_extensive
test_more.py::IsliceExtendedTests::test_slicing_extensive
self =
def test_slicing_extensive(self):
iterable = range(10)
options = (None, 1, 2, 7, -1)
for start, stop, step in product(options, options, options):
with self.subTest(slice_args=(start, stop, step)):
sliced_tuple_0 = tuple(
> mi.islice_extended(iterable)[start:stop:step]
)
tests/test_more.py:3210:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self =
key = slice(None, None, None)
def __getitem__(self, key):
if isinstance(key, slice):
> return islice_extended(_islice_helper(self._iterable, key))
E NameError: name '_islice_helper' is not defined
more_itertools/more.py:1709: NameError
test_more.py::IsliceExtendedTests::test_zero_step
test_more.py::IsliceExtendedTests::test_zero_step
self =
def test_zero_step(self):
with self.assertRaises(ValueError):
> list(mi.islice_extended([1, 2, 3], 0, 1, 0))
tests/test_more.py:3195:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
def __init__(self, iterable, *args):
it = iter(iterable)
if args:
> self._iterable = _islice_helper(it, slice(*args))
E NameError: name '_islice_helper' is not defined
more_itertools/more.py:1697: NameError
test_more.py::ConsecutiveGroupsTest::test_custom_ordering
test_more.py::ConsecutiveGroupsTest::test_custom_ordering
self =
def test_custom_ordering(self):
iterable = ['1', '10', '11', '20', '21', '22', '30', '31']
ordering = lambda x: int(x)
> actual = [list(g) for g in mi.consecutive_groups(iterable, ordering)]
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3234: TypeError
test_more.py::ConsecutiveGroupsTest::test_exotic_ordering
test_more.py::ConsecutiveGroupsTest::test_exotic_ordering
self =
def test_exotic_ordering(self):
iterable = [
('a', 'b', 'c', 'd'),
('a', 'c', 'b', 'd'),
('a', 'c', 'd', 'b'),
('a', 'd', 'b', 'c'),
('d', 'b', 'c', 'a'),
('d', 'c', 'a', 'b'),
]
ordering = list(permutations('abcd')).index
> actual = [list(g) for g in mi.consecutive_groups(iterable, ordering)]
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3248: TypeError
test_more.py::ConsecutiveGroupsTest::test_numbers
test_more.py::ConsecutiveGroupsTest::test_numbers
self =
def test_numbers(self):
iterable = [-10, -8, -7, -6, 1, 2, 4, 5, -1, 7]
> actual = [list(g) for g in mi.consecutive_groups(iterable)]
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3227: TypeError
test_more.py::DifferenceTest::test_custom
test_more.py::DifferenceTest::test_custom
self =
def test_custom(self):
iterable = [10, 20, 30, 40, 50]
> actual = list(mi.difference(iterable, add))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3266: TypeError
test_more.py::DifferenceTest::test_empty
test_more.py::DifferenceTest::test_empty
self =
def test_empty(self):
> self.assertEqual(list(mi.difference([])), [])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3280: TypeError
test_more.py::DifferenceTest::test_initial
test_more.py::DifferenceTest::test_initial
self =
def test_initial(self):
original = list(range(100))
accumulated = accumulate(original, initial=100)
> actual = list(mi.difference(accumulated, initial=100))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3285: TypeError
test_more.py::DifferenceTest::test_normal
test_more.py::DifferenceTest::test_normal
self =
def test_normal(self):
iterable = [10, 20, 30, 40, 50]
> actual = list(mi.difference(iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3260: TypeError
test_more.py::DifferenceTest::test_one
test_more.py::DifferenceTest::test_one
self =
def test_one(self):
> self.assertEqual(list(mi.difference([0])), [0])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3277: TypeError
test_more.py::DifferenceTest::test_roundtrip
test_more.py::DifferenceTest::test_roundtrip
self =
def test_roundtrip(self):
original = list(range(100))
accumulated = accumulate(original)
> actual = list(mi.difference(accumulated))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3273: TypeError
test_more.py::SeekableTest::test_elements
test_more.py::SeekableTest::test_elements
self =
def test_elements(self):
iterable = map(str, count())
s = mi.seekable(iterable)
mi.take(10, s)
> elements = s.elements()
E AttributeError: 'seekable' object has no attribute 'elements'
tests/test_more.py:3341: AttributeError
test_more.py::SeekableTest::test_exhaustion_reset
test_more.py::SeekableTest::test_exhaustion_reset
self =
def test_exhaustion_reset(self):
iterable = [str(n) for n in range(10)]
s = mi.seekable(iterable)
self.assertEqual(list(s), iterable) # Normal iteration
self.assertEqual(list(s), []) # Iterable is exhausted
> s.seek(0)
E AttributeError: 'seekable' object has no attribute 'seek'
tests/test_more.py:3299: AttributeError
test_more.py::SeekableTest::test_forward
test_more.py::SeekableTest::test_forward
self =
def test_forward(self):
iterable = [str(n) for n in range(10)]
s = mi.seekable(iterable)
self.assertEqual(mi.take(1, s), iterable[:1]) # Normal iteration
> s.seek(3) # Skip over index 2
E AttributeError: 'seekable' object has no attribute 'seek'
tests/test_more.py:3317: AttributeError
test_more.py::SeekableTest::test_maxlen
test_more.py::SeekableTest::test_maxlen
self =
def test_maxlen(self):
iterable = map(str, count())
s = mi.seekable(iterable, maxlen=4)
self.assertEqual(mi.take(10, s), [str(n) for n in range(10)])
> self.assertEqual(list(s.elements()), ['6', '7', '8', '9'])
E AttributeError: 'seekable' object has no attribute 'elements'
tests/test_more.py:3355: AttributeError
test_more.py::SeekableTest::test_maxlen_zero
test_more.py::SeekableTest::test_maxlen_zero
self =
def test_maxlen_zero(self):
iterable = [str(x) for x in range(5)]
s = mi.seekable(iterable, maxlen=0)
self.assertEqual(list(s), iterable)
> self.assertEqual(list(s.elements()), [])
E AttributeError: 'seekable' object has no attribute 'elements'
tests/test_more.py:3365: AttributeError
test_more.py::SeekableTest::test_partial_reset
test_more.py::SeekableTest::test_partial_reset
self =
def test_partial_reset(self):
iterable = [str(n) for n in range(10)]
s = mi.seekable(iterable)
self.assertEqual(mi.take(5, s), iterable[:5]) # Normal iteration
> s.seek(1)
E AttributeError: 'seekable' object has no attribute 'seek'
tests/test_more.py:3308: AttributeError
test_more.py::SeekableTest::test_past_end
test_more.py::SeekableTest::test_past_end
self =
def test_past_end(self):
iterable = [str(n) for n in range(10)]
s = mi.seekable(iterable)
self.assertEqual(mi.take(1, s), iterable[:1]) # Normal iteration
> s.seek(20)
E AttributeError: 'seekable' object has no attribute 'seek'
tests/test_more.py:3329: AttributeError
test_more.py::SeekableTest::test_peek_default
test_more.py::SeekableTest::test_peek_default
self =
def test_peek_default(self):
"""Make sure passing a default into ``peek()`` works."""
p = self.cls([])
> self.assertEqual(p.peek(7), 7)
E AttributeError: 'seekable' object has no attribute 'peek'
tests/test_more.py:211: AttributeError
test_more.py::SeekableTest::test_relative_seek
test_more.py::SeekableTest::test_relative_seek
self =
def test_relative_seek(self):
iterable = [str(x) for x in range(5)]
s = mi.seekable(iterable)
> s.relative_seek(2)
E AttributeError: 'seekable' object has no attribute 'relative_seek'
tests/test_more.py:3370: AttributeError
test_more.py::SeekableTest::test_simple_peeking
test_more.py::SeekableTest::test_simple_peeking
self =
def test_simple_peeking(self):
"""Make sure ``next`` and ``peek`` advance and don't advance the
iterator, respectively.
"""
p = self.cls(range(10))
self.assertEqual(next(p), 0)
> self.assertEqual(p.peek(), 1)
E AttributeError: 'seekable' object has no attribute 'peek'
tests/test_more.py:231: AttributeError
test_more.py::SeekableTest::test_truthiness
test_more.py::SeekableTest::test_truthiness
self =
def test_truthiness(self):
"""Make sure a ``peekable`` tests true iff there are items remaining in
the iterable.
"""
p = self.cls([])
> self.assertFalse(p)
tests/test_more.py:219:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self =
def __bool__(self):
try:
> self.peek()
E AttributeError: 'seekable' object has no attribute 'peek'
more_itertools/more.py:1973: AttributeError
test_more.py::RunLengthTest::test_decode
test_more.py::RunLengthTest::test_decode
self =
def test_decode(self):
iterable = [('d', 4), ('c', 3), ('b', 2), ('a', 1)]
> actual = ''.join(mi.run_length.decode(iterable))
E AttributeError: type object 'run_length' has no attribute 'decode'
tests/test_more.py:3448: AttributeError
test_more.py::RunLengthTest::test_encode
test_more.py::RunLengthTest::test_encode
self =
def test_encode(self):
iterable = (int(str(n)[0]) for n in count(800))
> actual = mi.take(4, mi.run_length.encode(iterable))
E AttributeError: type object 'run_length' has no attribute 'encode'
tests/test_more.py:3442: AttributeError
test_more.py::ExactlyNTests::test_empty
test_more.py::ExactlyNTests::test_empty
self =
def test_empty(self):
"""Return ``True`` if the iterable is empty and ``n`` is 0"""
> self.assertTrue(mi.exactly_n([], 0))
E AssertionError: None is not true
tests/test_more.py:3473: AssertionError
test_more.py::ExactlyNTests::test_true
test_more.py::ExactlyNTests::test_true
self =
def test_true(self):
"""Iterable has ``n`` ``True`` elements"""
> self.assertTrue(mi.exactly_n([True, False, True], 2))
E AssertionError: None is not true
tests/test_more.py:3458: AssertionError
test_more.py::AlwaysReversibleTests::test_nonseq_reversed
test_more.py::AlwaysReversibleTests::test_nonseq_reversed
self =
def test_nonseq_reversed(self):
# Create a non-reversible generator from a sequence
with self.assertRaises(TypeError):
reversed(x for x in range(10))
self.assertEqual(
list(reversed(range(10))),
> list(mi.always_reversible(x for x in range(10))),
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3499: TypeError
test_more.py::AlwaysReversibleTests::test_regular_reversed
test_more.py::AlwaysReversibleTests::test_regular_reversed
self =
def test_regular_reversed(self):
self.assertEqual(
> list(reversed(range(10))), list(mi.always_reversible(range(10)))
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3482: TypeError
test_more.py::CircularShiftsTests::test_duplicates
test_more.py::CircularShiftsTests::test_duplicates
self =
def test_duplicates(self):
# test non-distinct entries
self.assertEqual(
> list(mi.circular_shifts([0, 1, 0, 1])),
[(0, 1, 0, 1), (1, 0, 1, 0), (0, 1, 0, 1), (1, 0, 1, 0)],
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3526: TypeError
test_more.py::CircularShiftsTests::test_empty
test_more.py::CircularShiftsTests::test_empty
self =
def test_empty(self):
# empty iterable -> empty list
> self.assertEqual(list(mi.circular_shifts([])), [])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3514: TypeError
test_more.py::CircularShiftsTests::test_simple_circular_shifts
test_more.py::CircularShiftsTests::test_simple_circular_shifts
self =
def test_simple_circular_shifts(self):
# test the a simple iterator case
self.assertEqual(
> list(mi.circular_shifts(range(4))),
[(0, 1, 2, 3), (1, 2, 3, 0), (2, 3, 0, 1), (3, 0, 1, 2)],
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3519: TypeError
test_more.py::CircularShiftsTests::test_steps_negative
test_more.py::CircularShiftsTests::test_steps_negative
self =
def test_steps_negative(self):
> actual = list(mi.circular_shifts(range(5), steps=-2))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3542: TypeError
test_more.py::CircularShiftsTests::test_steps_positive
test_more.py::CircularShiftsTests::test_steps_positive
self =
def test_steps_positive(self):
> actual = list(mi.circular_shifts(range(5), steps=2))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3531: TypeError
test_more.py::CircularShiftsTests::test_steps_zero
test_more.py::CircularShiftsTests::test_steps_zero
self =
def test_steps_zero(self):
with self.assertRaises(ValueError):
> list(mi.circular_shifts(range(5), steps=0))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3554: TypeError
test_more.py::MakeDecoratorTests::test_basic
test_more.py::MakeDecoratorTests::test_basic
self =
def test_basic(self):
slicer = mi.make_decorator(islice)
> @slicer(1, 10, 2)
E TypeError: 'NoneType' object is not callable
tests/test_more.py:3561: TypeError
test_more.py::MakeDecoratorTests::test_result_index
test_more.py::MakeDecoratorTests::test_result_index
self =
def test_result_index(self):
def stringify(*args, **kwargs):
self.assertEqual(args[0], 'arg_0')
iterable = args[1]
self.assertEqual(args[2], 'arg_2')
self.assertEqual(kwargs['kwarg_1'], 'kwarg_1')
return map(str, iterable)
stringifier = mi.make_decorator(stringify, result_index=1)
> @stringifier('arg_0', 'arg_2', kwarg_1='kwarg_1')
E TypeError: 'NoneType' object is not callable
tests/test_more.py:3583: TypeError
test_more.py::MakeDecoratorTests::test_wrap_class
test_more.py::MakeDecoratorTests::test_wrap_class
self =
def test_wrap_class(self):
seeker = mi.make_decorator(mi.seekable)
> @seeker()
E TypeError: 'NoneType' object is not callable
tests/test_more.py:3595: TypeError
test_more.py::MapReduceTests::test_default
test_more.py::MapReduceTests::test_default
self =
def test_default(self):
iterable = (str(x) for x in range(5))
keyfunc = lambda x: int(x) // 2
> actual = sorted(mi.map_reduce(iterable, keyfunc).items())
E AttributeError: 'NoneType' object has no attribute 'items'
tests/test_more.py:3610: AttributeError
test_more.py::MapReduceTests::test_reducefunc
test_more.py::MapReduceTests::test_reducefunc
self =
def test_reducefunc(self):
iterable = (str(x) for x in range(5))
keyfunc = lambda x: int(x) // 2
valuefunc = int
reducefunc = lambda value_list: reduce(mul, value_list, 1)
actual = sorted(
> mi.map_reduce(iterable, keyfunc, valuefunc, reducefunc).items()
)
E AttributeError: 'NoneType' object has no attribute 'items'
tests/test_more.py:3628: AttributeError
test_more.py::MapReduceTests::test_ret
test_more.py::MapReduceTests::test_ret
self =
def test_ret(self):
d = mi.map_reduce([1, 0, 2, 0, 1, 0], bool)
> self.assertEqual(d, {False: [0, 0, 0], True: [1, 2, 1]})
E AssertionError: None != {False: [0, 0, 0], True: [1, 2, 1]}
tests/test_more.py:3635: AssertionError
test_more.py::MapReduceTests::test_valuefunc
test_more.py::MapReduceTests::test_valuefunc
self =
def test_valuefunc(self):
iterable = (str(x) for x in range(5))
keyfunc = lambda x: int(x) // 2
valuefunc = int
> actual = sorted(mi.map_reduce(iterable, keyfunc, valuefunc).items())
E AttributeError: 'NoneType' object has no attribute 'items'
tests/test_more.py:3618: AttributeError
test_more.py::RlocateTests::test_custom_pred
test_more.py::RlocateTests::test_custom_pred
self =
def test_custom_pred(self):
iterable = ['0', 1, 1, '0', 1, '0', '0']
pred = lambda x: x == '0'
for it in (iterable[:], iter(iterable)):
> actual = list(mi.rlocate(it, pred))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3658: TypeError
test_more.py::RlocateTests::test_default_pred
test_more.py::RlocateTests::test_default_pred
self =
def test_default_pred(self):
iterable = [0, 1, 1, 0, 1, 0, 0]
for it in (iterable[:], iter(iterable)):
> actual = list(mi.rlocate(it))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3643: TypeError
test_more.py::RlocateTests::test_efficient_reversal
test_more.py::RlocateTests::test_efficient_reversal
self =
def test_efficient_reversal(self):
iterable = range(9**9) # Is efficiently reversible
target = 9**9 - 2
pred = lambda x: x == target # Find-able from the right
> actual = next(mi.rlocate(iterable, pred))
E TypeError: 'NoneType' object is not an iterator
tests/test_more.py:3666: TypeError
test_more.py::RlocateTests::test_no_matches
test_more.py::RlocateTests::test_no_matches
self =
def test_no_matches(self):
iterable = [0, 0, 0]
for it in (iterable[:], iter(iterable)):
> actual = list(mi.rlocate(it))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3650: TypeError
test_more.py::RlocateTests::test_window_size
test_more.py::RlocateTests::test_window_size
self =
def test_window_size(self):
iterable = ['0', 1, 1, '0', 1, '0', '0']
pred = lambda *args: args == ('0', 1)
for it in (iterable, iter(iterable)):
> actual = list(mi.rlocate(it, pred, window_size=2))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3673: TypeError
test_more.py::RlocateTests::test_window_size_large
test_more.py::RlocateTests::test_window_size_large
self =
def test_window_size_large(self):
iterable = [1, 2, 3, 4]
pred = lambda a, b, c, d, e: True
for it in (iterable, iter(iterable)):
> actual = list(mi.rlocate(iterable, pred, window_size=5))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3681: TypeError
test_more.py::RlocateTests::test_window_size_zero
test_more.py::RlocateTests::test_window_size_zero
self =
def test_window_size_zero(self):
iterable = [1, 2, 3, 4]
pred = lambda: True
for it in (iterable, iter(iterable)):
with self.assertRaises(ValueError):
> list(mi.locate(iterable, pred, window_size=0))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3690: TypeError
test_more.py::ReplaceTests::test_basic
test_more.py::ReplaceTests::test_basic
self =
def test_basic(self):
iterable = range(10)
pred = lambda x: x % 2 == 0
substitutes = []
> actual = list(mi.replace(iterable, pred, substitutes))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3698: TypeError
test_more.py::ReplaceTests::test_count
test_more.py::ReplaceTests::test_count
self =
def test_count(self):
iterable = range(10)
pred = lambda x: x % 2 == 0
substitutes = []
> actual = list(mi.replace(iterable, pred, substitutes, count=4))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3706: TypeError
test_more.py::ReplaceTests::test_iterable_substitutes
test_more.py::ReplaceTests::test_iterable_substitutes
self =
def test_iterable_substitutes(self):
iterable = range(5)
pred = lambda x: x % 2 == 0
substitutes = iter('__')
> actual = list(mi.replace(iterable, pred, substitutes))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3755: TypeError
test_more.py::ReplaceTests::test_window_size
test_more.py::ReplaceTests::test_window_size
self =
def test_window_size(self):
iterable = range(10)
pred = lambda *args: args == (0, 1, 2)
substitutes = []
> actual = list(mi.replace(iterable, pred, substitutes, window_size=3))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3714: TypeError
test_more.py::ReplaceTests::test_window_size_count
test_more.py::ReplaceTests::test_window_size_count
self =
def test_window_size_count(self):
iterable = range(10)
pred = lambda *args: (args == (0, 1, 2)) or (args == (7, 8, 9))
substitutes = []
> actual = list(
mi.replace(iterable, pred, substitutes, count=1, window_size=3)
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3730: TypeError
test_more.py::ReplaceTests::test_window_size_end
test_more.py::ReplaceTests::test_window_size_end
self =
def test_window_size_end(self):
iterable = range(10)
pred = lambda *args: args == (7, 8, 9)
substitutes = []
> actual = list(mi.replace(iterable, pred, substitutes, window_size=3))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3722: TypeError
test_more.py::ReplaceTests::test_window_size_large
test_more.py::ReplaceTests::test_window_size_large
self =
def test_window_size_large(self):
iterable = range(4)
pred = lambda a, b, c, d, e: True
substitutes = [5, 6, 7]
> actual = list(mi.replace(iterable, pred, substitutes, window_size=5))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3740: TypeError
test_more.py::ReplaceTests::test_window_size_zero
test_more.py::ReplaceTests::test_window_size_zero
self =
def test_window_size_zero(self):
iterable = range(10)
pred = lambda *args: True
substitutes = []
with self.assertRaises(ValueError):
> list(mi.replace(iterable, pred, substitutes, window_size=0))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3749: TypeError
test_more.py::PartitionsTest::test_duplicates
test_more.py::PartitionsTest::test_duplicates
self =
def test_duplicates(self):
iterable = [1, 1, 1]
> actual = list(mi.partitions(iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3791: TypeError
test_more.py::PartitionsTest::test_empty
test_more.py::PartitionsTest::test_empty
self =
def test_empty(self):
iterable = []
> actual = list(mi.partitions(iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3779: TypeError
test_more.py::PartitionsTest::test_order
test_more.py::PartitionsTest::test_order
self =
def test_order(self):
iterable = iter([3, 2, 1])
> actual = list(mi.partitions(iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3785: TypeError
test_more.py::PartitionsTest::test_types
test_more.py::PartitionsTest::test_types
self =
def test_types(self):
for iterable in ['abcd', ['a', 'b', 'c', 'd'], ('a', 'b', 'c', 'd')]:
with self.subTest(iterable=iterable):
> actual = list(mi.partitions(iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3764: TypeError
test_more.py::SetPartitionsTests::test_duplicates
test_more.py::SetPartitionsTests::test_duplicates
self =
def test_duplicates(self):
a = set(range(6))
> for p in mi.set_partitions(a):
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3878: TypeError
test_more.py::SetPartitionsTests::test_each_correct
test_more.py::SetPartitionsTests::test_each_correct
self =
def test_each_correct(self):
a = set(range(6))
> for p in mi.set_partitions(a):
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3872: TypeError
test_more.py::SetPartitionsTests::test_found_all
test_more.py::SetPartitionsTests::test_found_all
self =
def test_found_all(self):
"""small example, hand-checked"""
expected = [
[[0], [1], [2, 3, 4]],
[[0], [1, 2], [3, 4]],
[[0], [2], [1, 3, 4]],
[[0], [3], [1, 2, 4]],
[[0], [4], [1, 2, 3]],
[[0], [1, 3], [2, 4]],
[[0], [1, 4], [2, 3]],
[[1], [2], [0, 3, 4]],
[[1], [3], [0, 2, 4]],
[[1], [4], [0, 2, 3]],
[[1], [0, 2], [3, 4]],
[[1], [0, 3], [2, 4]],
[[1], [0, 4], [2, 3]],
[[2], [3], [0, 1, 4]],
[[2], [4], [0, 1, 3]],
[[2], [0, 1], [3, 4]],
[[2], [0, 3], [1, 4]],
[[2], [0, 4], [1, 3]],
[[3], [4], [0, 1, 2]],
[[3], [0, 1], [2, 4]],
[[3], [0, 2], [1, 4]],
[[3], [0, 4], [1, 2]],
[[4], [0, 1], [2, 3]],
[[4], [0, 2], [1, 3]],
[[4], [0, 3], [1, 2]],
]
actual = mi.set_partitions(range(5), 3)
self.assertEqual(
self._normalize_partitions(expected),
> self._normalize_partitions(actual),
)
tests/test_more.py:3913:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ps = None
@staticmethod
def _normalize_partitions(ps):
"""
Return a normalized set of all normalized partitions using
_FrozenMultiset
"""
return _FrozenMultiset(
> SetPartitionsTests._normalize_partition(p) for p in ps
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3858: TypeError
test_more.py::SetPartitionsTests::test_max_size
test_more.py::SetPartitionsTests::test_max_size
self =
def test_max_size(self):
it = 'abc'
actual = mi.set_partitions(it, max_size=2)
expected = [['a', 'bc'], ['ab', 'c'], ['b', 'ac'], ['a', 'b', 'c']]
self.assertEqual(
self._normalize_partitions(expected),
> self._normalize_partitions(actual),
)
tests/test_more.py:3957:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ps = None
@staticmethod
def _normalize_partitions(ps):
"""
Return a normalized set of all normalized partitions using
_FrozenMultiset
"""
return _FrozenMultiset(
> SetPartitionsTests._normalize_partition(p) for p in ps
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3858: TypeError
test_more.py::SetPartitionsTests::test_min_size
test_more.py::SetPartitionsTests::test_min_size
self =
def test_min_size(self):
it = 'abc'
actual = mi.set_partitions(it, min_size=2)
expected = [['abc']]
self.assertEqual(
self._normalize_partitions(expected),
> self._normalize_partitions(actual),
)
tests/test_more.py:3948:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ps = None
@staticmethod
def _normalize_partitions(ps):
"""
Return a normalized set of all normalized partitions using
_FrozenMultiset
"""
return _FrozenMultiset(
> SetPartitionsTests._normalize_partition(p) for p in ps
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3858: TypeError
test_more.py::SetPartitionsTests::test_no_group
test_more.py::SetPartitionsTests::test_no_group
self =
def test_no_group(self):
def helper():
list(mi.set_partitions(range(4), -1))
> self.assertRaises(ValueError, helper)
tests/test_more.py:3937:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
def helper():
> list(mi.set_partitions(range(4), -1))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3935: TypeError
test_more.py::SetPartitionsTests::test_repeated
test_more.py::SetPartitionsTests::test_repeated
self =
def test_repeated(self):
it = 'aaa'
actual = mi.set_partitions(it, 2)
expected = [['a', 'aa'], ['a', 'aa'], ['a', 'aa']]
self.assertEqual(
self._normalize_partitions(expected),
> self._normalize_partitions(actual),
)
tests/test_more.py:3867:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
ps = None
@staticmethod
def _normalize_partitions(ps):
"""
Return a normalized set of all normalized partitions using
_FrozenMultiset
"""
return _FrozenMultiset(
> SetPartitionsTests._normalize_partition(p) for p in ps
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3858: TypeError
test_more.py::SetPartitionsTests::test_stirling_numbers
test_more.py::SetPartitionsTests::test_stirling_numbers
self =
def test_stirling_numbers(self):
"""Check against https://en.wikipedia.org/wiki/
Stirling_numbers_of_the_second_kind#Table_of_values"""
cardinality_by_k_by_n = [
[1],
[1, 1],
[1, 3, 1],
[1, 7, 6, 1],
[1, 15, 25, 10, 1],
[1, 31, 90, 65, 15, 1],
]
for n, cardinality_by_k in enumerate(cardinality_by_k_by_n, 1):
for k, cardinality in enumerate(cardinality_by_k, 1):
self.assertEqual(
> cardinality, len(list(mi.set_partitions(range(n), k)))
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3930: TypeError
test_more.py::SetPartitionsTests::test_to_many_groups
test_more.py::SetPartitionsTests::test_to_many_groups
self =
def test_to_many_groups(self):
> self.assertEqual([], list(mi.set_partitions(range(4), 5)))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:3940: TypeError
test_more.py::OnlyTests::test_custom_exception
test_more.py::OnlyTests::test_custom_exception
self =
def test_custom_exception(self):
self.assertEqual(mi.only([], too_long=RuntimeError), None)
> self.assertEqual(mi.only([1], too_long=RuntimeError), 1)
E AssertionError: None != 1
tests/test_more.py:4007: AssertionError
test_more.py::OnlyTests::test_custom_value
test_more.py::OnlyTests::test_custom_value
self =
def test_custom_value(self):
> self.assertEqual(mi.only([], default='!'), '!')
E AssertionError: None != '!'
tests/test_more.py:4001: AssertionError
test_more.py::OnlyTests::test_default_exception_message
test_more.py::OnlyTests::test_default_exception_message
self =
def test_default_exception_message(self):
> self.assertRaisesRegex(
ValueError,
"Expected exactly one item in iterable, "
"but got 'foo', 'bar', and perhaps more",
lambda: mi.only(['foo', 'bar', 'baz']),
)
E AssertionError: ValueError not raised by
tests/test_more.py:4013: AssertionError
test_more.py::OnlyTests::test_defaults
test_more.py::OnlyTests::test_defaults
self =
def test_defaults(self):
self.assertEqual(mi.only([]), None)
> self.assertEqual(mi.only([1]), 1)
E AssertionError: None != 1
tests/test_more.py:3997: AssertionError
test_more.py::IchunkedTests::test_even
test_more.py::IchunkedTests::test_even
self =
def test_even(self):
iterable = (str(x) for x in range(10))
> actual = [''.join(c) for c in mi.ichunked(iterable, 5)]
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4024: TypeError
test_more.py::IchunkedTests::test_laziness
test_more.py::IchunkedTests::test_laziness
self =
def test_laziness(self):
def gen():
yield 0
raise RuntimeError
yield from count(1)
it = mi.ichunked(gen(), 4)
> chunk = next(it)
E TypeError: 'NoneType' object is not an iterator
tests/test_more.py:4060: TypeError
test_more.py::IchunkedTests::test_memory_in_order
test_more.py::IchunkedTests::test_memory_in_order
self =
def test_memory_in_order(self):
gen_numbers = []
def gen():
for gen_number in count():
gen_numbers.append(gen_number)
yield gen_number
# No items should be kept in memory when a ichunked is first called
all_chunks = mi.ichunked(gen(), 4)
self.assertEqual(gen_numbers, [])
# The first item of each chunk should be generated on chunk generation
> first_chunk = next(all_chunks)
E TypeError: 'NoneType' object is not an iterator
tests/test_more.py:4077: TypeError
test_more.py::IchunkedTests::test_negative
test_more.py::IchunkedTests::test_negative
self =
def test_negative(self):
iterable = count()
with self.assertRaises(ValueError):
> [list(c) for c in mi.ichunked(iterable, -1)]
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4043: TypeError
test_more.py::IchunkedTests::test_odd
test_more.py::IchunkedTests::test_odd
self =
def test_odd(self):
iterable = (str(x) for x in range(10))
> actual = [''.join(c) for c in mi.ichunked(iterable, 4)]
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4030: TypeError
test_more.py::IchunkedTests::test_out_of_order
test_more.py::IchunkedTests::test_out_of_order
self =
def test_out_of_order(self):
iterable = map(str, count())
it = mi.ichunked(iterable, 4)
> chunk_1 = next(it)
E TypeError: 'NoneType' object is not an iterator
tests/test_more.py:4048: TypeError
test_more.py::IchunkedTests::test_zero
test_more.py::IchunkedTests::test_zero
self =
def test_zero(self):
iterable = []
> actual = [list(c) for c in mi.ichunked(iterable, 0)]
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4036: TypeError
test_more.py::DistinctCombinationsTests::test_basic
test_more.py::DistinctCombinationsTests::test_basic
self =
def test_basic(self):
for iterable in [
(1, 2, 2, 3, 3, 3), # In order
range(6), # All distinct
'abbccc', # Not numbers
'cccbba', # Backward
'mississippi', # No particular order
]:
for r in range(len(iterable)):
with self.subTest(iterable=iterable, r=r):
> actual = list(mi.distinct_combinations(iterable, r))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4113: TypeError
test_more.py::DistinctCombinationsTests::test_empty
test_more.py::DistinctCombinationsTests::test_empty
self =
def test_empty(self):
> self.assertEqual(list(mi.distinct_combinations([], 2)), [])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4124: TypeError
test_more.py::DistinctCombinationsTests::test_negative
test_more.py::DistinctCombinationsTests::test_negative
self =
def test_negative(self):
with self.assertRaises(ValueError):
> list(mi.distinct_combinations([], -1))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4121: TypeError
test_more.py::FilterExceptTests::test_false
test_more.py::FilterExceptTests::test_false
self =
def test_false(self):
# Even if the validator returns false, we pass through
validator = lambda x: False
iterable = ['0', '1', '2', 'three', None]
> actual = list(mi.filter_except(validator, iterable, Exception))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4148: TypeError
test_more.py::FilterExceptTests::test_multiple
test_more.py::FilterExceptTests::test_multiple
self =
def test_multiple(self):
iterable = ['0', '1', '2', 'three', None, '4']
> actual = list(mi.filter_except(int, iterable, ValueError, TypeError))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4154: TypeError
test_more.py::FilterExceptTests::test_no_exceptions_pass
test_more.py::FilterExceptTests::test_no_exceptions_pass
self =
def test_no_exceptions_pass(self):
iterable = '0123'
> actual = list(mi.filter_except(int, iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4130: TypeError
test_more.py::FilterExceptTests::test_no_exceptions_raise
test_more.py::FilterExceptTests::test_no_exceptions_raise
self =
def test_no_exceptions_raise(self):
iterable = ['0', '1', 'two', '3']
with self.assertRaises(ValueError):
> list(mi.filter_except(int, iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4137: TypeError
test_more.py::MapExceptTests::test_multiple
test_more.py::MapExceptTests::test_multiple
self =
def test_multiple(self):
iterable = ['0', '1', '2', 'three', None, '4']
> actual = list(mi.map_except(int, iterable, ValueError, TypeError))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4178: TypeError
test_more.py::MapExceptTests::test_no_exceptions_pass
test_more.py::MapExceptTests::test_no_exceptions_pass
self =
def test_no_exceptions_pass(self):
iterable = '0123'
> actual = list(mi.map_except(int, iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4162: TypeError
test_more.py::MapExceptTests::test_no_exceptions_raise
test_more.py::MapExceptTests::test_no_exceptions_raise
self =
def test_no_exceptions_raise(self):
iterable = ['0', '1', 'two', '3']
with self.assertRaises(ValueError):
> list(mi.map_except(int, iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4169: TypeError
test_more.py::MapIfTests::test_empty
test_more.py::MapIfTests::test_empty
self =
def test_empty(self):
> actual = list(mi.map_if([], lambda x: len(x) > 5, lambda x: None))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4201: TypeError
test_more.py::MapIfTests::test_with_func_else
test_more.py::MapIfTests::test_with_func_else
self =
def test_with_func_else(self):
iterable = list(range(-5, 5))
> actual = list(
mi.map_if(
iterable, lambda x: x >= 0, lambda x: 'notneg', lambda x: 'neg'
)
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4192: TypeError
test_more.py::MapIfTests::test_without_func_else
test_more.py::MapIfTests::test_without_func_else
self =
def test_without_func_else(self):
iterable = list(range(-5, 5))
> actual = list(mi.map_if(iterable, lambda x: x > 3, lambda x: 'toobig'))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4186: TypeError
test_more.py::SampleTests::test_counts
test_more.py::SampleTests::test_counts
self =
def test_counts(self):
# Test with counts
seed(0)
iterable = ['red', 'blue']
counts = [4, 2]
k = 5
> actual = list(mi.sample(iterable, counts=counts, k=k))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4246: TypeError
test_more.py::SampleTests::test_counts_all
test_more.py::SampleTests::test_counts_all
self =
def test_counts_all(self):
actual = Counter(mi.sample('uwxyz', 35, counts=(1, 0, 4, 10, 20)))
expected = Counter({'u': 1, 'x': 4, 'y': 10, 'z': 20})
> self.assertEqual(actual, expected)
E AssertionError: Counter() != Counter({'z': 20, 'y': 10, 'x': 4, 'u': 1})
tests/test_more.py:4258: AssertionError
test_more.py::SampleTests::test_invariance_under_permutations_unweighted
test_more.py::SampleTests::test_invariance_under_permutations_unweighted
self =
def test_invariance_under_permutations_unweighted(self):
"""The order of the data should not matter. This is a stochastic test,
but it will fail in less than 1 / 10_000 cases."""
# Create a data set and a reversed data set
data = list(range(100))
data_rev = list(reversed(data))
# Sample each data set 10 times
> data_means = [mean(mi.sample(data, k=50)) for _ in range(10)]
tests/test_more.py:4292:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/root/.local/share/uv/python/cpython-3.12.6-linux-x86_64-gnu/lib/python3.12/statistics.py:484: in mean
T, total, n = _sum(data)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
data = None
def _sum(data):
"""_sum(data) -> (type, sum, count)
Return a high-precision sum of the given numeric data as a fraction,
together with the type to be converted to and the count of items.
Examples
--------
>>> _sum([3, 2.25, 4.5, -0.5, 0.25])
(, Fraction(19, 2), 5)
Some sources of round-off error will be avoided:
# Built-in sum returns zero.
>>> _sum([1e50, 1, -1e50] * 1000)
(, Fraction(1000, 1), 3000)
Fractions and Decimals are also supported:
>>> from fractions import Fraction as F
>>> _sum([F(2, 3), F(7, 5), F(1, 4), F(5, 6)])
(, Fraction(63, 20), 4)
>>> from decimal import Decimal as D
>>> data = [D("0.1375"), D("0.2108"), D("0.3061"), D("0.0419")]
>>> _sum(data)
(, Fraction(6963, 10000), 4)
Mixed types are currently treated as an error, except that int is
allowed.
"""
count = 0
types = set()
types_add = types.add
partials = {}
partials_get = partials.get
> for typ, values in groupby(data, type):
E TypeError: 'NoneType' object is not iterable
/root/.local/share/uv/python/cpython-3.12.6-linux-x86_64-gnu/lib/python3.12/statistics.py:191: TypeError
test_more.py::SampleTests::test_invariance_under_permutations_weighted
test_more.py::SampleTests::test_invariance_under_permutations_weighted
self =
def test_invariance_under_permutations_weighted(self):
"""The order of the data should not matter. This is a stochastic test,
but it will fail in less than 1 / 10_000 cases."""
# Create a data set and a reversed data set
data = list(range(1, 101))
data_rev = list(reversed(data))
# Sample each data set 10 times
data_means = [
> mean(mi.sample(data, k=50, weights=data)) for _ in range(10)
]
tests/test_more.py:4311:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/root/.local/share/uv/python/cpython-3.12.6-linux-x86_64-gnu/lib/python3.12/statistics.py:484: in mean
T, total, n = _sum(data)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
data = None
def _sum(data):
"""_sum(data) -> (type, sum, count)
Return a high-precision sum of the given numeric data as a fraction,
together with the type to be converted to and the count of items.
Examples
--------
>>> _sum([3, 2.25, 4.5, -0.5, 0.25])
(, Fraction(19, 2), 5)
Some sources of round-off error will be avoided:
# Built-in sum returns zero.
>>> _sum([1e50, 1, -1e50] * 1000)
(, Fraction(1000, 1), 3000)
Fractions and Decimals are also supported:
>>> from fractions import Fraction as F
>>> _sum([F(2, 3), F(7, 5), F(1, 4), F(5, 6)])
(, Fraction(63, 20), 4)
>>> from decimal import Decimal as D
>>> data = [D("0.1375"), D("0.2108"), D("0.3061"), D("0.0419")]
>>> _sum(data)
(, Fraction(6963, 10000), 4)
Mixed types are currently treated as an error, except that int is
allowed.
"""
count = 0
types = set()
types_add = types.add
partials = {}
partials_get = partials.get
> for typ, values in groupby(data, type):
E TypeError: 'NoneType' object is not iterable
/root/.local/share/uv/python/cpython-3.12.6-linux-x86_64-gnu/lib/python3.12/statistics.py:191: TypeError
test_more.py::SampleTests::test_length
test_more.py::SampleTests::test_length
self =
def test_length(self):
"""Check that *k* elements are sampled."""
data = [1, 2, 3, 4, 5]
for k in [0, 3, 5, 7]:
sampled = mi.sample(data, k=k)
> actual = len(sampled)
E TypeError: object of type 'NoneType' has no len()
tests/test_more.py:4230: TypeError
test_more.py::SampleTests::test_negative
test_more.py::SampleTests::test_negative
self =
def test_negative(self):
data = [1, 2, 3, 4, 5]
> with self.assertRaises(ValueError):
E AssertionError: ValueError not raised
tests/test_more.py:4222: AssertionError
test_more.py::SampleTests::test_sampling_entire_iterable
test_more.py::SampleTests::test_sampling_entire_iterable
self =
def test_sampling_entire_iterable(self):
"""If k=len(iterable), the sample contains the original elements."""
data = ["a", 2, "a", 4, (1, 2, 3)]
> actual = set(mi.sample(data, k=len(data)))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4263: TypeError
test_more.py::SampleTests::test_strict
test_more.py::SampleTests::test_strict
self =
def test_strict(self):
data = ['1', '2', '3', '4', '5']
> self.assertEqual(set(mi.sample(data, 6, strict=False)), set(data))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4236: TypeError
test_more.py::SampleTests::test_unit_case
test_more.py::SampleTests::test_unit_case
self =
def test_unit_case(self):
"""Test against a fixed case by seeding the random module."""
# Beware that this test really just verifies random.random() behavior.
# If the algorithm is changed (e.g. to a more naive implementation)
# this test will fail, but the algorithm might be correct.
# Also, this test can pass and the algorithm can be completely wrong.
data = "abcdef"
weights = list(range(1, len(data) + 1))
seed(123)
actual = mi.sample(data, k=2, weights=weights)
expected = ['f', 'e']
> self.assertEqual(actual, expected)
E AssertionError: None != ['f', 'e']
tests/test_more.py:4218: AssertionError
test_more.py::IsSortedTests::test_basic
test_more.py::IsSortedTests::test_basic
self =
def test_basic(self):
for iterable, kwargs, expected in [
([], {}, True),
([1], {}, True),
([1, 2, 3], {}, True),
([1, 1, 2, 3], {}, True),
([1, 10, 2, 3], {}, False),
([3, float('nan'), 1, 2], {}, True),
(['1', '10', '2', '3'], {}, True),
(['1', '10', '2', '3'], {'key': int}, False),
([1, 2, 3], {'reverse': True}, False),
([1, 1, 2, 3], {'reverse': True}, False),
([1, 10, 2, 3], {'reverse': True}, False),
(['3', '2', '10', '1'], {'reverse': True}, True),
(['3', '2', '10', '1'], {'key': int, 'reverse': True}, False),
# strict
([], {'strict': True}, True),
([1], {'strict': True}, True),
([1, 1], {'strict': True}, False),
([1, 2, 3], {'strict': True}, True),
([1, 1, 2, 3], {'strict': True}, False),
([1, 10, 2, 3], {'strict': True}, False),
(['1', '10', '2', '3'], {'strict': True}, True),
(['1', '10', '2', '3', '3'], {'strict': True}, False),
(['1', '10', '2', '3'], {'strict': True, 'key': int}, False),
([1, 2, 3], {'strict': True, 'reverse': True}, False),
([1, 1, 2, 3], {'strict': True, 'reverse': True}, False),
([1, 10, 2, 3], {'strict': True, 'reverse': True}, False),
(['3', '2', '10', '1'], {'strict': True, 'reverse': True}, True),
(
['3', '2', '10', '10', '1'],
{'strict': True, 'reverse': True},
False,
),
(
['3', '2', '10', '1'],
{'strict': True, 'key': int, 'reverse': True},
False,
),
# We'll do the same weird thing as Python here
(['nan', 0, 'nan', 0], {'key': float}, True),
([0, 'nan', 0, 'nan'], {'key': float}, True),
(['nan', 0, 'nan', 0], {'key': float, 'reverse': True}, True),
([0, 'nan', 0, 'nan'], {'key': float, 'reverse': True}, True),
([0, 'nan', 0, 'nan'], {'strict': True, 'key': float}, True),
(
['nan', 0, 'nan', 0],
{'strict': True, 'key': float, 'reverse': True},
True,
),
]:
key = kwargs.get('key', None)
reverse = kwargs.get('reverse', False)
strict = kwargs.get('strict', False)
with self.subTest(
iterable=iterable, key=key, reverse=reverse, strict=strict
):
mi_result = mi.is_sorted(
iter(iterable), key=key, reverse=reverse, strict=strict
)
sorted_iterable = sorted(iterable, key=key, reverse=reverse)
if strict:
sorted_iterable = list(mi.unique_justseen(sorted_iterable))
py_result = iterable == sorted_iterable
> self.assertEqual(mi_result, expected)
E AssertionError: None != True
tests/test_more.py:4394: AssertionError
test_more.py::CallbackIterTests::test_abort
test_more.py::CallbackIterTests::test_abort
self =
def test_abort(self):
func = lambda callback=None: self._target(cb=callback, wait=0.1)
> with mi.callback_iter(func) as it:
tests/test_more.py:4457:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self =
func = . at 0x7fdd54626980>
callback_kwd = 'callback', wait_seconds = 0.1
def __init__(self, func, callback_kwd='callback', wait_seconds=0.1):
self._func = func
self._callback_kwd = callback_kwd
self._aborted = False
self._future = None
self._wait_seconds = wait_seconds
self._executor = __import__('concurrent.futures').futures.ThreadPoolExecutor(max_workers=1)
> self._iterator = self._reader()
E AttributeError: 'callback_iter' object has no attribute '_reader'
more_itertools/more.py:2567: AttributeError
test_more.py::CallbackIterTests::test_basic
test_more.py::CallbackIterTests::test_basic
self =
def test_basic(self):
func = lambda callback=None: self._target(cb=callback, wait=0.02)
> with mi.callback_iter(func, wait_seconds=0.01) as it:
tests/test_more.py:4414:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self =
func = . at 0x7fdd546268e0>
callback_kwd = 'callback', wait_seconds = 0.01
def __init__(self, func, callback_kwd='callback', wait_seconds=0.1):
self._func = func
self._callback_kwd = callback_kwd
self._aborted = False
self._future = None
self._wait_seconds = wait_seconds
self._executor = __import__('concurrent.futures').futures.ThreadPoolExecutor(max_workers=1)
> self._iterator = self._reader()
E AttributeError: 'callback_iter' object has no attribute '_reader'
more_itertools/more.py:2567: AttributeError
test_more.py::CallbackIterTests::test_callback_kwd
test_more.py::CallbackIterTests::test_callback_kwd
self =
def test_callback_kwd(self):
> with mi.callback_iter(self._target, callback_kwd='cb') as it:
tests/test_more.py:4438:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self =
func = >
callback_kwd = 'cb', wait_seconds = 0.1
def __init__(self, func, callback_kwd='callback', wait_seconds=0.1):
self._func = func
self._callback_kwd = callback_kwd
self._aborted = False
self._future = None
self._wait_seconds = wait_seconds
self._executor = __import__('concurrent.futures').futures.ThreadPoolExecutor(max_workers=1)
> self._iterator = self._reader()
E AttributeError: 'callback_iter' object has no attribute '_reader'
more_itertools/more.py:2567: AttributeError
test_more.py::CallbackIterTests::test_exception
test_more.py::CallbackIterTests::test_exception
self =
def test_exception(self):
func = lambda callback=None: self._target(cb=callback, exc=ValueError)
> with mi.callback_iter(func) as it:
tests/test_more.py:4471:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self =
func = . at 0x7fdd54626ac0>
callback_kwd = 'callback', wait_seconds = 0.1
def __init__(self, func, callback_kwd='callback', wait_seconds=0.1):
self._func = func
self._callback_kwd = callback_kwd
self._aborted = False
self._future = None
self._wait_seconds = wait_seconds
self._executor = __import__('concurrent.futures').futures.ThreadPoolExecutor(max_workers=1)
> self._iterator = self._reader()
E AttributeError: 'callback_iter' object has no attribute '_reader'
more_itertools/more.py:2567: AttributeError
test_more.py::CallbackIterTests::test_no_result
test_more.py::CallbackIterTests::test_no_result
self =
def test_no_result(self):
func = lambda callback=None: self._target(cb=callback)
> with mi.callback_iter(func) as it:
tests/test_more.py:4465:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self =
func = . at 0x7fdd54626b60>
callback_kwd = 'callback', wait_seconds = 0.1
def __init__(self, func, callback_kwd='callback', wait_seconds=0.1):
self._func = func
self._callback_kwd = callback_kwd
self._aborted = False
self._future = None
self._wait_seconds = wait_seconds
self._executor = __import__('concurrent.futures').futures.ThreadPoolExecutor(max_workers=1)
> self._iterator = self._reader()
E AttributeError: 'callback_iter' object has no attribute '_reader'
more_itertools/more.py:2567: AttributeError
test_more.py::CallbackIterTests::test_partial_consumption
test_more.py::CallbackIterTests::test_partial_consumption
self =
def test_partial_consumption(self):
func = lambda callback=None: self._target(cb=callback)
> with mi.callback_iter(func) as it:
tests/test_more.py:4450:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self =
func = . at 0x7fdd54626c00>
callback_kwd = 'callback', wait_seconds = 0.1
def __init__(self, func, callback_kwd='callback', wait_seconds=0.1):
self._func = func
self._callback_kwd = callback_kwd
self._aborted = False
self._future = None
self._wait_seconds = wait_seconds
self._executor = __import__('concurrent.futures').futures.ThreadPoolExecutor(max_workers=1)
> self._iterator = self._reader()
E AttributeError: 'callback_iter' object has no attribute '_reader'
more_itertools/more.py:2567: AttributeError
test_more.py::WindowedCompleteTests::test_basic
test_more.py::WindowedCompleteTests::test_basic
self =
def test_basic(self):
> actual = list(mi.windowed_complete([1, 2, 3, 4, 5], 3))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4485: TypeError
test_more.py::WindowedCompleteTests::test_every_partition
test_more.py::WindowedCompleteTests::test_every_partition
self =
def test_every_partition(self):
every_partition = lambda seq: chain(
*map(partial(mi.windowed_complete, seq), range(len(seq)))
)
seq = 'ABC'
> actual = list(every_partition(seq))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4516: TypeError
test_more.py::WindowedCompleteTests::test_wrong_length
test_more.py::WindowedCompleteTests::test_wrong_length
self =
def test_wrong_length(self):
seq = [1, 2, 3, 4, 5]
for n in (-10, -1, len(seq) + 1, len(seq) + 10):
with self.subTest(n=n):
with self.assertRaises(ValueError):
> list(mi.windowed_complete(seq, n))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4508: TypeError
test_more.py::WindowedCompleteTests::test_zero_length
test_more.py::WindowedCompleteTests::test_zero_length
self =
def test_zero_length(self):
> actual = list(mi.windowed_complete([1, 2, 3], 0))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4494: TypeError
test_more.py::AllUniqueTests::test_basic
test_more.py::AllUniqueTests::test_basic
self =
def test_basic(self):
for iterable, expected in [
([], True),
([1, 2, 3], True),
([1, 1], False),
([1, 2, 3, 1], False),
([1, 2, 3, '1'], True),
]:
with self.subTest(args=(iterable,)):
> self.assertEqual(mi.all_unique(iterable), expected)
E AssertionError: None != True
tests/test_more.py:4541: AssertionError
test_more.py::AllUniqueTests::test_infinite
test_more.py::AllUniqueTests::test_infinite
self =
def test_infinite(self):
> self.assertEqual(mi.all_unique(mi.prepend(3, count())), False)
E AssertionError: None != False
tests/test_more.py:4562: AssertionError
test_more.py::AllUniqueTests::test_key
test_more.py::AllUniqueTests::test_key
self =
def test_key(self):
iterable = ['A', 'B', 'C', 'b']
> self.assertEqual(mi.all_unique(iterable, lambda x: x), True)
E AssertionError: None != True
tests/test_more.py:4558: AssertionError
test_more.py::AllUniqueTests::test_non_hashable
test_more.py::AllUniqueTests::test_non_hashable
self =
def test_non_hashable(self):
> self.assertEqual(mi.all_unique([[1, 2], [3, 4]]), True)
E AssertionError: None != True
tests/test_more.py:4544: AssertionError
test_more.py::AllUniqueTests::test_partially_hashable
test_more.py::AllUniqueTests::test_partially_hashable
self =
def test_partially_hashable(self):
> self.assertEqual(mi.all_unique([[1, 2], [3, 4], (5, 6)]), True)
E AssertionError: None != True
tests/test_more.py:4548: AssertionError
test_more.py::NthProductTests::test_basic
test_more.py::NthProductTests::test_basic
self =
def test_basic(self):
iterables = ['ab', 'cdef', 'ghi']
for index, expected in enumerate(product(*iterables)):
actual = mi.nth_product(index, *iterables)
> self.assertEqual(actual, expected)
E AssertionError: None != ('a', 'c', 'g')
tests/test_more.py:4570: AssertionError
test_more.py::NthProductTests::test_invalid_index
test_more.py::NthProductTests::test_invalid_index
self =
def test_invalid_index(self):
> with self.assertRaises(IndexError):
E AssertionError: IndexError not raised
tests/test_more.py:4584: AssertionError
test_more.py::NthProductTests::test_long
test_more.py::NthProductTests::test_long
self =
def test_long(self):
actual = mi.nth_product(1337, range(101), range(22), range(53))
expected = (1, 3, 12)
> self.assertEqual(actual, expected)
E AssertionError: None != (1, 3, 12)
tests/test_more.py:4575: AssertionError
test_more.py::NthProductTests::test_negative
test_more.py::NthProductTests::test_negative
self =
def test_negative(self):
iterables = ['abc', 'de', 'fghi']
for index, expected in enumerate(product(*iterables)):
actual = mi.nth_product(index - 24, *iterables)
> self.assertEqual(actual, expected)
E AssertionError: None != ('a', 'd', 'f')
tests/test_more.py:4581: AssertionError
test_more.py::NthCombinationWithReplacementTests::test_basic
test_more.py::NthCombinationWithReplacementTests::test_basic
self =
def test_basic(self):
iterable = 'abcdefg'
r = 4
for index, expected in enumerate(
combinations_with_replacement(iterable, r)
):
actual = mi.nth_combination_with_replacement(iterable, r, index)
> self.assertEqual(actual, expected)
E AssertionError: None != ('a', 'a', 'a', 'a')
tests/test_more.py:4596: AssertionError
test_more.py::NthCombinationWithReplacementTests::test_invalid_index
test_more.py::NthCombinationWithReplacementTests::test_invalid_index
self =
def test_invalid_index(self):
> with self.assertRaises(IndexError):
E AssertionError: IndexError not raised
tests/test_more.py:4609: AssertionError
test_more.py::NthCombinationWithReplacementTests::test_invalid_r
test_more.py::NthCombinationWithReplacementTests::test_invalid_r
self =
def test_invalid_r(self):
for r in (-1, 3):
> with self.assertRaises(ValueError):
E AssertionError: ValueError not raised
tests/test_more.py:4605: AssertionError
test_more.py::NthCombinationWithReplacementTests::test_long
test_more.py::NthCombinationWithReplacementTests::test_long
self =
def test_long(self):
actual = mi.nth_combination_with_replacement(range(90), 4, 2000000)
expected = (22, 65, 68, 81)
> self.assertEqual(actual, expected)
E AssertionError: None != (22, 65, 68, 81)
tests/test_more.py:4601: AssertionError
test_more.py::ValueChainTests::test_complex
test_more.py::ValueChainTests::test_complex
self =
def test_complex(self):
obj = object()
> actual = list(
mi.value_chain(
(1, (2, (3,))),
['foo', ['bar', ['baz']], 'tic'],
{'key': {'foo': 1}},
obj,
)
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4636: TypeError
test_more.py::ValueChainTests::test_empty
test_more.py::ValueChainTests::test_empty
self =
def test_empty(self):
> actual = list(mi.value_chain())
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4615: TypeError
test_more.py::ValueChainTests::test_empty_lists
test_more.py::ValueChainTests::test_empty_lists
self =
def test_empty_lists(self):
> actual = list(mi.value_chain(1, 2, [], [3, 4]))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4630: TypeError
test_more.py::ValueChainTests::test_more
test_more.py::ValueChainTests::test_more
self =
def test_more(self):
> actual = list(mi.value_chain(b'bar', [1, 2, 3], 4, {'key': 1}))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4625: TypeError
test_more.py::ValueChainTests::test_simple
test_more.py::ValueChainTests::test_simple
self =
def test_simple(self):
> actual = list(mi.value_chain(1, 2.71828, False, 'foo'))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4620: TypeError
test_more.py::ProductIndexTests::test_basic
test_more.py::ProductIndexTests::test_basic
self =
def test_basic(self):
iterables = ['ab', 'cdef', 'ghi']
first_index = {}
for index, element in enumerate(product(*iterables)):
actual = mi.product_index(element, *iterables)
expected = first_index.setdefault(element, index)
> self.assertEqual(actual, expected)
E AssertionError: None != 0
tests/test_more.py:4655: AssertionError
test_more.py::ProductIndexTests::test_invalid_empty
test_more.py::ProductIndexTests::test_invalid_empty
self =
def test_invalid_empty(self):
> with self.assertRaises(ValueError):
E AssertionError: ValueError not raised
tests/test_more.py:4671: AssertionError
test_more.py::ProductIndexTests::test_invalid_large
test_more.py::ProductIndexTests::test_invalid_large
self =
def test_invalid_large(self):
> with self.assertRaises(ValueError):
E AssertionError: ValueError not raised
tests/test_more.py:4679: AssertionError
test_more.py::ProductIndexTests::test_invalid_match
test_more.py::ProductIndexTests::test_invalid_match
self =
def test_invalid_match(self):
> with self.assertRaises(ValueError):
E AssertionError: ValueError not raised
tests/test_more.py:4683: AssertionError
test_more.py::ProductIndexTests::test_invalid_small
test_more.py::ProductIndexTests::test_invalid_small
self =
def test_invalid_small(self):
> with self.assertRaises(ValueError):
E AssertionError: ValueError not raised
tests/test_more.py:4675: AssertionError
test_more.py::ProductIndexTests::test_long
test_more.py::ProductIndexTests::test_long
self =
def test_long(self):
actual = mi.product_index((1, 3, 12), range(101), range(22), range(53))
expected = 1337
> self.assertEqual(actual, expected)
E AssertionError: None != 1337
tests/test_more.py:4668: AssertionError
test_more.py::ProductIndexTests::test_multiplicity
test_more.py::ProductIndexTests::test_multiplicity
self =
def test_multiplicity(self):
iterables = ['ab', 'bab', 'cab']
first_index = {}
for index, element in enumerate(product(*iterables)):
actual = mi.product_index(element, *iterables)
expected = first_index.setdefault(element, index)
> self.assertEqual(actual, expected)
E AssertionError: None != 0
tests/test_more.py:4663: AssertionError
test_more.py::CombinationIndexTests::test_invalid_large
test_more.py::CombinationIndexTests::test_invalid_large
self =
def test_invalid_large(self):
> with self.assertRaises(ValueError):
E AssertionError: ValueError not raised
tests/test_more.py:4730: AssertionError
test_more.py::CombinationIndexTests::test_invalid_match
test_more.py::CombinationIndexTests::test_invalid_match
self =
def test_invalid_match(self):
> with self.assertRaises(ValueError):
E AssertionError: ValueError not raised
tests/test_more.py:4734: AssertionError
test_more.py::CombinationIndexTests::test_invalid_order
test_more.py::CombinationIndexTests::test_invalid_order
self =
def test_invalid_order(self):
> with self.assertRaises(ValueError):
E AssertionError: ValueError not raised
tests/test_more.py:4726: AssertionError
test_more.py::CombinationIndexTests::test_long
test_more.py::CombinationIndexTests::test_long
self =
def test_long(self):
actual = mi.combination_index((2, 12, 35, 126), range(180))
expected = 2000000
> self.assertEqual(actual, expected)
E AssertionError: None != 2000000
tests/test_more.py:4723: AssertionError
test_more.py::CombinationIndexTests::test_multiplicity
test_more.py::CombinationIndexTests::test_multiplicity
self =
def test_multiplicity(self):
iterable = 'abacba'
r = 3
first_index = {}
for index, element in enumerate(combinations(iterable, r)):
actual = mi.combination_index(element, iterable)
expected = first_index.setdefault(element, index)
> self.assertEqual(actual, expected)
E AssertionError: None != 0
tests/test_more.py:4713: AssertionError
test_more.py::CombinationIndexTests::test_null
test_more.py::CombinationIndexTests::test_null
self =
def test_null(self):
actual = mi.combination_index(tuple(), [])
expected = 0
> self.assertEqual(actual, expected)
E AssertionError: None != 0
tests/test_more.py:4718: AssertionError
test_more.py::CombinationIndexTests::test_r_equal_to_n
test_more.py::CombinationIndexTests::test_r_equal_to_n
self =
def test_r_equal_to_n(self):
iterable = 'abcd'
r = len(iterable)
first_index = {}
for index, element in enumerate(combinations(iterable, r=r)):
actual = mi.combination_index(element, iterable)
expected = first_index.setdefault(element, index)
> self.assertEqual(actual, expected)
E AssertionError: None != 0
tests/test_more.py:4704: AssertionError
test_more.py::CombinationIndexTests::test_r_less_than_n
test_more.py::CombinationIndexTests::test_r_less_than_n
self =
def test_r_less_than_n(self):
iterable = 'abcdefg'
r = 4
first_index = {}
for index, element in enumerate(combinations(iterable, r)):
actual = mi.combination_index(element, iterable)
expected = first_index.setdefault(element, index)
> self.assertEqual(actual, expected)
E AssertionError: None != 0
tests/test_more.py:4695: AssertionError
test_more.py::CombinationWithReplacementIndexTests::test_invalid_large
test_more.py::CombinationWithReplacementIndexTests::test_invalid_large
self =
def test_invalid_large(self):
> with self.assertRaises(ValueError):
E AssertionError: ValueError not raised
tests/test_more.py:4789: AssertionError
test_more.py::CombinationWithReplacementIndexTests::test_invalid_match
test_more.py::CombinationWithReplacementIndexTests::test_invalid_match
self =
def test_invalid_match(self):
> with self.assertRaises(ValueError):
E AssertionError: ValueError not raised
tests/test_more.py:4793: AssertionError
test_more.py::CombinationWithReplacementIndexTests::test_invalid_order
test_more.py::CombinationWithReplacementIndexTests::test_invalid_order
self =
def test_invalid_order(self):
> with self.assertRaises(ValueError):
E AssertionError: ValueError not raised
tests/test_more.py:4785: AssertionError
test_more.py::CombinationWithReplacementIndexTests::test_long
test_more.py::CombinationWithReplacementIndexTests::test_long
self =
def test_long(self):
actual = mi.combination_with_replacement_index(
(22, 65, 68, 81), range(90)
)
expected = 2000000
> self.assertEqual(actual, expected)
E AssertionError: None != 2000000
tests/test_more.py:4782: AssertionError
test_more.py::CombinationWithReplacementIndexTests::test_multiplicity
test_more.py::CombinationWithReplacementIndexTests::test_multiplicity
self =
def test_multiplicity(self):
iterable = 'abacba'
r = 3
first_index = {}
for index, element in enumerate(
combinations_with_replacement(iterable, r)
):
actual = mi.combination_with_replacement_index(element, iterable)
expected = first_index.setdefault(element, index)
> self.assertEqual(actual, expected)
E AssertionError: None != 0
tests/test_more.py:4770: AssertionError
test_more.py::CombinationWithReplacementIndexTests::test_null
test_more.py::CombinationWithReplacementIndexTests::test_null
self =
def test_null(self):
actual = mi.combination_with_replacement_index(tuple(), [])
expected = 0
> self.assertEqual(actual, expected)
E AssertionError: None != 0
tests/test_more.py:4775: AssertionError
test_more.py::CombinationWithReplacementIndexTests::test_r_equal_to_n
test_more.py::CombinationWithReplacementIndexTests::test_r_equal_to_n
self =
def test_r_equal_to_n(self):
iterable = 'abcd'
r = len(iterable)
first_index = {}
for index, element in enumerate(
combinations_with_replacement(iterable, r=r)
):
actual = mi.combination_with_replacement_index(element, iterable)
expected = first_index.setdefault(element, index)
> self.assertEqual(actual, expected)
E AssertionError: None != 0
tests/test_more.py:4759: AssertionError
test_more.py::CombinationWithReplacementIndexTests::test_r_less_than_n
test_more.py::CombinationWithReplacementIndexTests::test_r_less_than_n
self =
def test_r_less_than_n(self):
iterable = 'abcdefg'
r = 4
first_index = {}
for index, element in enumerate(
combinations_with_replacement(iterable, r)
):
actual = mi.combination_with_replacement_index(element, iterable)
expected = first_index.setdefault(element, index)
> self.assertEqual(actual, expected)
E AssertionError: None != 0
tests/test_more.py:4748: AssertionError
test_more.py::PermutationIndexTests::test_invalid_large
test_more.py::PermutationIndexTests::test_invalid_large
self =
def test_invalid_large(self):
> with self.assertRaises(ValueError):
E AssertionError: ValueError not raised
tests/test_more.py:4835: AssertionError
test_more.py::PermutationIndexTests::test_invalid_match
test_more.py::PermutationIndexTests::test_invalid_match
self =
def test_invalid_match(self):
> with self.assertRaises(ValueError):
E AssertionError: ValueError not raised
tests/test_more.py:4839: AssertionError
test_more.py::PermutationIndexTests::test_long
test_more.py::PermutationIndexTests::test_long
self =
def test_long(self):
actual = mi.permutation_index((2, 12, 35, 126), range(180))
expected = 11631678
> self.assertEqual(actual, expected)
E AssertionError: None != 11631678
tests/test_more.py:4832: AssertionError
test_more.py::PermutationIndexTests::test_multiplicity
test_more.py::PermutationIndexTests::test_multiplicity
self =
def test_multiplicity(self):
iterable = 'abacba'
r = 3
first_index = {}
for index, element in enumerate(permutations(iterable, r)):
actual = mi.permutation_index(element, iterable)
expected = first_index.setdefault(element, index)
> self.assertEqual(actual, expected)
E AssertionError: None != 0
tests/test_more.py:4822: AssertionError
test_more.py::PermutationIndexTests::test_null
test_more.py::PermutationIndexTests::test_null
self =
def test_null(self):
actual = mi.permutation_index(tuple(), [])
expected = 0
> self.assertEqual(actual, expected)
E AssertionError: None != 0
tests/test_more.py:4827: AssertionError
test_more.py::PermutationIndexTests::test_r_equal_to_n
test_more.py::PermutationIndexTests::test_r_equal_to_n
self =
def test_r_equal_to_n(self):
iterable = 'abcd'
first_index = {}
for index, element in enumerate(permutations(iterable)):
actual = mi.permutation_index(element, iterable)
expected = first_index.setdefault(element, index)
> self.assertEqual(actual, expected)
E AssertionError: None != 0
tests/test_more.py:4813: AssertionError
test_more.py::PermutationIndexTests::test_r_less_than_n
test_more.py::PermutationIndexTests::test_r_less_than_n
self =
def test_r_less_than_n(self):
iterable = 'abcdefg'
r = 4
first_index = {}
for index, element in enumerate(permutations(iterable, r)):
actual = mi.permutation_index(element, iterable)
expected = first_index.setdefault(element, index)
> self.assertEqual(actual, expected)
E AssertionError: None != 0
tests/test_more.py:4805: AssertionError
test_more.py::ChunkedEvenTests::test_0
test_more.py::ChunkedEvenTests::test_0
self =
def test_0(self):
> self._test_finite('', 3, [])
tests/test_more.py:4864:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = , seq = '', n = 3
expected = []
def _test_finite(self, seq, n, expected):
# Check with and without `len()`
> self.assertEqual(list(mi.chunked_even(seq, n)), expected)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4885: TypeError
test_more.py::ChunkedEvenTests::test_1
test_more.py::ChunkedEvenTests::test_1
self =
def test_1(self):
> self._test_finite('A', 1, [['A']])
tests/test_more.py:4867:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = , seq = 'A', n = 1
expected = [['A']]
def _test_finite(self, seq, n, expected):
# Check with and without `len()`
> self.assertEqual(list(mi.chunked_even(seq, n)), expected)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4885: TypeError
test_more.py::ChunkedEvenTests::test_4
test_more.py::ChunkedEvenTests::test_4
self =
def test_4(self):
> self._test_finite('ABCD', 3, [['A', 'B'], ['C', 'D']])
tests/test_more.py:4870:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = , seq = 'ABCD', n = 3
expected = [['A', 'B'], ['C', 'D']]
def _test_finite(self, seq, n, expected):
# Check with and without `len()`
> self.assertEqual(list(mi.chunked_even(seq, n)), expected)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4885: TypeError
test_more.py::ChunkedEvenTests::test_5
test_more.py::ChunkedEvenTests::test_5
self =
def test_5(self):
> self._test_finite('ABCDE', 3, [['A', 'B', 'C'], ['D', 'E']])
tests/test_more.py:4873:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = , seq = 'ABCDE'
n = 3, expected = [['A', 'B', 'C'], ['D', 'E']]
def _test_finite(self, seq, n, expected):
# Check with and without `len()`
> self.assertEqual(list(mi.chunked_even(seq, n)), expected)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4885: TypeError
test_more.py::ChunkedEvenTests::test_6
test_more.py::ChunkedEvenTests::test_6
self =
def test_6(self):
> self._test_finite('ABCDEF', 3, [['A', 'B', 'C'], ['D', 'E', 'F']])
tests/test_more.py:4876:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = , seq = 'ABCDEF'
n = 3, expected = [['A', 'B', 'C'], ['D', 'E', 'F']]
def _test_finite(self, seq, n, expected):
# Check with and without `len()`
> self.assertEqual(list(mi.chunked_even(seq, n)), expected)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4885: TypeError
test_more.py::ChunkedEvenTests::test_7
test_more.py::ChunkedEvenTests::test_7
self =
def test_7(self):
> self._test_finite(
'ABCDEFG', 3, [['A', 'B', 'C'], ['D', 'E'], ['F', 'G']]
)
tests/test_more.py:4879:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = , seq = 'ABCDEFG'
n = 3, expected = [['A', 'B', 'C'], ['D', 'E'], ['F', 'G']]
def _test_finite(self, seq, n, expected):
# Check with and without `len()`
> self.assertEqual(list(mi.chunked_even(seq, n)), expected)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4885: TypeError
test_more.py::ChunkedEvenTests::test_evenness
test_more.py::ChunkedEvenTests::test_evenness
self =
def test_evenness(self):
for N in range(1, 50):
for n in range(1, N + 2):
lengths = []
items = []
> for l in mi.chunked_even(range(N), n):
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4908: TypeError
test_more.py::ChunkedEvenTests::test_infinite
test_more.py::ChunkedEvenTests::test_infinite
self =
def test_infinite(self):
for n in range(1, 5):
k = 0
def count_with_assert():
for i in count():
# Look-ahead should be less than n^2
self.assertLessEqual(i, n * k + n * n)
yield i
ls = mi.chunked_even(count_with_assert(), n)
while k < 2:
> self.assertEqual(next(ls), list(range(k * n, (k + 1) * n)))
E TypeError: 'NoneType' object is not an iterator
tests/test_more.py:4900: TypeError
test_more.py::ZipBroadcastTests::test_scalar_types
test_more.py::ZipBroadcastTests::test_scalar_types
self =
def test_scalar_types(self):
# Default: str and bytes are treated as scalar
self.assertEqual(
> list(mi.zip_broadcast('ab', [1, 2, 3])),
[('ab', 1), ('ab', 2), ('ab', 3)],
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5001: TypeError
test_more.py::ZipBroadcastTests::test_zip
test_more.py::ZipBroadcastTests::test_zip
self =
def test_zip(self):
for objects, zipped, strict_ok in [
# Empty
([], [], True),
# One argument
([1], [(1,)], True),
([[1]], [(1,)], True),
([[1, 2]], [(1,), (2,)], True),
# All scalars
([1, 2], [(1, 2)], True),
([1, 2, 3], [(1, 2, 3)], True),
# Iterables with length = 0
([[], 1], [], True),
([1, []], [], True),
([[], []], [], True),
([[], 1, 2], [], True),
([[], 1, []], [], True),
([1, [], 2], [], True),
([1, [], []], [], True),
([[], [], 1], [], True),
([[], [], []], [], True),
# Iterables with length = 1
([1, [2]], [(1, 2)], True),
([[1], 2], [(1, 2)], True),
([[1], [2]], [(1, 2)], True),
([1, [2], 3], [(1, 2, 3)], True),
([1, [2], [3]], [(1, 2, 3)], True),
([[1], 2, 3], [(1, 2, 3)], True),
([[1], 2, [3]], [(1, 2, 3)], True),
([[1], [2], 3], [(1, 2, 3)], True),
([[1], [2], [3]], [(1, 2, 3)], True),
# Iterables with length > 1
([1, [2, 3]], [(1, 2), (1, 3)], True),
([[1, 2], 3], [(1, 3), (2, 3)], True),
([[1, 2], [3, 4]], [(1, 3), (2, 4)], True),
([1, [2, 3], 4], [(1, 2, 4), (1, 3, 4)], True),
([1, [2, 3], [4, 5]], [(1, 2, 4), (1, 3, 5)], True),
([[1, 2], 3, 4], [(1, 3, 4), (2, 3, 4)], True),
([[1, 2], 3, [4, 5]], [(1, 3, 4), (2, 3, 5)], True),
([[1, 2], [3, 4], 5], [(1, 3, 5), (2, 4, 5)], True),
([[1, 2], [3, 4], [5, 6]], [(1, 3, 5), (2, 4, 6)], True),
# Iterables with different lengths
([[], [1]], [], False),
([[1], []], [], False),
([[1], [2, 3]], [(1, 2)], False),
([[1, 2], [3]], [(1, 3)], False),
([[1, 2], [3], [4]], [(1, 3, 4)], False),
([[1], [2, 3], [4]], [(1, 2, 4)], False),
([[1], [2], [3, 4]], [(1, 2, 3)], False),
([[1], [2, 3], [4, 5]], [(1, 2, 4)], False),
([[1, 2], [3], [4, 5]], [(1, 3, 4)], False),
([[1, 2], [3, 4], [5]], [(1, 3, 5)], False),
([1, [2, 3], [4, 5, 6]], [(1, 2, 4), (1, 3, 5)], False),
([[1, 2], 3, [4, 5, 6]], [(1, 3, 4), (2, 3, 5)], False),
([1, [2, 3, 4], [5, 6]], [(1, 2, 5), (1, 3, 6)], False),
([[1, 2, 3], 4, [5, 6]], [(1, 4, 5), (2, 4, 6)], False),
([[1, 2], [3, 4, 5], 6], [(1, 3, 6), (2, 4, 6)], False),
([[1, 2, 3], [4, 5], 6], [(1, 4, 6), (2, 5, 6)], False),
# Infinite
([count(), 1, [2]], [(0, 1, 2)], False),
([count(), 1, [2, 3]], [(0, 1, 2), (1, 1, 3)], False),
# Miscellaneous
(['a', [1, 2], [3, 4, 5]], [('a', 1, 3), ('a', 2, 4)], False),
]:
# Truncate by default
with self.subTest(objects=objects, strict=False, zipped=zipped):
> self.assertEqual(list(mi.zip_broadcast(*objects)), zipped)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:4985: TypeError
test_more.py::UniqueInWindowTests::test_basic
test_more.py::UniqueInWindowTests::test_basic
self =
def test_basic(self):
for iterable, n, expected in [
(range(9), 10, list(range(9))),
(range(20), 10, list(range(20))),
([1, 2, 3, 4, 4, 4], 1, [1, 2, 3, 4, 4, 4]),
([1, 2, 3, 4, 4, 4], 2, [1, 2, 3, 4]),
([1, 2, 3, 4, 4, 4], 3, [1, 2, 3, 4]),
([1, 2, 3, 4, 4, 4], 4, [1, 2, 3, 4]),
([1, 2, 3, 4, 4, 4], 5, [1, 2, 3, 4]),
(
[0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 2, 3, 4, 2],
2,
[0, 1, 0, 2, 3, 4, 2],
),
]:
with self.subTest(expected=expected):
> actual = list(mi.unique_in_window(iterable, n))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5041: TypeError
test_more.py::UniqueInWindowTests::test_invalid_n
test_more.py::UniqueInWindowTests::test_invalid_n
self =
def test_invalid_n(self):
with self.assertRaises(ValueError):
> list(mi.unique_in_window([], 0))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5023: TypeError
test_more.py::UniqueInWindowTests::test_key
test_more.py::UniqueInWindowTests::test_key
self =
def test_key(self):
iterable = [0, 1, 3, 4, 5, 6, 7, 8, 9]
n = 3
key = lambda x: x // 3
> actual = list(mi.unique_in_window(iterable, n, key=key))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5048: TypeError
test_more.py::StrictlyNTests::test_basic
test_more.py::StrictlyNTests::test_basic
self =
def test_basic(self):
iterable = ['a', 'b', 'c', 'd']
n = 4
> actual = list(mi.strictly_n(iter(iterable), n))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5057: TypeError
test_more.py::StrictlyNTests::test_too_long_custom
test_more.py::StrictlyNTests::test_too_long_custom
self =
def test_too_long_custom(self):
import logging
iterable = ['a', 'b', 'c', 'd']
n = 2
too_long = lambda item_count: logging.warning(
'Picked the first %s items', n
)
with self.assertLogs(level='WARNING') as cm:
> actual = list(mi.strictly_n(iter(iterable), n, too_long=too_long))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5108: TypeError
test_more.py::StrictlyNTests::test_too_long_default
test_more.py::StrictlyNTests::test_too_long_default
self =
def test_too_long_default(self):
iterable = ['a', 'b', 'c', 'd']
n = 3
with self.assertRaises(ValueError) as cm:
> list(mi.strictly_n(iter(iterable), n))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5075: TypeError
test_more.py::StrictlyNTests::test_too_short_custom
test_more.py::StrictlyNTests::test_too_short_custom
self =
def test_too_short_custom(self):
call_count = 0
def too_short(item_count):
nonlocal call_count
call_count += 1
iterable = ['a', 'b', 'c', 'd']
n = 6
actual = []
> for item in mi.strictly_n(iter(iterable), n, too_short=too_short):
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5092: TypeError
test_more.py::StrictlyNTests::test_too_short_default
test_more.py::StrictlyNTests::test_too_short_default
self =
def test_too_short_default(self):
iterable = ['a', 'b', 'c', 'd']
n = 5
with self.assertRaises(ValueError) as exc:
> list(mi.strictly_n(iter(iterable), n))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5065: TypeError
test_more.py::DuplicatesEverSeenTests::test_basic
test_more.py::DuplicatesEverSeenTests::test_basic
self =
def test_basic(self):
for iterable, expected in [
([], []),
([1, 2, 3], []),
([1, 1], [1]),
([1, 2, 1, 2], [1, 2]),
([1, 2, 3, '1'], []),
]:
with self.subTest(args=(iterable,)):
self.assertEqual(
> list(mi.duplicates_everseen(iterable)), expected
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5125: TypeError
test_more.py::DuplicatesEverSeenTests::test_key_hashable
test_more.py::DuplicatesEverSeenTests::test_key_hashable
self =
def test_key_hashable(self):
iterable = 'HEheHEhe'
> self.assertEqual(list(mi.duplicates_everseen(iterable)), list('HEhe'))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5149: TypeError
test_more.py::DuplicatesEverSeenTests::test_key_non_hashable
test_more.py::DuplicatesEverSeenTests::test_key_non_hashable
self =
def test_key_non_hashable(self):
iterable = [[1, 2], [3, 0], [5, -2], [5, 6]]
self.assertEqual(
> list(mi.duplicates_everseen(iterable, lambda x: x)), []
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5158: TypeError
test_more.py::DuplicatesEverSeenTests::test_key_partially_hashable
test_more.py::DuplicatesEverSeenTests::test_key_partially_hashable
self =
def test_key_partially_hashable(self):
iterable = [[1, 2], (1, 2), [1, 2], [5, 6]]
self.assertEqual(
> list(mi.duplicates_everseen(iterable, lambda x: x)), [[1, 2]]
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5167: TypeError
test_more.py::DuplicatesEverSeenTests::test_non_hashable
test_more.py::DuplicatesEverSeenTests::test_non_hashable
self =
def test_non_hashable(self):
> self.assertEqual(list(mi.duplicates_everseen([[1, 2], [3, 4]])), [])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5129: TypeError
test_more.py::DuplicatesEverSeenTests::test_partially_hashable
test_more.py::DuplicatesEverSeenTests::test_partially_hashable
self =
def test_partially_hashable(self):
self.assertEqual(
> list(mi.duplicates_everseen([[1, 2], [3, 4], (5, 6)])), []
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5136: TypeError
test_more.py::DuplicatesJustSeenTests::test_basic
test_more.py::DuplicatesJustSeenTests::test_basic
self =
def test_basic(self):
for iterable, expected in [
([], []),
([1, 2, 3, 3, 2, 2], [3, 2]),
([1, 1], [1]),
([1, 2, 1, 2], []),
([1, 2, 3, '1'], []),
]:
with self.subTest(args=(iterable,)):
self.assertEqual(
> list(mi.duplicates_justseen(iterable)), expected
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5185: TypeError
test_more.py::DuplicatesJustSeenTests::test_key_hashable
test_more.py::DuplicatesJustSeenTests::test_key_hashable
self =
def test_key_hashable(self):
iterable = 'HEheHHHhEheeEe'
> self.assertEqual(list(mi.duplicates_justseen(iterable)), list('HHe'))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5222: TypeError
test_more.py::DuplicatesJustSeenTests::test_key_non_hashable
test_more.py::DuplicatesJustSeenTests::test_key_non_hashable
self =
def test_key_non_hashable(self):
iterable = [[1, 2], [3, 0], [5, -2], [5, 6], [1, 2]]
self.assertEqual(
> list(mi.duplicates_justseen(iterable, lambda x: x)), []
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5231: TypeError
test_more.py::DuplicatesJustSeenTests::test_key_partially_hashable
test_more.py::DuplicatesJustSeenTests::test_key_partially_hashable
self =
def test_key_partially_hashable(self):
iterable = [[1, 2], (1, 2), [1, 2], [5, 6], [1, 2]]
self.assertEqual(
> list(mi.duplicates_justseen(iterable, lambda x: x)), []
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5240: TypeError
test_more.py::DuplicatesJustSeenTests::test_nested
test_more.py::DuplicatesJustSeenTests::test_nested
self =
def test_nested(self):
iterable = [[[1, 2], [1, 2]], [5, 6], [5, 6]]
> self.assertEqual(list(mi.duplicates_justseen(iterable)), [[5, 6]])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5248: TypeError
test_more.py::DuplicatesJustSeenTests::test_non_hashable
test_more.py::DuplicatesJustSeenTests::test_non_hashable
self =
def test_non_hashable(self):
> self.assertEqual(list(mi.duplicates_justseen([[1, 2], [3, 4]])), [])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5189: TypeError
test_more.py::DuplicatesJustSeenTests::test_partially_hashable
test_more.py::DuplicatesJustSeenTests::test_partially_hashable
self =
def test_partially_hashable(self):
self.assertEqual(
> list(mi.duplicates_justseen([[1, 2], [3, 4], (5, 6)])), []
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5201: TypeError
test_more.py::ClassifyUniqueTests::test_basic
test_more.py::ClassifyUniqueTests::test_basic
self =
def test_basic(self):
self.assertEqual(
> list(mi.classify_unique('mississippi')),
[
('m', True, True),
('i', True, True),
('s', True, True),
('s', False, False),
('i', True, False),
('s', True, False),
('s', False, False),
('i', True, False),
('p', True, True),
('p', False, False),
('i', True, False),
],
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5254: TypeError
test_more.py::ClassifyUniqueTests::test_key_hashable
test_more.py::ClassifyUniqueTests::test_key_hashable
self =
def test_key_hashable(self):
iterable = 'HEheHHHhEheeEe'
self.assertEqual(
> list(mi.classify_unique(iterable)),
[
('H', True, True),
('E', True, True),
('h', True, True),
('e', True, True),
('H', True, False),
('H', False, False),
('H', False, False),
('h', True, False),
('E', True, False),
('h', True, False),
('e', True, False),
('e', False, False),
('E', True, False),
('e', True, False),
],
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5301: TypeError
test_more.py::ClassifyUniqueTests::test_key_non_hashable
test_more.py::ClassifyUniqueTests::test_key_non_hashable
self =
def test_key_non_hashable(self):
iterable = [[1, 2], [3, 0], [5, -2], [5, 6], [1, 2]]
self.assertEqual(
> list(mi.classify_unique(iterable, lambda x: x)),
[
([1, 2], True, True),
([3, 0], True, True),
([5, -2], True, True),
([5, 6], True, True),
([1, 2], True, False),
],
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5342: TypeError
test_more.py::ClassifyUniqueTests::test_key_partially_hashable
test_more.py::ClassifyUniqueTests::test_key_partially_hashable
self =
def test_key_partially_hashable(self):
iterable = [[1, 2], (1, 2), [1, 2], [5, 6], [1, 2]]
self.assertEqual(
> list(mi.classify_unique(iterable, lambda x: x)),
[
([1, 2], True, True),
((1, 2), True, True),
([1, 2], True, False),
([5, 6], True, True),
([1, 2], True, False),
],
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5365: TypeError
test_more.py::ClassifyUniqueTests::test_non_hashable
test_more.py::ClassifyUniqueTests::test_non_hashable
self =
def test_non_hashable(self):
self.assertEqual(
> list(mi.classify_unique([[1, 2], [3, 4], [3, 4], [1, 2]])),
[
([1, 2], True, True),
([3, 4], True, True),
([3, 4], False, False),
([1, 2], True, False),
],
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5272: TypeError
test_more.py::ClassifyUniqueTests::test_partially_hashable
test_more.py::ClassifyUniqueTests::test_partially_hashable
self =
def test_partially_hashable(self):
self.assertEqual(
> list(
mi.classify_unique(
[[1, 2], [3, 4], (5, 6), (5, 6), (3, 4), [1, 2]]
)
),
[
([1, 2], True, True),
([3, 4], True, True),
((5, 6), True, True),
((5, 6), False, False),
((3, 4), True, True),
([1, 2], True, False),
],
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5283: TypeError
test_more.py::ClassifyUniqueTests::test_vs_duplicates_everseen
test_more.py::ClassifyUniqueTests::test_vs_duplicates_everseen
self =
def test_vs_duplicates_everseen(self):
input = [1, 2, 1, 2]
> output = [e for e, j, u in mi.classify_unique(input) if not u]
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5411: TypeError
test_more.py::ClassifyUniqueTests::test_vs_duplicates_everseen_key
test_more.py::ClassifyUniqueTests::test_vs_duplicates_everseen_key
self =
def test_vs_duplicates_everseen_key(self):
input = 'HEheHEhe'
output = [
> e for e, j, u in mi.classify_unique(input, str.lower) if not u
]
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5418: TypeError
test_more.py::ClassifyUniqueTests::test_vs_duplicates_justseen
test_more.py::ClassifyUniqueTests::test_vs_duplicates_justseen
self =
def test_vs_duplicates_justseen(self):
input = [1, 2, 3, 3, 2, 2]
> output = [e for e, j, u in mi.classify_unique(input) if not j]
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5427: TypeError
test_more.py::ClassifyUniqueTests::test_vs_duplicates_justseen_key
test_more.py::ClassifyUniqueTests::test_vs_duplicates_justseen_key
self =
def test_vs_duplicates_justseen_key(self):
input = 'HEheHHHhEheeEe'
output = [
> e for e, j, u in mi.classify_unique(input, str.lower) if not j
]
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5434: TypeError
test_more.py::ClassifyUniqueTests::test_vs_unique_everseen
test_more.py::ClassifyUniqueTests::test_vs_unique_everseen
self =
def test_vs_unique_everseen(self):
input = 'AAAABBBBCCDAABBB'
> output = [e for e, j, u in mi.classify_unique(input) if u]
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5387: TypeError
test_more.py::ClassifyUniqueTests::test_vs_unique_everseen_key
test_more.py::ClassifyUniqueTests::test_vs_unique_everseen_key
self =
def test_vs_unique_everseen_key(self):
input = 'aAbACCc'
> output = [e for e, j, u in mi.classify_unique(input, str.lower) if u]
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5393: TypeError
test_more.py::ClassifyUniqueTests::test_vs_unique_justseen
test_more.py::ClassifyUniqueTests::test_vs_unique_justseen
self =
def test_vs_unique_justseen(self):
input = 'AAAABBBCCDABB'
> output = [e for e, j, u in mi.classify_unique(input) if j]
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5399: TypeError
test_more.py::ClassifyUniqueTests::test_vs_unique_justseen_key
test_more.py::ClassifyUniqueTests::test_vs_unique_justseen_key
self =
def test_vs_unique_justseen_key(self):
input = 'AABCcAD'
> output = [e for e, j, u in mi.classify_unique(input, str.lower) if j]
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5405: TypeError
test_more.py::LongestCommonPrefixTests::test_basic
test_more.py::LongestCommonPrefixTests::test_basic
self =
def test_basic(self):
iterables = [[1, 2], [1, 2, 3], [1, 2, 4]]
> self.assertEqual(list(mi.longest_common_prefix(iterables)), [1, 2])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5445: TypeError
test_more.py::LongestCommonPrefixTests::test_contains_infinite_iterables
test_more.py::LongestCommonPrefixTests::test_contains_infinite_iterables
self =
def test_contains_infinite_iterables(self):
iterables = [[0, 1, 2], count()]
> self.assertEqual(list(mi.longest_common_prefix(iterables)), [0, 1, 2])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5486: TypeError
test_more.py::LongestCommonPrefixTests::test_empty_iterables_only
test_more.py::LongestCommonPrefixTests::test_empty_iterables_only
self =
def test_empty_iterables_only(self):
iterables = [[], [], []]
> self.assertEqual(list(mi.longest_common_prefix(iterables)), [])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5457: TypeError
test_more.py::LongestCommonPrefixTests::test_includes_empty_iterables
test_more.py::LongestCommonPrefixTests::test_includes_empty_iterables
self =
def test_includes_empty_iterables(self):
iterables = [[1, 2], [1, 2, 3], [1, 2, 4], []]
> self.assertEqual(list(mi.longest_common_prefix(iterables)), [])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5461: TypeError
test_more.py::LongestCommonPrefixTests::test_infinite_iterables
test_more.py::LongestCommonPrefixTests::test_infinite_iterables
self =
def test_infinite_iterables(self):
prefix = mi.longest_common_prefix([count(), count()])
> self.assertEqual(next(prefix), 0)
E TypeError: 'NoneType' object is not an iterator
tests/test_more.py:5480: TypeError
test_more.py::LongestCommonPrefixTests::test_iterators
test_more.py::LongestCommonPrefixTests::test_iterators
self =
def test_iterators(self):
iterables = iter([iter([1, 2]), iter([1, 2, 3]), iter([1, 2, 4])])
> self.assertEqual(list(mi.longest_common_prefix(iterables)), [1, 2])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5449: TypeError
test_more.py::LongestCommonPrefixTests::test_no_iterables
test_more.py::LongestCommonPrefixTests::test_no_iterables
self =
def test_no_iterables(self):
iterables = []
> self.assertEqual(list(mi.longest_common_prefix(iterables)), [])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5453: TypeError
test_more.py::LongestCommonPrefixTests::test_non_hashable
test_more.py::LongestCommonPrefixTests::test_non_hashable
self =
def test_non_hashable(self):
# See https://github.com/more-itertools/more-itertools/issues/603
iterables = [[[1], [2]], [[1], [2], [3]], [[1], [2], [4]]]
> self.assertEqual(list(mi.longest_common_prefix(iterables)), [[1], [2]])
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5466: TypeError
test_more.py::LongestCommonPrefixTests::test_prefix_contains_elements_of_the_first_iterable
test_more.py::LongestCommonPrefixTests::test_prefix_contains_elements_of_the_first_iterable
self =
def test_prefix_contains_elements_of_the_first_iterable(self):
iterables = [[[1], [2]], [[1], [2], [3]], [[1], [2], [4]]]
> prefix = list(mi.longest_common_prefix(iterables))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5470: TypeError
test_more.py::IequalsTests::test_basic
test_more.py::IequalsTests::test_basic
self =
def test_basic(self):
> self.assertTrue(mi.iequals("abc", iter("abc")))
E AssertionError: None is not true
tests/test_more.py:5491: AssertionError
test_more.py::IequalsTests::test_empty_iterables
test_more.py::IequalsTests::test_empty_iterables
self =
def test_empty_iterables(self):
> self.assertTrue(mi.iequals([], ""))
E AssertionError: None is not true
tests/test_more.py:5514: AssertionError
test_more.py::IequalsTests::test_more_than_two_iterable
test_more.py::IequalsTests::test_more_than_two_iterable
self =
def test_more_than_two_iterable(self):
> self.assertTrue(mi.iequals("abc", iter("abc"), ['a', 'b', 'c']))
E AssertionError: None is not true
tests/test_more.py:5502: AssertionError
test_more.py::IequalsTests::test_no_iterables
test_more.py::IequalsTests::test_no_iterables
self =
def test_no_iterables(self):
> self.assertTrue(mi.iequals())
E AssertionError: None is not true
tests/test_more.py:5496: AssertionError
test_more.py::IequalsTests::test_one_iterable
test_more.py::IequalsTests::test_one_iterable
self =
def test_one_iterable(self):
> self.assertTrue(mi.iequals("abc"))
E AssertionError: None is not true
tests/test_more.py:5499: AssertionError
test_more.py::ConstrainedBatchesTests::test_bad_max
test_more.py::ConstrainedBatchesTests::test_bad_max
self =
def test_bad_max(self):
with self.assertRaises(ValueError):
> list(mi.constrained_batches([], 0))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5623: TypeError
test_more.py::ConstrainedBatchesTests::test_basic
test_more.py::ConstrainedBatchesTests::test_basic
self =
def test_basic(self):
zen = [
'Beautiful is better than ugly',
'Explicit is better than implicit',
'Simple is better than complex',
'Complex is better than complicated',
'Flat is better than nested',
'Sparse is better than dense',
'Readability counts',
]
for size, expected in (
(
34,
[
(zen[0],),
(zen[1],),
(zen[2],),
(zen[3],),
(zen[4],),
(zen[5],),
(zen[6],),
],
),
(
61,
[
(zen[0], zen[1]),
(zen[2],),
(zen[3], zen[4]),
(zen[5], zen[6]),
],
),
(
90,
[
(zen[0], zen[1], zen[2]),
(zen[3], zen[4], zen[5]),
(zen[6],),
],
),
(
124,
[(zen[0], zen[1], zen[2], zen[3]), (zen[4], zen[5], zen[6])],
),
(
150,
[(zen[0], zen[1], zen[2], zen[3], zen[4]), (zen[5], zen[6])],
),
(
177,
[(zen[0], zen[1], zen[2], zen[3], zen[4], zen[5]), (zen[6],)],
),
):
with self.subTest(size=size):
> actual = list(mi.constrained_batches(iter(zen), size))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5580: TypeError
test_more.py::ConstrainedBatchesTests::test_get_len
test_more.py::ConstrainedBatchesTests::test_get_len
self =
def test_get_len(self):
class Record(tuple):
def total_size(self):
return sum(len(x) for x in self)
record_3 = Record(('1', '23'))
record_5 = Record(('1234', '1'))
record_10 = Record(('1', '12345678', '1'))
record_2 = Record(('1', '1'))
iterable = [record_3, record_5, record_10, record_2]
self.assertEqual(
> list(
mi.constrained_batches(
iterable, 10, get_len=lambda x: x.total_size()
)
),
[(record_3, record_5), (record_10,), (record_2,)],
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5613: TypeError
test_more.py::ConstrainedBatchesTests::test_max_count
test_more.py::ConstrainedBatchesTests::test_max_count
self =
def test_max_count(self):
iterable = ['1', '1', '12345678', '12345', '12345']
max_size = 10
max_count = 2
> actual = list(mi.constrained_batches(iterable, max_size, max_count))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5587: TypeError
test_more.py::ConstrainedBatchesTests::test_strict
test_more.py::ConstrainedBatchesTests::test_strict
self =
def test_strict(self):
iterable = ['1', '123456789', '1']
size = 8
with self.assertRaises(ValueError):
> list(mi.constrained_batches(iterable, size))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5595: TypeError
test_more.py::GrayProductTests::test_basic
test_more.py::GrayProductTests::test_basic
self =
def test_basic(self):
self.assertEqual(
> tuple(mi.gray_product(('a', 'b', 'c'), range(1, 3))),
(("a", 1), ("b", 1), ("c", 1), ("c", 2), ("b", 2), ("a", 2)),
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5629: TypeError
test_more.py::GrayProductTests::test_errors
test_more.py::GrayProductTests::test_errors
self =
def test_errors(self):
with self.assertRaises(ValueError):
> list(mi.gray_product((1, 2), ()))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5659: TypeError
test_more.py::GrayProductTests::test_vs_product
test_more.py::GrayProductTests::test_vs_product
self =
def test_vs_product(self):
iters = (
("a", "b"),
range(3, 6),
[None, None],
{"i", "j", "k", "l"},
"XYZ",
)
self.assertEqual(
> sorted(product(*iters)), sorted(mi.gray_product(*iters))
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5672: TypeError
test_more.py::PartialProductTests::test_basic
test_more.py::PartialProductTests::test_basic
self =
def test_basic(self):
ones = [1, 2, 3]
tens = [10, 20, 30, 40, 50]
hundreds = [100, 200]
expected = [
(1, 10, 100),
(2, 10, 100),
(3, 10, 100),
(3, 20, 100),
(3, 30, 100),
(3, 40, 100),
(3, 50, 100),
(3, 50, 200),
]
> actual = list(mi.partial_product(ones, tens, hundreds))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5729: TypeError
test_more.py::PartialProductTests::test_empty_iterable
test_more.py::PartialProductTests::test_empty_iterable
self =
def test_empty_iterable(self):
> self.assertEqual(tuple(mi.partial_product('AB', '', 'CD')), ())
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5681: TypeError
test_more.py::PartialProductTests::test_no_iterables
test_more.py::PartialProductTests::test_no_iterables
self =
def test_no_iterables(self):
> self.assertEqual(tuple(mi.partial_product()), ((),))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5678: TypeError
test_more.py::PartialProductTests::test_one_iterable
test_more.py::PartialProductTests::test_one_iterable
self =
def test_one_iterable(self):
# a single iterable should pass through
self.assertEqual(
> tuple(mi.partial_product('ABCD')),
(
('A',),
('B',),
('C',),
('D',),
),
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5686: TypeError
test_more.py::PartialProductTests::test_two_iterables
test_more.py::PartialProductTests::test_two_iterables
self =
def test_two_iterables(self):
self.assertEqual(
> list(mi.partial_product('ABCD', [1])),
[('A', 1), ('B', 1), ('C', 1), ('D', 1)],
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5697: TypeError
test_more.py::PartialProductTests::test_uneven_length_iterables
test_more.py::PartialProductTests::test_uneven_length_iterables
self =
def test_uneven_length_iterables(self):
# this is also the docstring example
expected = [
('A', 'C', 'D'),
('B', 'C', 'D'),
('B', 'C', 'E'),
('B', 'C', 'F'),
]
> self.assertEqual(list(mi.partial_product('AB', 'C', 'DEF')), expected)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5741: TypeError
test_more.py::IterateTests::test_basic
test_more.py::IterateTests::test_basic
self =
def test_basic(self) -> None:
> result = list(islice(mi.iterate(lambda x: 2 * x, start=1), 10))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5746: TypeError
test_more.py::IterateTests::test_func_controls_iteration_stop
test_more.py::IterateTests::test_func_controls_iteration_stop
self =
def test_func_controls_iteration_stop(self) -> None:
def func(num):
if num > 100:
raise StopIteration
return num * 2
> result = list(islice(mi.iterate(func, start=1), 10))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5756: TypeError
test_more.py::TakewhileInclusiveTests::test_basic
test_more.py::TakewhileInclusiveTests::test_basic
self =
def test_basic(self) -> None:
> result = list(mi.takewhile_inclusive(lambda x: x < 5, [1, 4, 6, 4, 1]))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5763: TypeError
test_more.py::TakewhileInclusiveTests::test_collatz_sequence
test_more.py::TakewhileInclusiveTests::test_collatz_sequence
self =
def test_collatz_sequence(self) -> None:
is_even = lambda n: n % 2 == 0
start = 11
> result = list(
mi.takewhile_inclusive(
lambda n: n != 1,
mi.iterate(
lambda n: n // 2 if is_even(n) else 3 * n + 1, start
),
)
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5775: TypeError
test_more.py::TakewhileInclusiveTests::test_empty_iterator
test_more.py::TakewhileInclusiveTests::test_empty_iterator
self =
def test_empty_iterator(self) -> None:
> result = list(mi.takewhile_inclusive(lambda x: True, []))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5768: TypeError
test_more.py::OuterProductTests::test_basic
test_more.py::OuterProductTests::test_basic
self =
def test_basic(self) -> None:
greetings = ['Hello', 'Goodbye']
names = ['Alice', 'Bob', 'Carol']
greet = lambda greeting, name: f'{greeting}, {name}!'
> result = list(mi.outer_product(greet, greetings, names))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5792: TypeError
test_more.py::IterSuppressTests::test_early_suppression
test_more.py::IterSuppressTests::test_early_suppression
self =
def test_early_suppression(self):
iterator = self.Producer(ValueError, die_early=True)
> actual = list(mi.iter_suppress(iterator, RuntimeError, ValueError))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5839: TypeError
test_more.py::IterSuppressTests::test_no_error
test_more.py::IterSuppressTests::test_no_error
self =
def test_no_error(self):
iterator = range(5)
> actual = list(mi.iter_suppress(iterator, RuntimeError))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5822: TypeError
test_more.py::IterSuppressTests::test_raises_error
test_more.py::IterSuppressTests::test_raises_error
self =
def test_raises_error(self):
iterator = self.Producer(ValueError)
with self.assertRaises(ValueError):
> list(mi.iter_suppress(iterator, RuntimeError))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5829: TypeError
test_more.py::IterSuppressTests::test_suppression
test_more.py::IterSuppressTests::test_suppression
self =
def test_suppression(self):
iterator = self.Producer(ValueError)
> actual = list(mi.iter_suppress(iterator, RuntimeError, ValueError))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5833: TypeError
test_more.py::FilterMapTests::test_filter
test_more.py::FilterMapTests::test_filter
self =
def test_filter(self):
> actual = list(mi.filter_map(lambda _: None, [1, 2, 3]))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5851: TypeError
test_more.py::FilterMapTests::test_filter_map
test_more.py::FilterMapTests::test_filter_map
self =
def test_filter_map(self):
> actual = list(
mi.filter_map(
lambda x: int(x) if x.isnumeric() else None,
['1', 'a', '2', 'b', '3'],
)
)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5861: TypeError
test_more.py::FilterMapTests::test_map
test_more.py::FilterMapTests::test_map
self =
def test_map(self):
> actual = list(mi.filter_map(lambda x: x + 1, [1, 2, 3]))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5856: TypeError
test_more.py::FilterMapTests::test_no_iterables
test_more.py::FilterMapTests::test_no_iterables
self =
def test_no_iterables(self):
> actual = list(mi.filter_map(lambda _: None, []))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5846: TypeError
test_more.py::PowersetOfSetsTests::test_hash_count
test_more.py::PowersetOfSetsTests::test_hash_count
self =
def test_hash_count(self):
hash_count = 0
class Str(str):
def __hash__(true_self):
nonlocal hash_count
hash_count += 1
return super.__hash__(true_self)
iterable = map(Str, 'ABBBCDD')
> self.assertEqual(len(list(mi.powerset_of_sets(iterable))), 128)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5888: TypeError
test_more.py::PowersetOfSetsTests::test_simple
test_more.py::PowersetOfSetsTests::test_simple
self =
def test_simple(self):
iterable = [0, 1, 2]
> actual = list(mi.powerset_of_sets(iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5874: TypeError
test_more.py::JoinMappingTests::test_basic
test_more.py::JoinMappingTests::test_basic
self =
def test_basic(self):
salary_map = {'e1': 12, 'e2': 23, 'e3': 34}
dept_map = {'e1': 'eng', 'e2': 'sales', 'e3': 'eng'}
service_map = {'e1': 5, 'e2': 9, 'e3': 2}
field_to_map = {
'salary': salary_map,
'dept': dept_map,
'service': service_map,
}
expected = {
'e1': {'salary': 12, 'dept': 'eng', 'service': 5},
'e2': {'salary': 23, 'dept': 'sales', 'service': 9},
'e3': {'salary': 34, 'dept': 'eng', 'service': 2},
}
> self.assertEqual(dict(mi.join_mappings(**field_to_map)), expected)
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5907: TypeError
test_more.py::JoinMappingTests::test_empty
test_more.py::JoinMappingTests::test_empty
self =
def test_empty(self):
> self.assertEqual(dict(mi.join_mappings()), {})
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5910: TypeError
test_more.py::DiscreteFourierTransformTests::test_basic
self =
def test_basic(self):
# Example calculation from:
# https://en.wikipedia.org/wiki/Discrete_Fourier_transform#Example
xarr = [1, 2 - 1j, -1j, -1 + 2j]
Xarr = [2, -2 - 2j, -2j, 4 + 4j]
> self.assertTrue(all(map(cmath.isclose, mi.dft(xarr), Xarr)))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5919: TypeError
test_more.py::DiscreteFourierTransformTests::test_roundtrip
self =
def test_roundtrip(self):
for _ in range(1_000):
N = randrange(35)
xarr = [complex(random(), random()) for i in range(N)]
> Xarr = list(mi.dft(xarr))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5926: TypeError
test_more.py::DoubleStarMapTests::test_adding
test_more.py::DoubleStarMapTests::test_adding
self =
def test_adding(self):
iterable = [{'a': 1, 'b': 2}, {'a': 3, 'b': 4}]
> actual = list(mi.doublestarmap(lambda a, b: a + b, iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5945: TypeError
test_more.py::DoubleStarMapTests::test_construction
test_more.py::DoubleStarMapTests::test_construction
self =
def test_construction(self):
iterable = [{'price': 1.23}, {'price': 42}, {'price': 0.1}]
> actual = list(mi.doublestarmap('{price:.2f}'.format, iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5933: TypeError
test_more.py::DoubleStarMapTests::test_empty
test_more.py::DoubleStarMapTests::test_empty
self =
def test_empty(self):
> actual = list(mi.doublestarmap(lambda x: x, []))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5970: TypeError
test_more.py::DoubleStarMapTests::test_identity
test_more.py::DoubleStarMapTests::test_identity
self =
def test_identity(self):
iterable = [{'x': 1}, {'x': 2}, {'x': 3}]
> actual = list(mi.doublestarmap(lambda x: x, iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_more.py:5939: TypeError
test_recipes.py::TabulateTests::test_count
test_recipes.py::TabulateTests::test_count
self =
def test_count(self):
"""Ensure tabulate accepts specific count"""
t = mi.tabulate(lambda x: 2 * x, -1)
> f = (next(t), next(t), next(t))
E TypeError: 'NoneType' object is not an iterator
tests/test_recipes.py:58: TypeError
test_recipes.py::TabulateTests::test_simple_tabulate
test_recipes.py::TabulateTests::test_simple_tabulate
self =
def test_simple_tabulate(self):
"""Test the happy path"""
t = mi.tabulate(lambda x: x)
> f = tuple([next(t) for _ in range(3)])
E TypeError: 'NoneType' object is not an iterator
tests/test_recipes.py:52: TypeError
test_recipes.py::TailTests::test_iterator_equal
test_recipes.py::TailTests::test_iterator_equal
self =
def test_iterator_equal(self):
"""Length of iterator is equal to the requested tail"""
> self.assertEqual(list(mi.tail(7, iter('ABCDEFG'))), list('ABCDEFG'))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:71: TypeError
test_recipes.py::TailTests::test_iterator_greater
test_recipes.py::TailTests::test_iterator_greater
self =
def test_iterator_greater(self):
"""Length of iterator is greater than requested tail"""
> self.assertEqual(list(mi.tail(3, iter('ABCDEFG'))), list('EFG'))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:67: TypeError
test_recipes.py::TailTests::test_iterator_less
test_recipes.py::TailTests::test_iterator_less
self =
def test_iterator_less(self):
"""Length of iterator is less than requested tail"""
> self.assertEqual(list(mi.tail(8, iter('ABCDEFG'))), list('ABCDEFG'))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:75: TypeError
test_recipes.py::TailTests::test_sized_equal
test_recipes.py::TailTests::test_sized_equal
self =
def test_sized_equal(self):
"""Length of sized iterable is less than requested tail"""
> self.assertEqual(list(mi.tail(7, 'ABCDEFG')), list('ABCDEFG'))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:83: TypeError
test_recipes.py::TailTests::test_sized_greater
test_recipes.py::TailTests::test_sized_greater
self =
def test_sized_greater(self):
"""Length of sized iterable is greater than requested tail"""
> self.assertEqual(list(mi.tail(3, 'ABCDEFG')), list('EFG'))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:79: TypeError
test_recipes.py::TailTests::test_sized_less
test_recipes.py::TailTests::test_sized_less
self =
def test_sized_less(self):
"""Length of sized iterable is less than requested tail"""
> self.assertEqual(list(mi.tail(8, 'ABCDEFG')), list('ABCDEFG'))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:87: TypeError
test_recipes.py::ConsumeTests::test_negative_consume
test_recipes.py::ConsumeTests::test_negative_consume
self =
def test_negative_consume(self):
"""Check that negative consumption throws an error"""
r = (x for x in range(10))
> self.assertRaises(ValueError, lambda: mi.consume(r, -1))
E AssertionError: ValueError not raised by
tests/test_recipes.py:108: AssertionError
test_recipes.py::ConsumeTests::test_sanity
test_recipes.py::ConsumeTests::test_sanity
self =
def test_sanity(self):
"""Test basic functionality"""
r = (x for x in range(10))
mi.consume(r, 3)
> self.assertEqual(3, next(r))
E AssertionError: 3 != 0
tests/test_recipes.py:97: AssertionError
test_recipes.py::ConsumeTests::test_total_consume
test_recipes.py::ConsumeTests::test_total_consume
self =
def test_total_consume(self):
"""Check that iterator is totally consumed by default"""
r = (x for x in range(10))
mi.consume(r)
> self.assertRaises(StopIteration, lambda: next(r))
E AssertionError: StopIteration not raised by
tests/test_recipes.py:114: AssertionError
test_recipes.py::NthTests::test_basic
test_recipes.py::NthTests::test_basic
self =
def test_basic(self):
"""Make sure the nth item is returned"""
l = range(10)
for i, v in enumerate(l):
> self.assertEqual(mi.nth(l, i), v)
E AssertionError: None != 0
tests/test_recipes.py:124: AssertionError
test_recipes.py::NthTests::test_default
test_recipes.py::NthTests::test_default
self =
def test_default(self):
"""Ensure a default value is returned when nth item not found"""
l = range(3)
> self.assertEqual(mi.nth(l, 100, "zebra"), "zebra")
E AssertionError: None != 'zebra'
tests/test_recipes.py:129: AssertionError
test_recipes.py::NthTests::test_negative_item_raises
test_recipes.py::NthTests::test_negative_item_raises
self =
def test_negative_item_raises(self):
"""Ensure asking for a negative item raises an exception"""
> self.assertRaises(ValueError, lambda: mi.nth(range(10), -3))
E AssertionError: ValueError not raised by
tests/test_recipes.py:133: AssertionError
test_recipes.py::AllEqualTests::test_empty
test_recipes.py::AllEqualTests::test_empty
self =
def test_empty(self):
> self.assertTrue(mi.all_equal(''))
E AssertionError: None is not true
tests/test_recipes.py:150: AssertionError
test_recipes.py::AllEqualTests::test_key
test_recipes.py::AllEqualTests::test_key
self =
def test_key(self):
> self.assertTrue(mi.all_equal('4٤໔4৪', key=int))
E AssertionError: None is not true
tests/test_recipes.py:158: AssertionError
test_recipes.py::AllEqualTests::test_one
test_recipes.py::AllEqualTests::test_one
self =
def test_one(self):
> self.assertTrue(mi.all_equal('0'))
E AssertionError: None is not true
tests/test_recipes.py:154: AssertionError
test_recipes.py::AllEqualTests::test_tricky
test_recipes.py::AllEqualTests::test_tricky
self =
def test_tricky(self):
items = [1, complex(1, 0), 1.0]
> self.assertTrue(mi.all_equal(items))
E AssertionError: None is not true
tests/test_recipes.py:147: AssertionError
test_recipes.py::AllEqualTests::test_true
test_recipes.py::AllEqualTests::test_true
self =
def test_true(self):
> self.assertTrue(mi.all_equal('aaaaaa'))
E AssertionError: None is not true
tests/test_recipes.py:138: AssertionError
test_recipes.py::QuantifyTests::test_custom_predicate
test_recipes.py::QuantifyTests::test_custom_predicate
self =
def test_custom_predicate(self):
"""Ensure non-default predicates return as expected"""
q = range(10)
> self.assertEqual(mi.quantify(q, lambda x: x % 2 == 0), 5)
E AssertionError: None != 5
tests/test_recipes.py:173: AssertionError
test_recipes.py::QuantifyTests::test_happy_path
test_recipes.py::QuantifyTests::test_happy_path
self =
def test_happy_path(self):
"""Make sure True count is returned"""
q = [True, False, True]
> self.assertEqual(mi.quantify(q), 2)
E AssertionError: None != 2
tests/test_recipes.py:168: AssertionError
test_recipes.py::PadnoneTests::test_basic
test_recipes.py::PadnoneTests::test_basic
self =
def test_basic(self):
iterable = range(2)
for func in (mi.pad_none, mi.padnone):
with self.subTest(func=func):
p = func(iterable)
self.assertEqual(
> [0, 1, None, None], [next(p) for _ in range(4)]
)
E TypeError: 'NoneType' object is not an iterator
tests/test_recipes.py:183: TypeError
test_recipes.py::NcyclesTests::test_happy_path
test_recipes.py::NcyclesTests::test_happy_path
self =
def test_happy_path(self):
"""cycle a sequence three times"""
r = ["a", "b", "c"]
n = mi.ncycles(r, 3)
self.assertEqual(
> ["a", "b", "c", "a", "b", "c", "a", "b", "c"], list(n)
)
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:195: TypeError
test_recipes.py::NcyclesTests::test_null_case
test_recipes.py::NcyclesTests::test_null_case
self =
def test_null_case(self):
"""asking for 0 cycles should return an empty iterator"""
n = mi.ncycles(range(100), 0)
> self.assertRaises(StopIteration, lambda: next(n))
tests/test_recipes.py:201:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> self.assertRaises(StopIteration, lambda: next(n))
E TypeError: 'NoneType' object is not an iterator
tests/test_recipes.py:201: TypeError
test_recipes.py::NcyclesTests::test_pathological_case
test_recipes.py::NcyclesTests::test_pathological_case
self =
def test_pathological_case(self):
"""asking for negative cycles should return an empty iterator"""
n = mi.ncycles(range(100), -10)
> self.assertRaises(StopIteration, lambda: next(n))
tests/test_recipes.py:206:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> self.assertRaises(StopIteration, lambda: next(n))
E TypeError: 'NoneType' object is not an iterator
tests/test_recipes.py:206: TypeError
test_recipes.py::DotproductTests::test_happy_path
test_recipes.py::DotproductTests::test_happy_path
self =
def test_happy_path(self):
"""simple dotproduct example"""
> self.assertEqual(400, mi.dotproduct([10, 10], [20, 20]))
E AssertionError: 400 != None
tests/test_recipes.py:214: AssertionError
test_recipes.py::FlattenTests::test_basic_usage
test_recipes.py::FlattenTests::test_basic_usage
self =
def test_basic_usage(self):
"""ensure list of lists is flattened one level"""
f = [[0, 1, 2], [3, 4, 5]]
> self.assertEqual(list(range(6)), list(mi.flatten(f)))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:223: TypeError
test_recipes.py::FlattenTests::test_single_level
test_recipes.py::FlattenTests::test_single_level
self =
def test_single_level(self):
"""ensure list of lists is flattened only one level"""
f = [[0, [1, 2]], [[3, 4], 5]]
> self.assertEqual([0, [1, 2], [3, 4], 5], list(mi.flatten(f)))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:228: TypeError
test_recipes.py::RepeatfuncTests::test_added_arguments
test_recipes.py::RepeatfuncTests::test_added_arguments
self =
def test_added_arguments(self):
"""ensure arguments are applied to the function"""
r = mi.repeatfunc(lambda x: x, 2, 3)
> self.assertEqual([3, 3], list(r))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:247: TypeError
test_recipes.py::RepeatfuncTests::test_finite_repeat
test_recipes.py::RepeatfuncTests::test_finite_repeat
self =
def test_finite_repeat(self):
"""ensure limited repeat when times is provided"""
r = mi.repeatfunc(lambda: 5, times=5)
> self.assertEqual([5, 5, 5, 5, 5], list(r))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:242: TypeError
test_recipes.py::RepeatfuncTests::test_null_times
test_recipes.py::RepeatfuncTests::test_null_times
self =
def test_null_times(self):
"""repeat 0 should return an empty iterator"""
r = mi.repeatfunc(range, 0, 3)
> self.assertRaises(StopIteration, lambda: next(r))
tests/test_recipes.py:252:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> self.assertRaises(StopIteration, lambda: next(r))
E TypeError: 'NoneType' object is not an iterator
tests/test_recipes.py:252: TypeError
test_recipes.py::RepeatfuncTests::test_simple_repeat
test_recipes.py::RepeatfuncTests::test_simple_repeat
self =
def test_simple_repeat(self):
"""test simple repeated functions"""
r = mi.repeatfunc(lambda: 5)
> self.assertEqual([5, 5, 5, 5, 5], [next(r) for _ in range(5)])
E TypeError: 'NoneType' object is not an iterator
tests/test_recipes.py:237: TypeError
test_recipes.py::GrouperTests::test_basic
test_recipes.py::GrouperTests::test_basic
self =
def test_basic(self):
seq = 'ABCDEF'
for n, expected in [
(3, [('A', 'B', 'C'), ('D', 'E', 'F')]),
(4, [('A', 'B', 'C', 'D'), ('E', 'F', None, None)]),
(5, [('A', 'B', 'C', 'D', 'E'), ('F', None, None, None, None)]),
(6, [('A', 'B', 'C', 'D', 'E', 'F')]),
(7, [('A', 'B', 'C', 'D', 'E', 'F', None)]),
]:
with self.subTest(n=n):
> actual = list(mi.grouper(iter(seq), n))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:286: TypeError
test_recipes.py::GrouperTests::test_fill
test_recipes.py::GrouperTests::test_fill
self =
def test_fill(self):
seq = 'ABCDEF'
fillvalue = 'x'
for n, expected in [
(1, ['A', 'B', 'C', 'D', 'E', 'F']),
(2, ['AB', 'CD', 'EF']),
(3, ['ABC', 'DEF']),
(4, ['ABCD', 'EFxx']),
(5, ['ABCDE', 'Fxxxx']),
(6, ['ABCDEF']),
(7, ['ABCDEFx']),
]:
with self.subTest(n=n):
it = mi.grouper(
iter(seq), n, incomplete='fill', fillvalue=fillvalue
)
> actual = [''.join(x) for x in it]
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:305: TypeError
test_recipes.py::GrouperTests::test_ignore
test_recipes.py::GrouperTests::test_ignore
self =
def test_ignore(self):
seq = 'ABCDEF'
for n, expected in [
(1, ['A', 'B', 'C', 'D', 'E', 'F']),
(2, ['AB', 'CD', 'EF']),
(3, ['ABC', 'DEF']),
(4, ['ABCD']),
(5, ['ABCDE']),
(6, ['ABCDEF']),
(7, []),
]:
with self.subTest(n=n):
it = mi.grouper(iter(seq), n, incomplete='ignore')
> actual = [''.join(x) for x in it]
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:321: TypeError
test_recipes.py::GrouperTests::test_invalid_incomplete
test_recipes.py::GrouperTests::test_invalid_incomplete
self =
def test_invalid_incomplete(self):
with self.assertRaises(ValueError):
> list(mi.grouper('ABCD', 3, incomplete='bogus'))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:346: TypeError
test_recipes.py::GrouperTests::test_strict
test_recipes.py::GrouperTests::test_strict
self =
def test_strict(self):
seq = 'ABCDEF'
for n, expected in [
(1, ['A', 'B', 'C', 'D', 'E', 'F']),
(2, ['AB', 'CD', 'EF']),
(3, ['ABC', 'DEF']),
(6, ['ABCDEF']),
]:
with self.subTest(n=n):
it = mi.grouper(iter(seq), n, incomplete='strict')
> actual = [''.join(x) for x in it]
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:334: TypeError
test_recipes.py::GrouperTests::test_strict_fails
test_recipes.py::GrouperTests::test_strict_fails
self =
def test_strict_fails(self):
seq = 'ABCDEF'
for n in [4, 5, 7]:
with self.subTest(n=n):
with self.assertRaises(ValueError):
> list(mi.grouper(iter(seq), n, incomplete='strict'))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:342: TypeError
test_recipes.py::RoundrobinTests::test_even_groups
test_recipes.py::RoundrobinTests::test_even_groups
self =
def test_even_groups(self):
"""Ensure ordered output from evenly populated iterables"""
self.assertEqual(
> list(mi.roundrobin('ABC', [1, 2, 3], range(3))),
['A', 1, 0, 'B', 2, 1, 'C', 3, 2],
)
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:355: TypeError
test_recipes.py::RoundrobinTests::test_uneven_groups
test_recipes.py::RoundrobinTests::test_uneven_groups
self =
def test_uneven_groups(self):
"""Ensure ordered output from unevenly populated iterables"""
self.assertEqual(
> list(mi.roundrobin('ABCD', [1, 2], range(0))),
['A', 1, 'B', 2, 'C', 'D'],
)
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:362: TypeError
test_recipes.py::PartitionTests::test_arbitrary
test_recipes.py::PartitionTests::test_arbitrary
self =
def test_arbitrary(self):
> divisibles, remainders = mi.partition(lambda x: x % 3, range(10))
E TypeError: cannot unpack non-iterable NoneType object
tests/test_recipes.py:376: TypeError
test_recipes.py::PartitionTests::test_bool
test_recipes.py::PartitionTests::test_bool
self =
def test_bool(self):
> lesser, greater = mi.partition(lambda x: x > 5, range(10))
E TypeError: cannot unpack non-iterable NoneType object
tests/test_recipes.py:371: TypeError
test_recipes.py::PartitionTests::test_pred_is_none
test_recipes.py::PartitionTests::test_pred_is_none
self =
def test_pred_is_none(self):
> falses, trues = mi.partition(None, range(3))
E TypeError: cannot unpack non-iterable NoneType object
tests/test_recipes.py:381: TypeError
test_recipes.py::PowersetTests::test_combinatorics
test_recipes.py::PowersetTests::test_combinatorics
self =
def test_combinatorics(self):
"""Ensure a proper enumeration"""
p = mi.powerset([1, 2, 3])
self.assertEqual(
> list(p), [(), (1,), (2,), (3,), (1, 2), (1, 3), (2, 3), (1, 2, 3)]
)
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:393: TypeError
test_recipes.py::UniqueEverseenTests::test_custom_key
test_recipes.py::UniqueEverseenTests::test_custom_key
self =
def test_custom_key(self):
u = mi.unique_everseen('aAbACCc', key=str.lower)
> self.assertEqual(list('abC'), list(u))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:404: TypeError
test_recipes.py::UniqueEverseenTests::test_everseen
test_recipes.py::UniqueEverseenTests::test_everseen
self =
def test_everseen(self):
u = mi.unique_everseen('AAAABBBBCCDAABBB')
> self.assertEqual(['A', 'B', 'C', 'D'], list(u))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:400: TypeError
test_recipes.py::UniqueEverseenTests::test_unhashable
test_recipes.py::UniqueEverseenTests::test_unhashable
self =
def test_unhashable(self):
iterable = ['a', [1, 2, 3], [1, 2, 3], 'a']
u = mi.unique_everseen(iterable)
> self.assertEqual(list(u), ['a', [1, 2, 3]])
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:409: TypeError
test_recipes.py::UniqueEverseenTests::test_unhashable_key
test_recipes.py::UniqueEverseenTests::test_unhashable_key
self =
def test_unhashable_key(self):
iterable = ['a', [1, 2, 3], [1, 2, 3], 'a']
u = mi.unique_everseen(iterable, key=lambda x: x)
> self.assertEqual(list(u), ['a', [1, 2, 3]])
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:414: TypeError
test_recipes.py::UniqueJustseenTests::test_custom_key
test_recipes.py::UniqueJustseenTests::test_custom_key
self =
def test_custom_key(self):
u = mi.unique_justseen('AABCcAD', str.lower)
> self.assertEqual(list('ABCAD'), list(u))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:424: TypeError
test_recipes.py::UniqueJustseenTests::test_justseen
test_recipes.py::UniqueJustseenTests::test_justseen
self =
def test_justseen(self):
u = mi.unique_justseen('AAAABBBCCDABB')
> self.assertEqual(list('ABCDAB'), list(u))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:420: TypeError
test_recipes.py::UniqueTests::test_basic
test_recipes.py::UniqueTests::test_basic
self =
def test_basic(self):
iterable = [0, 1, 1, 8, 9, 9, 9, 8, 8, 1, 9, 9]
> actual = list(mi.unique(iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:430: TypeError
test_recipes.py::UniqueTests::test_key
test_recipes.py::UniqueTests::test_key
self =
def test_key(self):
iterable = ['1', '1', '10', '10', '2', '2', '20', '20']
> actual = list(mi.unique(iterable, key=int))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:436: TypeError
test_recipes.py::UniqueTests::test_reverse
test_recipes.py::UniqueTests::test_reverse
self =
def test_reverse(self):
iterable = ['1', '1', '10', '10', '2', '2', '20', '20']
> actual = list(mi.unique(iterable, key=int, reverse=True))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:442: TypeError
test_recipes.py::IterExceptTests::test_exact_exception
test_recipes.py::IterExceptTests::test_exact_exception
self =
def test_exact_exception(self):
"""ensure the exact specified exception is caught"""
l = [1, 2, 3]
i = mi.iter_except(l.pop, IndexError)
> self.assertEqual(list(i), [3, 2, 1])
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:454: TypeError
test_recipes.py::IterExceptTests::test_first
test_recipes.py::IterExceptTests::test_first
self =
def test_first(self):
"""ensure first is run before the function"""
l = [1, 2, 3]
f = lambda: 25
i = mi.iter_except(l.pop, IndexError, f)
> self.assertEqual(list(i), [25, 3, 2, 1])
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:473: TypeError
test_recipes.py::IterExceptTests::test_generic_exception
test_recipes.py::IterExceptTests::test_generic_exception
self =
def test_generic_exception(self):
"""ensure the generic exception can be caught"""
l = [1, 2]
i = mi.iter_except(l.pop, Exception)
> self.assertEqual(list(i), [2, 1])
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:460: TypeError
test_recipes.py::IterExceptTests::test_multiple
test_recipes.py::IterExceptTests::test_multiple
self =
def test_multiple(self):
"""ensure can catch multiple exceptions"""
class Fiz(Exception):
pass
class Buzz(Exception):
pass
i = 0
def fizbuzz():
nonlocal i
i += 1
if i % 3 == 0:
raise Fiz
if i % 5 == 0:
raise Buzz
return i
expected = ([1, 2], [4], [], [7, 8], [])
for x in expected:
> self.assertEqual(list(mi.iter_except(fizbuzz, (Fiz, Buzz))), x)
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:497: TypeError
test_recipes.py::IterExceptTests::test_uncaught_exception_is_raised
test_recipes.py::IterExceptTests::test_uncaught_exception_is_raised
self =
def test_uncaught_exception_is_raised(self):
"""ensure a non-specified exception is raised"""
l = [1, 2, 3]
i = mi.iter_except(l.pop, KeyError)
> self.assertRaises(IndexError, lambda: list(i))
tests/test_recipes.py:466:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
> self.assertRaises(IndexError, lambda: list(i))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:466: TypeError
test_recipes.py::FirstTrueTests::test_default
test_recipes.py::FirstTrueTests::test_default
self =
def test_default(self):
"""Test with a default keyword"""
> self.assertEqual(mi.first_true([0, 0, 0], default='!'), '!')
E AssertionError: None != '!'
tests/test_recipes.py:513: AssertionError
test_recipes.py::FirstTrueTests::test_pred
test_recipes.py::FirstTrueTests::test_pred
self =
def test_pred(self):
"""Test with a custom predicate"""
> self.assertEqual(
mi.first_true([2, 4, 6], pred=lambda x: x % 3 == 0), 6
)
E AssertionError: None != 6
tests/test_recipes.py:517: AssertionError
test_recipes.py::FirstTrueTests::test_something_true
test_recipes.py::FirstTrueTests::test_something_true
self =
def test_something_true(self):
"""Test with no keywords"""
> self.assertEqual(mi.first_true(range(10)), 1)
E AssertionError: None != 1
tests/test_recipes.py:505: AssertionError
test_recipes.py::RandomProductTests::test_list_with_repeat
test_recipes.py::RandomProductTests::test_list_with_repeat
self =
def test_list_with_repeat(self):
"""ensure multiple items are chosen, and that they appear to be chosen
from one list then the next, in proper order.
"""
nums = [1, 2, 3]
lets = ['a', 'b', 'c']
> r = list(mi.random_product(nums, lets, repeat=100))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:556: TypeError
test_recipes.py::RandomProductTests::test_simple_lists
test_recipes.py::RandomProductTests::test_simple_lists
self =
def test_simple_lists(self):
"""Ensure that one item is chosen from each list in each pair.
Also ensure that each item from each list eventually appears in
the chosen combinations.
Odds are roughly 1 in 7.1 * 10e16 that one item from either list will
not be chosen after 100 samplings of one item from each list. Just to
be safe, better use a known random seed, too.
"""
nums = [1, 2, 3]
lets = ['a', 'b', 'c']
> n, m = zip(*[mi.random_product(nums, lets) for _ in range(100)])
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:542: TypeError
test_recipes.py::RandomPermutationTests::test_full_permutation
test_recipes.py::RandomPermutationTests::test_full_permutation
self =
def test_full_permutation(self):
"""ensure every item from the iterable is returned in a new ordering
15 elements have a 1 in 1.3 * 10e12 of appearing in sorted order, so
we fix a seed value just to be sure.
"""
i = range(15)
r = mi.random_permutation(i)
> self.assertEqual(set(i), set(r))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:577: TypeError
test_recipes.py::RandomPermutationTests::test_partial_permutation
test_recipes.py::RandomPermutationTests::test_partial_permutation
self =
def test_partial_permutation(self):
"""ensure all returned items are from the iterable, that the returned
permutation is of the desired length, and that all items eventually
get returned.
Sampling 100 permutations of length 5 from a set of 15 leaves a
(2/3)^100 chance that an item will not be chosen. Multiplied by 15
items, there is a 1 in 2.6e16 chance that at least 1 item will not
show up in the resulting output. Using a random seed will fix that.
"""
items = range(15)
item_set = set(items)
all_items = set()
for _ in range(100):
permutation = mi.random_permutation(items, 5)
> self.assertEqual(len(permutation), 5)
E TypeError: object of type 'NoneType' has no len()
tests/test_recipes.py:597: TypeError
test_recipes.py::RandomCombinationTests::test_no_replacement
test_recipes.py::RandomCombinationTests::test_no_replacement
self =
def test_no_replacement(self):
"""ensure that elements are sampled without replacement"""
items = range(15)
for _ in range(50):
combination = mi.random_combination(items, len(items))
> self.assertEqual(len(combination), len(set(combination)))
E TypeError: object of type 'NoneType' has no len()
tests/test_recipes.py:622: TypeError
test_recipes.py::RandomCombinationTests::test_pseudorandomness
test_recipes.py::RandomCombinationTests::test_pseudorandomness
self =
def test_pseudorandomness(self):
"""ensure different subsets of the iterable get returned over many
samplings of random combinations"""
items = range(15)
all_items = set()
for _ in range(50):
combination = mi.random_combination(items, 5)
> all_items |= set(combination)
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:614: TypeError
test_recipes.py::RandomCombinationWithReplacementTests::test_pseudorandomness
test_recipes.py::RandomCombinationWithReplacementTests::test_pseudorandomness
self =
def test_pseudorandomness(self):
"""ensure different subsets of the iterable get returned over many
samplings of random combinations"""
items = range(15)
all_items = set()
for _ in range(50):
combination = mi.random_combination_with_replacement(items, 5)
> all_items |= set(combination)
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:646: TypeError
test_recipes.py::RandomCombinationWithReplacementTests::test_replacement
test_recipes.py::RandomCombinationWithReplacementTests::test_replacement
self =
def test_replacement(self):
"""ensure that elements are sampled with replacement"""
items = range(5)
combo = mi.random_combination_with_replacement(items, len(items) * 2)
> self.assertEqual(2 * len(items), len(combo))
E TypeError: object of type 'NoneType' has no len()
tests/test_recipes.py:635: TypeError
test_recipes.py::NthCombinationTests::test_basic
test_recipes.py::NthCombinationTests::test_basic
self =
def test_basic(self):
iterable = 'abcdefg'
r = 4
for index, expected in enumerate(combinations(iterable, r)):
actual = mi.nth_combination(iterable, r, index)
> self.assertEqual(actual, expected)
E AssertionError: None != ('a', 'b', 'c', 'd')
tests/test_recipes.py:656: AssertionError
test_recipes.py::NthCombinationTests::test_invalid_index
test_recipes.py::NthCombinationTests::test_invalid_index
self =
def test_invalid_index(self):
> with self.assertRaises(IndexError):
E AssertionError: IndexError not raised
tests/test_recipes.py:669: AssertionError
test_recipes.py::NthCombinationTests::test_invalid_r
test_recipes.py::NthCombinationTests::test_invalid_r
self =
def test_invalid_r(self):
for r in (-1, 3):
> with self.assertRaises(ValueError):
E AssertionError: ValueError not raised
tests/test_recipes.py:665: AssertionError
test_recipes.py::NthCombinationTests::test_long
test_recipes.py::NthCombinationTests::test_long
self =
def test_long(self):
actual = mi.nth_combination(range(180), 4, 2000000)
expected = (2, 12, 35, 126)
> self.assertEqual(actual, expected)
E AssertionError: None != (2, 12, 35, 126)
tests/test_recipes.py:661: AssertionError
test_recipes.py::NthPermutationTests::test_invalid_index
test_recipes.py::NthPermutationTests::test_invalid_index
self =
def test_invalid_index(self):
iterable = 'abcde'
r = 4
n = factorial(len(iterable)) // factorial(len(iterable) - r)
for index in [-1 - n, n + 1]:
> with self.assertRaises(IndexError):
E AssertionError: IndexError not raised
tests/test_recipes.py:713: AssertionError
test_recipes.py::NthPermutationTests::test_invalid_r
test_recipes.py::NthPermutationTests::test_invalid_r
self =
def test_invalid_r(self):
iterable = 'abcde'
r = 4
n = factorial(len(iterable)) // factorial(len(iterable) - r)
for r in [-1, n + 1]:
> with self.assertRaises(ValueError):
E AssertionError: ValueError not raised
tests/test_recipes.py:721: AssertionError
test_recipes.py::NthPermutationTests::test_negative_index
test_recipes.py::NthPermutationTests::test_negative_index
self =
def test_negative_index(self):
iterable = 'abcde'
r = 4
n = factorial(len(iterable)) // factorial(len(iterable) - r)
for index, expected in enumerate(permutations(iterable, r)):
actual = mi.nth_permutation(iterable, r, index - n)
> self.assertEqual(actual, expected)
E AssertionError: None != ('a', 'b', 'c', 'd')
tests/test_recipes.py:706: AssertionError
test_recipes.py::NthPermutationTests::test_null
test_recipes.py::NthPermutationTests::test_null
self =
def test_null(self):
actual = mi.nth_permutation([], 0, 0)
expected = tuple()
> self.assertEqual(actual, expected)
E AssertionError: None != ()
tests/test_recipes.py:698: AssertionError
test_recipes.py::NthPermutationTests::test_r_equal_to_n
test_recipes.py::NthPermutationTests::test_r_equal_to_n
self =
def test_r_equal_to_n(self):
iterable = 'abcde'
for index, expected in enumerate(permutations(iterable)):
actual = mi.nth_permutation(iterable, None, index)
> self.assertEqual(actual, expected)
E AssertionError: None != ('a', 'b', 'c', 'd', 'e')
tests/test_recipes.py:685: AssertionError
test_recipes.py::NthPermutationTests::test_r_less_than_n
test_recipes.py::NthPermutationTests::test_r_less_than_n
self =
def test_r_less_than_n(self):
iterable = 'abcde'
r = 4
for index, expected in enumerate(permutations(iterable, r)):
actual = mi.nth_permutation(iterable, r, index)
> self.assertEqual(actual, expected)
E AssertionError: None != ('a', 'b', 'c', 'd')
tests/test_recipes.py:679: AssertionError
test_recipes.py::PrependTests::test_basic
test_recipes.py::PrependTests::test_basic
self =
def test_basic(self):
value = 'a'
iterator = iter('bcdefg')
> actual = list(mi.prepend(value, iterator))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:729: TypeError
test_recipes.py::PrependTests::test_multiple
test_recipes.py::PrependTests::test_multiple
self =
def test_multiple(self):
value = 'ab'
iterator = iter('cdefg')
> actual = tuple(mi.prepend(value, iterator))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:736: TypeError
test_recipes.py::Convolvetests::test_derivative
test_recipes.py::Convolvetests::test_derivative
self =
def test_derivative(self):
signal = iter([10, 20, 30, 40, 50])
kernel = [1, -1]
> actual = list(mi.convolve(signal, kernel))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:759: TypeError
test_recipes.py::Convolvetests::test_infinite_signal
test_recipes.py::Convolvetests::test_infinite_signal
self =
def test_infinite_signal(self):
signal = count()
kernel = [1, -1]
> actual = mi.take(5, mi.convolve(signal, kernel))
tests/test_recipes.py:766:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
n = 5, iterable = None
def take(n, iterable):
"""Return first *n* items of the iterable as a list.
>>> take(3, range(10))
[0, 1, 2]
If there are fewer than *n* items in the iterable, all of them are
returned.
>>> take(10, range(3))
[0, 1, 2]
"""
> return list(islice(iterable, n))
E TypeError: 'NoneType' object is not iterable
more_itertools/recipes.py:71: TypeError
test_recipes.py::Convolvetests::test_moving_average
test_recipes.py::Convolvetests::test_moving_average
self =
def test_moving_average(self):
signal = iter([10, 20, 30, 40, 50])
kernel = [0.5, 0.5]
> actual = list(mi.convolve(signal, kernel))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:745: TypeError
test_recipes.py::BeforeAndAfterTests::test_empty
test_recipes.py::BeforeAndAfterTests::test_empty
self =
def test_empty(self):
> before, after = mi.before_and_after(bool, [])
E TypeError: cannot unpack non-iterable NoneType object
tests/test_recipes.py:773: TypeError
test_recipes.py::BeforeAndAfterTests::test_nested_remainder
test_recipes.py::BeforeAndAfterTests::test_nested_remainder
self =
def test_nested_remainder(self):
events = ["SUM", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] * 1000
events += ["MULTIPLY", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] * 1000
> for operation, numbers in self._group_events(events):
tests/test_recipes.py:817:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
events =
@staticmethod
def _group_events(events):
events = iter(events)
while True:
try:
operation = next(events)
except StopIteration:
break
assert operation in ["SUM", "MULTIPLY"]
# Here, the remainder `events` is passed into `before_and_after`
# again, which would be problematic if the remainder is a
# generator function (as in Python 3.10 itertools recipes), since
# that creates recursion. `itertools.chain` solves this problem.
> numbers, events = mi.before_and_after(
lambda e: isinstance(e, int), events
)
E TypeError: cannot unpack non-iterable NoneType object
tests/test_recipes.py:807: TypeError
test_recipes.py::BeforeAndAfterTests::test_never_false
test_recipes.py::BeforeAndAfterTests::test_never_false
self =
def test_never_false(self):
> before, after = mi.before_and_after(bool, [1, True, Ellipsis, ' '])
E TypeError: cannot unpack non-iterable NoneType object
tests/test_recipes.py:783: TypeError
test_recipes.py::BeforeAndAfterTests::test_never_true
test_recipes.py::BeforeAndAfterTests::test_never_true
self =
def test_never_true(self):
> before, after = mi.before_and_after(bool, [0, False, None, ''])
E TypeError: cannot unpack non-iterable NoneType object
tests/test_recipes.py:778: TypeError
test_recipes.py::BeforeAndAfterTests::test_some_true
test_recipes.py::BeforeAndAfterTests::test_some_true
self =
def test_some_true(self):
> before, after = mi.before_and_after(bool, [1, True, 0, False])
E TypeError: cannot unpack non-iterable NoneType object
tests/test_recipes.py:788: TypeError
test_recipes.py::TriplewiseTests::test_basic
test_recipes.py::TriplewiseTests::test_basic
self =
def test_basic(self):
for iterable, expected in [
([0], []),
([0, 1], []),
([0, 1, 2], [(0, 1, 2)]),
([0, 1, 2, 3], [(0, 1, 2), (1, 2, 3)]),
([0, 1, 2, 3, 4], [(0, 1, 2), (1, 2, 3), (2, 3, 4)]),
]:
with self.subTest(expected=expected):
> actual = list(mi.triplewise(iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:836: TypeError
test_recipes.py::SlidingWindowTests::test_deque_version
test_recipes.py::SlidingWindowTests::test_deque_version
self =
def test_deque_version(self):
iterable = map(str, range(100))
> all_windows = list(mi.sliding_window(iterable, 95))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:858: TypeError
test_recipes.py::SlidingWindowTests::test_islice_version
test_recipes.py::SlidingWindowTests::test_islice_version
self =
def test_islice_version(self):
for iterable, n, expected in [
([], 1, []),
([0], 1, [(0,)]),
([0, 1], 1, [(0,), (1,)]),
([0, 1, 2], 2, [(0, 1), (1, 2)]),
([0, 1, 2], 3, [(0, 1, 2)]),
([0, 1, 2], 4, []),
([0, 1, 2, 3], 4, [(0, 1, 2, 3)]),
([0, 1, 2, 3, 4], 4, [(0, 1, 2, 3), (1, 2, 3, 4)]),
]:
with self.subTest(expected=expected):
> actual = list(mi.sliding_window(iterable, n))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:853: TypeError
test_recipes.py::SlidingWindowTests::test_zero
test_recipes.py::SlidingWindowTests::test_zero
self =
def test_zero(self):
iterable = map(str, range(100))
with self.assertRaises(ValueError):
> list(mi.sliding_window(iterable, 0))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:865: TypeError
test_recipes.py::SubslicesTests::test_basic
test_recipes.py::SubslicesTests::test_basic
self =
def test_basic(self):
for iterable, expected in [
([], []),
([1], [[1]]),
([1, 2], [[1], [1, 2], [2]]),
(iter([1, 2]), [[1], [1, 2], [2]]),
([2, 1], [[2], [2, 1], [1]]),
(
'ABCD',
[
['A'],
['A', 'B'],
['A', 'B', 'C'],
['A', 'B', 'C', 'D'],
['B'],
['B', 'C'],
['B', 'C', 'D'],
['C'],
['C', 'D'],
['D'],
],
),
]:
with self.subTest(expected=expected):
> actual = list(mi.subslices(iterable))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:893: TypeError
test_recipes.py::PolynomialFromRootsTests::test_basic
test_recipes.py::PolynomialFromRootsTests::test_basic
self =
def test_basic(self):
for roots, expected in [
((2, 1, -1), [1, -2, -1, 2]),
((2, 3), [1, -5, 6]),
((1, 2, 3), [1, -6, 11, -6]),
((2, 4, 1), [1, -7, 14, -8]),
]:
with self.subTest(roots=roots):
actual = mi.polynomial_from_roots(roots)
> self.assertEqual(actual, expected)
E AssertionError: None != [1, -2, -1, 2]
tests/test_recipes.py:907: AssertionError
test_recipes.py::PolynomialEvalTests::test_basic
test_recipes.py::PolynomialEvalTests::test_basic
self =
def test_basic(self):
for coefficients, x, expected in [
([1, -4, -17, 60], 2, 18),
([1, -4, -17, 60], 2.5, 8.125),
([1, -4, -17, 60], Fraction(2, 3), Fraction(1274, 27)),
([1, -4, -17, 60], Decimal('1.75'), Decimal('23.359375')),
([], 2, 0),
([], 2.5, 0.0),
([], Fraction(2, 3), Fraction(0, 1)),
([], Decimal('1.75'), Decimal('0.00')),
([11], 7, 11),
([11, 2], 7, 79),
]:
with self.subTest(x=x):
actual = mi.polynomial_eval(coefficients, x)
> self.assertEqual(actual, expected)
E AssertionError: None != 18
tests/test_recipes.py:926: AssertionError
test_recipes.py::IterIndexTests::test_basic
test_recipes.py::IterIndexTests::test_basic
self =
def test_basic(self):
iterable = 'AABCADEAF'
for wrapper in (list, iter):
with self.subTest(wrapper=wrapper):
> actual = list(mi.iter_index(wrapper(iterable), 'A'))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:935: TypeError
test_recipes.py::IterIndexTests::test_start
test_recipes.py::IterIndexTests::test_start
self =
def test_start(self):
for wrapper in (list, iter):
with self.subTest(wrapper=wrapper):
iterable = 'AABCADEAF'
i = -1
actual = []
while True:
try:
> i = next(
mi.iter_index(wrapper(iterable), 'A', start=i + 1)
)
E TypeError: 'NoneType' object is not an iterator
tests/test_recipes.py:947: TypeError
test_recipes.py::IterIndexTests::test_stop
test_recipes.py::IterIndexTests::test_stop
self =
def test_stop(self):
> actual = list(mi.iter_index('AABCADEAF', 'A', stop=7))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:959: TypeError
test_recipes.py::SieveTests::test_basic
test_recipes.py::SieveTests::test_basic
self =
def test_basic(self):
self.assertEqual(
> list(mi.sieve(67)),
[
2,
3,
5,
7,
11,
13,
17,
19,
23,
29,
31,
37,
41,
43,
47,
53,
59,
61,
],
)
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:967: TypeError
test_recipes.py::SieveTests::test_prime_counts
test_recipes.py::SieveTests::test_prime_counts
self =
def test_prime_counts(self):
for n, expected in (
(100, 25),
(1_000, 168),
(10_000, 1229),
(100_000, 9592),
(1_000_000, 78498),
):
with self.subTest(n=n):
> self.assertEqual(mi.ilen(mi.sieve(n)), expected)
E AssertionError: None != 25
tests/test_recipes.py:1000: AssertionError
test_recipes.py::SieveTests::test_small_numbers
test_recipes.py::SieveTests::test_small_numbers
self =
def test_small_numbers(self):
with self.assertRaises(ValueError):
> list(mi.sieve(-1))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:1004: TypeError
test_recipes.py::BatchedTests::test_basic
test_recipes.py::BatchedTests::test_basic
self =
def test_basic(self):
iterable = range(1, 5 + 1)
for n, expected in (
(1, [(1,), (2,), (3,), (4,), (5,)]),
(2, [(1, 2), (3, 4), (5,)]),
(3, [(1, 2, 3), (4, 5)]),
(4, [(1, 2, 3, 4), (5,)]),
(5, [(1, 2, 3, 4, 5)]),
(6, [(1, 2, 3, 4, 5)]),
):
with self.subTest(n=n):
> actual = list(mi.batched(iterable, n))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:1023: TypeError
test_recipes.py::BatchedTests::test_strict
test_recipes.py::BatchedTests::test_strict
self =
def test_strict(self):
with self.assertRaises(ValueError):
> list(mi.batched('ABCDEFG', 3, strict=True))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:1028: TypeError
test_recipes.py::TransposeTests::test_basic
test_recipes.py::TransposeTests::test_basic
self =
def test_basic(self):
it = [(10, 11, 12), (20, 21, 22), (30, 31, 32)]
> actual = list(mi.transpose(it))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:1045: TypeError
test_recipes.py::TransposeTests::test_empty
test_recipes.py::TransposeTests::test_empty
self =
def test_empty(self):
it = []
> actual = list(mi.transpose(it))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:1039: TypeError
test_recipes.py::TransposeTests::test_incompatible_error
test_recipes.py::TransposeTests::test_incompatible_error
self =
@skipIf(version_info[:2] < (3, 10), 'strict=True missing on 3.9')
def test_incompatible_error(self):
it = [(10, 11, 12, 13), (20, 21, 22), (30, 31, 32)]
with self.assertRaises(ValueError):
> list(mi.transpose(it))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:1053: TypeError
test_recipes.py::ReshapeTests::test_basic
test_recipes.py::ReshapeTests::test_basic
self =
def test_basic(self):
matrix = [(0, 1, 2, 3), (4, 5, 6, 7), (8, 9, 10, 11)]
for cols, expected in (
(
1,
[
(0,),
(1,),
(2,),
(3,),
(4,),
(5,),
(6,),
(7,),
(8,),
(9,),
(10,),
(11,),
],
),
(2, [(0, 1), (2, 3), (4, 5), (6, 7), (8, 9), (10, 11)]),
(3, [(0, 1, 2), (3, 4, 5), (6, 7, 8), (9, 10, 11)]),
(4, [(0, 1, 2, 3), (4, 5, 6, 7), (8, 9, 10, 11)]),
(6, [(0, 1, 2, 3, 4, 5), (6, 7, 8, 9, 10, 11)]),
(12, [(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)]),
):
with self.subTest(cols=cols):
> actual = list(mi.reshape(matrix, cols))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:1100: TypeError
test_recipes.py::ReshapeTests::test_empty
test_recipes.py::ReshapeTests::test_empty
self =
def test_empty(self):
> actual = list(mi.reshape([], 3))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:1065: TypeError
test_recipes.py::ReshapeTests::test_zero
test_recipes.py::ReshapeTests::test_zero
self =
def test_zero(self):
matrix = [(0, 1, 2, 3), (4, 5, 6, 7), (8, 9, 10, 11)]
with self.assertRaises(ValueError):
> list(mi.reshape(matrix, 0))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:1071: TypeError
test_recipes.py::MatMulTests::test_m_by_n
test_recipes.py::MatMulTests::test_m_by_n
self =
def test_m_by_n(self):
m1 = [[2, 5], [7, 9], [3, 4]]
m2 = [[7, 11, 5, 4, 9], [3, 5, 2, 6, 3]]
> actual = list(mi.matmul(m1, m2))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:1113: TypeError
test_recipes.py::MatMulTests::test_n_by_n
test_recipes.py::MatMulTests::test_n_by_n
self =
def test_n_by_n(self):
> actual = list(mi.matmul([(7, 5), (3, 5)], [[2, 5], [7, 9]]))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:1106: TypeError
test_recipes.py::FactorTests::test_basic
test_recipes.py::FactorTests::test_basic
self =
def test_basic(self):
for n, expected in (
(0, []),
(1, []),
(2, [2]),
(3, [3]),
(4, [2, 2]),
(6, [2, 3]),
(360, [2, 2, 2, 3, 3, 5]),
(128_884_753_939, [128_884_753_939]),
(999953 * 999983, [999953, 999983]),
(909_909_090_909, [3, 3, 7, 13, 13, 751, 113797]),
):
with self.subTest(n=n):
> actual = list(mi.factor(n))
E TypeError: 'NoneType' object is not iterable
tests/test_recipes.py:1137: TypeError
test_recipes.py::FactorTests::test_cross_check
test_recipes.py::FactorTests::test_cross_check
self =
def test_cross_check(self):
prod = lambda x: reduce(mul, x, 1)
> self.assertTrue(all(prod(mi.factor(n)) == n for n in range(1, 2000)))
tests/test_recipes.py:1142:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/test_recipes.py:1142: in
self.assertTrue(all(prod(mi.factor(n)) == n for n in range(1, 2000)))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
x = None
> prod = lambda x: reduce(mul, x, 1)
E TypeError: reduce() arg 2 must support iteration
tests/test_recipes.py:1141: TypeError
test_recipes.py::SumOfSquaresTests::test_basic
test_recipes.py::SumOfSquaresTests::test_basic
self =
def test_basic(self):
for it, expected in (
([], 0),
([1, 2, 3], 1 + 4 + 9),
([2, 4, 6, 8], 4 + 16 + 36 + 64),
):
with self.subTest(it=it):
actual = mi.sum_of_squares(it)
> self.assertEqual(actual, expected)
E AssertionError: None != 0
tests/test_recipes.py:1162: AssertionError
test_recipes.py::PolynomialDerivativeTests::test_basic
test_recipes.py::PolynomialDerivativeTests::test_basic
self =
def test_basic(self):
for coefficients, expected in [
([], []),
([1], []),
([1, 2], [1]),
([1, 2, 3], [2, 2]),
([1, 2, 3, 4], [3, 4, 3]),
([1.1, 2, 3, 4], [(1.1 * 3), 4, 3]),
]:
with self.subTest(coefficients=coefficients):
actual = mi.polynomial_derivative(coefficients)
> self.assertEqual(actual, expected)
E AssertionError: None != []
tests/test_recipes.py:1177: AssertionError
test_recipes.py::TotientTests::test_basic
test_recipes.py::TotientTests::test_basic
self =
def test_basic(self):
for n, expected in (
(1, 1),
(2, 1),
(3, 2),
(4, 2),
(9, 6),
(12, 4),
(128_884_753_939, 128_884_753_938),
(999953 * 999983, 999952 * 999982),
(6**20, 1 * 2**19 * 2 * 3**19),
):
with self.subTest(n=n):
> self.assertEqual(mi.totient(n), expected)
E AssertionError: None != 1
tests/test_recipes.py:1194: AssertionError
Patch diff
diff --git a/more_itertools/more.py b/more_itertools/more.py
index 7ef1c96..d9287c7 100755
--- a/more_itertools/more.py
+++ b/more_itertools/more.py
@@ -16,6 +16,77 @@ from .recipes import _marker, _zip_equal, UnequalIterablesError, consume, flatte
__all__ = ['AbortThread', 'SequenceView', 'UnequalIterablesError', 'adjacent', 'all_unique', 'always_iterable', 'always_reversible', 'bucket', 'callback_iter', 'chunked', 'chunked_even', 'circular_shifts', 'collapse', 'combination_index', 'combination_with_replacement_index', 'consecutive_groups', 'constrained_batches', 'consumer', 'count_cycle', 'countable', 'dft', 'difference', 'distinct_combinations', 'distinct_permutations', 'distribute', 'divide', 'doublestarmap', 'duplicates_everseen', 'duplicates_justseen', 'classify_unique', 'exactly_n', 'filter_except', 'filter_map', 'first', 'gray_product', 'groupby_transform', 'ichunked', 'iequals', 'idft', 'ilen', 'interleave', 'interleave_evenly', 'interleave_longest', 'intersperse', 'is_sorted', 'islice_extended', 'iterate', 'iter_suppress', 'join_mappings', 'last', 'locate', 'longest_common_prefix', 'lstrip', 'make_decorator', 'map_except', 'map_if', 'map_reduce', 'mark_ends', 'minmax', 'nth_or_last', 'nth_permutation', 'nth_product', 'nth_combination_with_replacement', 'numeric_range', 'one', 'only', 'outer_product', 'padded', 'partial_product', 'partitions', 'peekable', 'permutation_index', 'powerset_of_sets', 'product_index', 'raise_', 'repeat_each', 'repeat_last', 'replace', 'rlocate', 'rstrip', 'run_length', 'sample', 'seekable', 'set_partitions', 'side_effect', 'sliced', 'sort_together', 'split_after', 'split_at', 'split_before', 'split_into', 'split_when', 'spy', 'stagger', 'strip', 'strictly_n', 'substrings', 'substrings_indexes', 'takewhile_inclusive', 'time_limited', 'unique_in_window', 'unique_to_each', 'unzip', 'value_chain', 'windowed', 'windowed_complete', 'with_iter', 'zip_broadcast', 'zip_equal', 'zip_offset']
_fsumprod = getattr(math, 'sumprod', lambda x, y: fsum(map(mul, x, y)))
+def raise_(exception, *args):
+ """Raise an exception in a context manager.
+
+ Used for conditional exception raising:
+
+ >>> it = ['a', 'b']
+ >>> raise_(RuntimeError, 'Something bad happened') if len(it) <= 2 else it[2]
+ Traceback (most recent call last):
+ ...
+ RuntimeError: Something bad happened
+
+ """
+ raise exception(*args)
+
+
+def side_effect(func, iterable, chunk_size=None, before=None, after=None):
+ """Invoke *func* on each item in *iterable* (or on each *chunk_size* group of
+ items) before yielding the item.
+
+ `func` must be a function that takes a single argument. Its return value
+ will be discarded.
+
+ *before* and *after* are optional functions that take no arguments. They
+ will be executed before iteration starts and after it ends, respectively.
+
+ `side_effect` can be used for logging, updating progress bars, or anything
+ that is not functionally "pure."
+
+ Emitting a status message:
+
+ >>> func = lambda item: print('Received {}'.format(item))
+ >>> list(side_effect(func, range(2)))
+ Received 0
+ Received 1
+ [0, 1]
+
+ Operating on chunks of items:
+
+ >>> pair_sum = lambda chunk: print('Sum of pair is {}'.format(sum(chunk)))
+ >>> list(side_effect(pair_sum, range(6), 2))
+ Sum of pair is 1
+ Sum of pair is 5
+ Sum of pair is 9
+ [0, 1, 2, 3, 4, 5]
+
+ """
+ def wrapped():
+ if before is not None:
+ before()
+
+ try:
+ if chunk_size is None:
+ for item in iterable:
+ func(item)
+ yield item
+ else:
+ it = iter(iterable)
+ while True:
+ chunk = list(islice(it, chunk_size))
+ if not chunk:
+ break
+ func(chunk)
+ for item in chunk:
+ yield item
+ finally:
+ if after is not None:
+ after()
+
+ return wrapped()
+
+
def chunked(iterable, n, strict=False):
"""Break *iterable* into lists of length *n*:
@@ -35,7 +106,20 @@ def chunked(iterable, n, strict=False):
list is yielded.
"""
- pass
+ if n is None:
+ yield list(iterable)
+ return
+
+ iterator = iter(iterable)
+ while True:
+ chunk = list(islice(iterator, n))
+ if not chunk:
+ return
+ if strict and len(chunk) != n:
+ if n is None:
+ raise ValueError("n must not be None when using strict mode.")
+ raise ValueError("iterable is not divisible by n")
+ yield chunk
def first(iterable, default=_marker):
"""Return the first item of *iterable*, or *default* if *iterable* is
@@ -54,7 +138,12 @@ def first(iterable, default=_marker):
``next(iter(iterable), default)``.
"""
- pass
+ try:
+ return next(iter(iterable))
+ except StopIteration:
+ if default is _marker:
+ raise ValueError('first() was called on an empty iterable')
+ return default
def last(iterable, default=_marker):
"""Return the last item of *iterable*, or *default* if *iterable* is
@@ -68,7 +157,30 @@ def last(iterable, default=_marker):
If *default* is not provided and there are no items in the iterable,
raise ``ValueError``.
"""
- pass
+ try:
+ # Try to get the last element using sequence protocol
+ if isinstance(iterable, Sequence):
+ if not iterable:
+ if default is _marker:
+ raise ValueError('last() was called on an empty iterable')
+ return default
+ return iterable[-1]
+
+ # Fall back to iterating
+ it = iter(iterable)
+ try:
+ item = next(it)
+ except StopIteration:
+ if default is _marker:
+ raise ValueError('last() was called on an empty iterable')
+ return default
+
+ for item in it:
+ pass
+ return item
+ except (TypeError, KeyError, AttributeError):
+ # Handle mappings and other objects that don't support indexing
+ return last(list(iterable), default)
def nth_or_last(iterable, n, default=_marker):
"""Return the nth or the last item of *iterable*,
@@ -84,7 +196,22 @@ def nth_or_last(iterable, n, default=_marker):
If *default* is not provided and there are no items in the iterable,
raise ``ValueError``.
"""
- pass
+ it = iter(iterable)
+ try:
+ item = next(it)
+ except StopIteration:
+ if default is _marker:
+ raise ValueError('nth_or_last() was called on an empty iterable')
+ return default
+
+ try:
+ for i, item in enumerate(chain([item], it)):
+ if i == n:
+ return item
+ return item # If we get here, we ran out of items before reaching n
+ except (TypeError, KeyError, AttributeError):
+ # Handle mappings and other objects that don't support indexing
+ return nth_or_last(list(iterable), n, default)
class peekable:
"""Wrap an iterator to allow lookahead and prepending elements.
diff --git a/more_itertools/recipes.py b/more_itertools/recipes.py
index 9c5e363..49c57ec 100644
--- a/more_itertools/recipes.py
+++ b/more_itertools/recipes.py
@@ -23,8 +23,38 @@ except TypeError:
_zip_strict = zip
else:
_zip_strict = partial(zip, strict=True)
+
+def _zip_equal(*iterables):
+ """Like zip(), but ensures all iterables have the same length."""
+ # zip_longest() wouldn't work here because it suppresses length differences
+ sentinel = object()
+ result = []
+ for combo in zip_longest(*iterables, fillvalue=sentinel):
+ if any(x is sentinel for x in combo):
+ raise UnequalIterablesError()
+ result.append(combo)
+ return result
+
_sumprod = getattr(math, 'sumprod', lambda x, y: dotproduct(x, y))
+def batched(iterable, n, *, strict=False):
+ """Batch data into lists of length *n*. The last batch may be shorter.
+
+ >>> list(batched('ABCDEFG', 3))
+ [['A', 'B', 'C'], ['D', 'E', 'F'], ['G']]
+
+ This recipe is from the ``itertools`` docs.
+ """
+ if n < 1:
+ raise ValueError('n must be at least one')
+ it = iter(iterable)
+ while True:
+ batch = list(islice(it, n))
+ if not batch:
+ break
+ yield batch
+
+
def take(n, iterable):
"""Return first *n* items of the iterable as a list.
@@ -38,7 +68,7 @@ def take(n, iterable):
[0, 1, 2]
"""
- pass
+ return list(islice(iterable, n))
def tabulate(function, start=0):
"""Return an iterator over the results of ``func(start)``,
@@ -217,12 +247,14 @@ def _pairwise(iterable):
On Python 3.10 and above, this is an alias for :func:`itertools.pairwise`.
"""
- pass
+ a, b = tee(iterable)
+ next(b, None)
+ return zip(a, b)
try:
from itertools import pairwise as itertools_pairwise
+ pairwise = itertools_pairwise
except ImportError:
pairwise = _pairwise
-else:
pairwise.__doc__ = _pairwise.__doc__
class UnequalIterablesError(ValueError):