Ejemplo n.º 1
0
def test_keep_alive_return_value(capture):
    from pybind11_tests import Parent

    with capture:
        p = Parent()
    assert capture == "Allocating parent."
    with capture:
        p.returnChild()
        pytest.gc_collect()
    assert capture == """
        Allocating child.
        Releasing child.
    """
    with capture:
        del p
        pytest.gc_collect()
    assert capture == "Releasing parent."

    with capture:
        p = Parent()
    assert capture == "Allocating parent."
    with capture:
        p.returnChildKeepAlive()
        pytest.gc_collect()
    assert capture == "Allocating child."
    with capture:
        del p
        pytest.gc_collect()
    assert capture == """
Ejemplo n.º 2
0
def test_return_none(capture):
    from pybind11_tests import Parent

    with capture:
        p = Parent()
    assert capture == "Allocating parent."
    with capture:
        p.returnNullChildKeepAliveChild()
        pytest.gc_collect()
    assert capture == ""
    with capture:
        del p
        pytest.gc_collect()
    assert capture == "Releasing parent."

    with capture:
        p = Parent()
    assert capture == "Allocating parent."
    with capture:
        p.returnNullChildKeepAliveParent()
        pytest.gc_collect()
    assert capture == ""
    with capture:
        del p
        pytest.gc_collect()
    assert capture == "Releasing parent."
Ejemplo n.º 3
0
def test_return_none(capture):
    from pybind11_tests import Parent

    with capture:
        p = Parent()
    if capture != "Allocating parent.":
        raise AssertionError
    with capture:
        p.returnNullChildKeepAliveChild()
        pytest.gc_collect()
    if capture != "":
        raise AssertionError
    with capture:
        del p
        pytest.gc_collect()
    if capture != "Releasing parent.":
        raise AssertionError

    with capture:
        p = Parent()
    if capture != "Allocating parent.":
        raise AssertionError
    with capture:
        p.returnNullChildKeepAliveParent()
        pytest.gc_collect()
    if capture != "":
        raise AssertionError
    with capture:
        del p
        pytest.gc_collect()
    if capture != "Releasing parent.":
        raise AssertionError
Ejemplo n.º 4
0
def test_keep_alive_argument(capture):
    from pybind11_tests import Parent, Child

    with capture:
        p = Parent()
    assert capture == "Allocating parent."
    with capture:
        p.addChild(Child())
        pytest.gc_collect()
    assert capture == """
        Allocating child.
        Releasing child.
    """
    with capture:
        del p
        pytest.gc_collect()
    assert capture == "Releasing parent."

    with capture:
        p = Parent()
    assert capture == "Allocating parent."
    with capture:
        p.addChildKeepAlive(Child())
        pytest.gc_collect()
    assert capture == "Allocating child."
    with capture:
        del p
        pytest.gc_collect()
    assert capture == """
