test_modules.py revision 12037
1 2def test_nested_modules(): 3 import pybind11_tests 4 from pybind11_tests.submodule import submodule_func 5 6 assert pybind11_tests.__name__ == "pybind11_tests" 7 assert pybind11_tests.submodule.__name__ == "pybind11_tests.submodule" 8 9 assert submodule_func() == "submodule_func()" 10 11 12def test_reference_internal(): 13 from pybind11_tests import ConstructorStats 14 from pybind11_tests.submodule import A, B 15 16 b = B() 17 assert str(b.get_a1()) == "A[1]" 18 assert str(b.a1) == "A[1]" 19 assert str(b.get_a2()) == "A[2]" 20 assert str(b.a2) == "A[2]" 21 22 b.a1 = A(42) 23 b.a2 = A(43) 24 assert str(b.get_a1()) == "A[42]" 25 assert str(b.a1) == "A[42]" 26 assert str(b.get_a2()) == "A[43]" 27 assert str(b.a2) == "A[43]" 28 29 astats, bstats = ConstructorStats.get(A), ConstructorStats.get(B) 30 assert astats.alive() == 2 31 assert bstats.alive() == 1 32 del b 33 assert astats.alive() == 0 34 assert bstats.alive() == 0 35 assert astats.values() == ['1', '2', '42', '43'] 36 assert bstats.values() == [] 37 assert astats.default_constructions == 0 38 assert bstats.default_constructions == 1 39 assert astats.copy_constructions == 0 40 assert bstats.copy_constructions == 0 41 # assert astats.move_constructions >= 0 # Don't invoke any 42 # assert bstats.move_constructions >= 0 # Don't invoke any 43 assert astats.copy_assignments == 2 44 assert bstats.copy_assignments == 0 45 assert astats.move_assignments == 0 46 assert bstats.move_assignments == 0 47 48 49def test_importing(): 50 from pybind11_tests import OD 51 from collections import OrderedDict 52 53 assert OD is OrderedDict 54 assert str(OD([(1, 'a'), (2, 'b')])) == "OrderedDict([(1, 'a'), (2, 'b')])" 55 56 57def test_pydoc(): 58 """Pydoc needs to be able to provide help() for everything inside a pybind11 module""" 59 import pybind11_tests 60 import pydoc 61 62 assert pydoc.text.docmodule(pybind11_tests) 63