MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_generalized_iterators

Function test_generalized_iterators

tests/test_sequences_and_iterators.py:24–46  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22
23
24def test_generalized_iterators():
25 assert list(m.IntPairs([(1, 2), (3, 4), (0, 5)]).nonzero()) == [(1, 2), (3, 4)]
26 assert list(m.IntPairs([(1, 2), (2, 0), (0, 3), (4, 5)]).nonzero()) == [(1, 2)]
27 assert list(m.IntPairs([(0, 3), (1, 2), (3, 4)]).nonzero()) == []
28
29 assert list(m.IntPairs([(1, 2), (3, 4), (0, 5)]).nonzero_keys()) == [1, 3]
30 assert list(m.IntPairs([(1, 2), (2, 0), (0, 3), (4, 5)]).nonzero_keys()) == [1]
31 assert list(m.IntPairs([(0, 3), (1, 2), (3, 4)]).nonzero_keys()) == []
32
33 assert list(m.IntPairs([(1, 2), (3, 4), (0, 5)]).nonzero_values()) == [2, 4]
34 assert list(m.IntPairs([(1, 2), (2, 0), (0, 3), (4, 5)]).nonzero_values()) == [2]
35 assert list(m.IntPairs([(0, 3), (1, 2), (3, 4)]).nonzero_values()) == []
36
37 # __next__ must continue to raise StopIteration
38 it = m.IntPairs([(0, 0)]).nonzero()
39 for _ in range(3):
40 with pytest.raises(StopIteration):
41 next(it)
42
43 it = m.IntPairs([(0, 0)]).nonzero_keys()
44 for _ in range(3):
45 with pytest.raises(StopIteration):
46 next(it)
47
48
49def test_nonref_iterators():

Callers

nothing calls this directly

Calls 2

listClass · 0.85
IntPairsMethod · 0.80

Tested by

no test coverage detected