(doc)
| 594 | |
| 595 | |
| 596 | def test_sequence_caster_protocol(doc): |
| 597 | from collections.abc import Sequence |
| 598 | |
| 599 | # Implements the Sequence protocol without explicitly inheriting from collections.abc.Sequence. |
| 600 | class BareSequenceLike: |
| 601 | def __init__(self, *args): |
| 602 | self.data = tuple(args) |
| 603 | |
| 604 | def __len__(self): |
| 605 | return len(self.data) |
| 606 | |
| 607 | def __getitem__(self, index): |
| 608 | return self.data[index] |
| 609 | |
| 610 | # Implements the Sequence protocol by reusing BareSequenceLike's implementation. |
| 611 | # Additionally, inherits from collections.abc.Sequence. |
| 612 | class FormalSequenceLike(BareSequenceLike, Sequence): |
| 613 | pass |
| 614 | |
| 615 | # convert mode |
| 616 | assert ( |
| 617 | doc(m.roundtrip_std_vector_int) |
| 618 | == "roundtrip_std_vector_int(arg0: collections.abc.Sequence[typing.SupportsInt | typing.SupportsIndex]) -> list[int]" |
| 619 | ) |
| 620 | assert m.roundtrip_std_vector_int([1, 2, 3]) == [1, 2, 3] |
| 621 | assert m.roundtrip_std_vector_int((1, 2, 3)) == [1, 2, 3] |
| 622 | assert m.roundtrip_std_vector_int(FormalSequenceLike(1, 2, 3)) == [1, 2, 3] |
| 623 | assert m.roundtrip_std_vector_int(BareSequenceLike(1, 2, 3)) == [1, 2, 3] |
| 624 | assert m.roundtrip_std_vector_int([]) == [] |
| 625 | assert m.roundtrip_std_vector_int(()) == [] |
| 626 | assert m.roundtrip_std_vector_int(BareSequenceLike()) == [] |
| 627 | # noconvert mode |
| 628 | assert ( |
| 629 | doc(m.roundtrip_std_vector_int_noconvert) |
| 630 | == "roundtrip_std_vector_int_noconvert(v: list[int]) -> list[int]" |
| 631 | ) |
| 632 | assert m.roundtrip_std_vector_int_noconvert([1, 2, 3]) == [1, 2, 3] |
| 633 | assert m.roundtrip_std_vector_int_noconvert((1, 2, 3)) == [1, 2, 3] |
| 634 | assert m.roundtrip_std_vector_int_noconvert(FormalSequenceLike(1, 2, 3)) == [ |
| 635 | 1, |
| 636 | 2, |
| 637 | 3, |
| 638 | ] |
| 639 | assert m.roundtrip_std_vector_int_noconvert(BareSequenceLike(1, 2, 3)) == [1, 2, 3] |
| 640 | assert m.roundtrip_std_vector_int_noconvert([]) == [] |
| 641 | assert m.roundtrip_std_vector_int_noconvert(()) == [] |
| 642 | assert m.roundtrip_std_vector_int_noconvert(BareSequenceLike()) == [] |
| 643 | |
| 644 | |
| 645 | def test_mapping_caster_protocol(doc): |
nothing calls this directly
no test coverage detected