File: test_class_sh_factory_constructors.py

package info (click to toggle)
pybind11 3.0.1-1
  • 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 (53 lines) | stat: -rw-r--r-- 1,465 bytes parent folder | download
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
41
42
43
44
45
46
47
48
49
50
51
52
53
from __future__ import annotations

import pytest

from pybind11_tests import class_sh_factory_constructors as m


def test_atyp_factories():
    assert m.atyp_valu().get_mtxt() == "Valu"
    assert m.atyp_rref().get_mtxt() == "Rref"
    # sert m.atyp_cref().get_mtxt() == "Cref"
    # sert m.atyp_mref().get_mtxt() == "Mref"
    # sert m.atyp_cptr().get_mtxt() == "Cptr"
    assert m.atyp_mptr().get_mtxt() == "Mptr"
    assert m.atyp_shmp().get_mtxt() == "Shmp"
    assert m.atyp_shcp().get_mtxt() == "Shcp"
    assert m.atyp_uqmp().get_mtxt() == "Uqmp"
    assert m.atyp_uqcp().get_mtxt() == "Uqcp"
    assert m.atyp_udmp().get_mtxt() == "Udmp"
    assert m.atyp_udcp().get_mtxt() == "Udcp"


@pytest.mark.parametrize(
    ("init_args", "expected"),
    [
        ((3,), 300),
        ((5, 7), 570),
        ((9, 11, 13), 1023),
    ],
)
def test_with_alias_success(init_args, expected):
    assert m.with_alias(*init_args).val == expected


@pytest.mark.parametrize(
    ("num_init_args", "smart_ptr"),
    [
        (4, "std::unique_ptr"),
        (5, "std::shared_ptr"),
    ],
)
def test_with_alias_invalid(num_init_args, smart_ptr):
    class PyDrvdWithAlias(m.with_alias):
        pass

    with pytest.raises(TypeError) as excinfo:
        PyDrvdWithAlias(*((0,) * num_init_args))
    assert (
        str(excinfo.value)
        == "pybind11::init(): construction failed: returned "
        + smart_ptr
        + " pointee is not an alias instance"
    )