示例#1
0
def test_no_id(capture, msg):
    from pybind11_tests.issues import get_element, expect_float, expect_int

    with pytest.raises(TypeError) as excinfo:
        get_element(None)
    assert msg(excinfo.value) == """
        get_element(): incompatible function arguments. The following argument types are supported:
            1. (arg0: m.issues.ElementA) -> int

        Invoked with: None
    """

    with pytest.raises(TypeError) as excinfo:
        expect_int(5.2)
    assert msg(excinfo.value) == """
        expect_int(): incompatible function arguments. The following argument types are supported:
            1. (arg0: int) -> int

        Invoked with: 5.2
    """
    assert expect_float(12) == 12
示例#2
0
def test_no_id(msg):
    from pybind11_tests.issues import get_element, expect_float, expect_int

    with pytest.raises(TypeError) as excinfo:
        get_element(None)
    assert msg(excinfo.value) == """
        get_element(): incompatible function arguments. The following argument types are supported:
            1. (arg0: m.issues.ElementA) -> int

        Invoked with: None
    """

    with pytest.raises(TypeError) as excinfo:
        expect_int(5.2)
    assert msg(excinfo.value) == """
        expect_int(): incompatible function arguments. The following argument types are supported:
            1. (arg0: int) -> int

        Invoked with: 5.2
    """
    assert expect_float(12) == 12
示例#3
0
def test_no_id(capture, msg):
    from pybind11_tests.issues import get_element, expect_float, expect_int

    with pytest.raises(TypeError) as excinfo:
        get_element(None)
    assert msg(excinfo.value) == """
        Incompatible function arguments. The following argument types are supported:
            1. (arg0: m.issues.ElementA) -> int
            Invoked with: None
    """

    with pytest.raises(TypeError) as excinfo:
        expect_int(5.2)
    assert msg(excinfo.value) == """
        Incompatible function arguments. The following argument types are supported:
            1. (arg0: int) -> int
            Invoked with: 5.2
    """
    assert expect_float(12) == 12

    from pybind11_tests.issues import A, call_f

    class B(A):
        def __init__(self):
            super(B, self).__init__()

        def f(self):
            print("In python f()")

    # C++ version
    with capture:
        a = A()
        call_f(a)
    assert capture == "A.f()"

    # Python version
    with capture:
        b = B()
        call_f(b)
    assert capture == """