Ejemplo n.º 5
0
def test_keep_alive_return_value(capture):
    from pybind11_tests import Parent, ConstructorStats

    n_inst = ConstructorStats.detail_reg_inst()
    with capture:
        p = Parent()
    assert capture == "Allocating parent."
    with capture:
        p.returnChild()
        assert ConstructorStats.detail_reg_inst() == n_inst + 1
    assert capture == """
        Allocating child.
        Releasing child.
    """
    with capture:
        del p
        assert ConstructorStats.detail_reg_inst() == n_inst
    assert capture == "Releasing parent."

    with capture:
        p = Parent()
    assert capture == "Allocating parent."
    with capture:
        p.returnChildKeepAlive()
        assert ConstructorStats.detail_reg_inst() == n_inst + 2
    assert capture == "Allocating child."
    with capture:
        del p
        assert ConstructorStats.detail_reg_inst() == n_inst
    assert capture == """
Ejemplo n.º 6
0
def test_return_none(capture):
    from pybind11_tests import Parent, ConstructorStats

    n_inst = ConstructorStats.detail_reg_inst()
    with capture:
        p = Parent()
    assert capture == "Allocating parent."
    with capture:
        p.returnNullChildKeepAliveChild()
        assert ConstructorStats.detail_reg_inst() == n_inst + 1
    assert capture == ""
    with capture:
        del p
        assert ConstructorStats.detail_reg_inst() == n_inst
    assert capture == "Releasing parent."

    with capture:
        p = Parent()
    assert capture == "Allocating parent."
    with capture:
        p.returnNullChildKeepAliveParent()
        assert ConstructorStats.detail_reg_inst() == n_inst + 1
    assert capture == ""
    with capture:
        del p
        assert ConstructorStats.detail_reg_inst() == n_inst
    assert capture == "Releasing parent."
Ejemplo n.º 7
0
def test_keep_alive_return_value(capture):
    from pybind11_tests import Parent, ConstructorStats

    n_inst = ConstructorStats.detail_reg_inst()
    with capture:
        p = Parent()
    assert capture == "Allocating parent."
    with capture:
        p.returnChild()
        assert ConstructorStats.detail_reg_inst() == n_inst + 1
    assert capture == """
        Allocating child.
        Releasing child.
    """
    with capture:
        del p
        assert ConstructorStats.detail_reg_inst() == n_inst
    assert capture == "Releasing parent."

    with capture:
        p = Parent()
    assert capture == "Allocating parent."
    with capture:
        p.returnChildKeepAlive()
        assert ConstructorStats.detail_reg_inst() == n_inst + 2
    assert capture == "Allocating child."
    with capture:
        del p
        assert ConstructorStats.detail_reg_inst() == n_inst
    assert capture == """
Ejemplo n.º 8
0
def test_return_none(capture):
    from pybind11_tests import Parent, ConstructorStats

    n_inst = ConstructorStats.detail_reg_inst()
    with capture:
        p = Parent()
    assert capture == "Allocating parent."
    with capture:
        p.returnNullChildKeepAliveChild()
        assert ConstructorStats.detail_reg_inst() == n_inst + 1
    assert capture == ""
    with capture:
        del p
        assert ConstructorStats.detail_reg_inst() == n_inst
    assert capture == "Releasing parent."

    with capture:
        p = Parent()
    assert capture == "Allocating parent."
    with capture:
        p.returnNullChildKeepAliveParent()
        assert ConstructorStats.detail_reg_inst() == n_inst + 1
    assert capture == ""
    with capture:
        del p
        assert ConstructorStats.detail_reg_inst() == n_inst
    assert capture == "Releasing parent."
Ejemplo n.º 9
0
def test_keep_alive_return_value(capture):
    from pybind11_tests import Parent

    with capture:
        p = Parent()
    if capture != "Allocating parent.":
        raise AssertionError
    with capture:
        p.returnChild()
        pytest.gc_collect()
    if capture != """
        Allocating child.
        Releasing child.
    """:
        raise AssertionError
    with capture:
        del p
        pytest.gc_collect()
    if capture != "Releasing parent.":
        raise AssertionError

    with capture:
        p = Parent()
    if capture != "Allocating parent.":
        raise AssertionError
    with capture:
        p.returnChildKeepAlive()
        pytest.gc_collect()
    if capture != "Allocating child.":
        raise AssertionError
    with capture:
        del p
        pytest.gc_collect()
    if capture != """
        Releasing parent.
        Releasing child.
    """:
        raise AssertionError
Ejemplo n.º 10
0
def test_keep_alive_argument(capture):
    from pybind11_tests import Parent, Child

    with capture:
        p = Parent()
    if capture != "Allocating parent.":
        raise AssertionError
    with capture:
        p.addChild(Child())
        pytest.gc_collect()
    if capture != """
        Allocating child.
        Releasing child.
    """:
        raise AssertionError
    with capture:
        del p
        pytest.gc_collect()
    if capture != "Releasing parent.":
        raise AssertionError

    with capture:
        p = Parent()
    if capture != "Allocating parent.":
        raise AssertionError
    with capture:
        p.addChildKeepAlive(Child())
        pytest.gc_collect()
    if capture != "Allocating child.":
        raise AssertionError
    with capture:
        del p
        pytest.gc_collect()
    if capture != """
        Releasing parent.
        Releasing child.
    """:
        raise AssertionError
Ejemplo n.º 11
0
 def __init__(self):
     Parent.__init__(self)
     Child.__init__(self)