test_modules.py revision 12037
111986Sandreas.sandberg@arm.com
211986Sandreas.sandberg@arm.comdef test_nested_modules():
311986Sandreas.sandberg@arm.com    import pybind11_tests
411986Sandreas.sandberg@arm.com    from pybind11_tests.submodule import submodule_func
511986Sandreas.sandberg@arm.com
611986Sandreas.sandberg@arm.com    assert pybind11_tests.__name__ == "pybind11_tests"
711986Sandreas.sandberg@arm.com    assert pybind11_tests.submodule.__name__ == "pybind11_tests.submodule"
811986Sandreas.sandberg@arm.com
911986Sandreas.sandberg@arm.com    assert submodule_func() == "submodule_func()"
1011986Sandreas.sandberg@arm.com
1111986Sandreas.sandberg@arm.com
1211986Sandreas.sandberg@arm.comdef test_reference_internal():
1311986Sandreas.sandberg@arm.com    from pybind11_tests import ConstructorStats
1411986Sandreas.sandberg@arm.com    from pybind11_tests.submodule import A, B
1511986Sandreas.sandberg@arm.com
1611986Sandreas.sandberg@arm.com    b = B()
1711986Sandreas.sandberg@arm.com    assert str(b.get_a1()) == "A[1]"
1811986Sandreas.sandberg@arm.com    assert str(b.a1) == "A[1]"
1911986Sandreas.sandberg@arm.com    assert str(b.get_a2()) == "A[2]"
2011986Sandreas.sandberg@arm.com    assert str(b.a2) == "A[2]"
2111986Sandreas.sandberg@arm.com
2211986Sandreas.sandberg@arm.com    b.a1 = A(42)
2311986Sandreas.sandberg@arm.com    b.a2 = A(43)
2411986Sandreas.sandberg@arm.com    assert str(b.get_a1()) == "A[42]"
2511986Sandreas.sandberg@arm.com    assert str(b.a1) == "A[42]"
2611986Sandreas.sandberg@arm.com    assert str(b.get_a2()) == "A[43]"
2711986Sandreas.sandberg@arm.com    assert str(b.a2) == "A[43]"
2811986Sandreas.sandberg@arm.com
2911986Sandreas.sandberg@arm.com    astats, bstats = ConstructorStats.get(A), ConstructorStats.get(B)
3011986Sandreas.sandberg@arm.com    assert astats.alive() == 2
3111986Sandreas.sandberg@arm.com    assert bstats.alive() == 1
3211986Sandreas.sandberg@arm.com    del b
3311986Sandreas.sandberg@arm.com    assert astats.alive() == 0
3411986Sandreas.sandberg@arm.com    assert bstats.alive() == 0
3511986Sandreas.sandberg@arm.com    assert astats.values() == ['1', '2', '42', '43']
3611986Sandreas.sandberg@arm.com    assert bstats.values() == []
3711986Sandreas.sandberg@arm.com    assert astats.default_constructions == 0
3811986Sandreas.sandberg@arm.com    assert bstats.default_constructions == 1
3911986Sandreas.sandberg@arm.com    assert astats.copy_constructions == 0
4011986Sandreas.sandberg@arm.com    assert bstats.copy_constructions == 0
4111986Sandreas.sandberg@arm.com    # assert astats.move_constructions >= 0  # Don't invoke any
4211986Sandreas.sandberg@arm.com    # assert bstats.move_constructions >= 0  # Don't invoke any
4311986Sandreas.sandberg@arm.com    assert astats.copy_assignments == 2
4411986Sandreas.sandberg@arm.com    assert bstats.copy_assignments == 0
4511986Sandreas.sandberg@arm.com    assert astats.move_assignments == 0
4611986Sandreas.sandberg@arm.com    assert bstats.move_assignments == 0
4711986Sandreas.sandberg@arm.com
4811986Sandreas.sandberg@arm.com
4911986Sandreas.sandberg@arm.comdef test_importing():
5011986Sandreas.sandberg@arm.com    from pybind11_tests import OD
5111986Sandreas.sandberg@arm.com    from collections import OrderedDict
5211986Sandreas.sandberg@arm.com
5311986Sandreas.sandberg@arm.com    assert OD is OrderedDict
5411986Sandreas.sandberg@arm.com    assert str(OD([(1, 'a'), (2, 'b')])) == "OrderedDict([(1, 'a'), (2, 'b')])"
5512037Sandreas.sandberg@arm.com
5612037Sandreas.sandberg@arm.com
5712037Sandreas.sandberg@arm.comdef test_pydoc():
5812037Sandreas.sandberg@arm.com    """Pydoc needs to be able to provide help() for everything inside a pybind11 module"""
5912037Sandreas.sandberg@arm.com    import pybind11_tests
6012037Sandreas.sandberg@arm.com    import pydoc
6112037Sandreas.sandberg@arm.com
6212037Sandreas.sandberg@arm.com    assert pydoc.text.docmodule(pybind11_tests)
63