File: test_docs_advanced_cast_custom.py

package info (click to toggle)
pybind11 3.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,448 kB
  • sloc: cpp: 27,239; python: 13,512; ansic: 4,244; makefile: 204; sh: 36
file content (40 lines) | stat: -rw-r--r-- 1,251 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from __future__ import annotations

from typing import TYPE_CHECKING, Sequence

if TYPE_CHECKING:
    from conftest import SanitizedString

from pybind11_tests import docs_advanced_cast_custom as m


def assert_negate_function(
    input_sequence: Sequence[float],
    target: tuple[float, float],
) -> None:
    output = m.negate(input_sequence)
    assert isinstance(output, tuple)
    assert len(output) == 2
    assert isinstance(output[0], float)
    assert isinstance(output[1], float)
    assert output == target


def test_negate(doc: SanitizedString) -> None:
    assert (
        doc(m.negate)
        == "negate(arg0: collections.abc.Sequence[float]) -> tuple[float, float]"
    )
    assert_negate_function([1.0, -1.0], (-1.0, 1.0))
    assert_negate_function((1.0, -1.0), (-1.0, 1.0))
    assert_negate_function([1, -1], (-1.0, 1.0))
    assert_negate_function((1, -1), (-1.0, 1.0))


def test_docs() -> None:
    ###########################################################################
    # PLEASE UPDATE docs/advanced/cast/custom.rst IF ANY CHANGES ARE MADE HERE.
    ###########################################################################
    point1 = [1.0, -1.0]
    point2 = m.negate(point1)
    assert point2 == (-1.0, 1.0)