1 from __future__
import annotations
8 from pybind11_tests
import ConstructorStats
9 from pybind11_tests
import modules
as m
10 from pybind11_tests.modules
import subsubmodule
as ms
16 assert pybind11_tests.__name__ ==
"pybind11_tests"
17 assert pybind11_tests.modules.__name__ ==
"pybind11_tests.modules"
19 pybind11_tests.modules.subsubmodule.__name__
20 ==
"pybind11_tests.modules.subsubmodule"
22 assert m.__name__ ==
"pybind11_tests.modules"
23 assert ms.__name__ ==
"pybind11_tests.modules.subsubmodule"
25 assert ms.submodule_func() ==
"submodule_func()"
30 assert str(b.get_a1()) ==
"A[1]"
31 assert str(b.a1) ==
"A[1]"
32 assert str(b.get_a2()) ==
"A[2]"
33 assert str(b.a2) ==
"A[2]"
37 assert str(b.get_a1()) ==
"A[42]"
38 assert str(b.a1) ==
"A[42]"
39 assert str(b.get_a2()) ==
"A[43]"
40 assert str(b.a2) ==
"A[43]"
43 assert astats.alive() == 2
44 assert bstats.alive() == 1
46 assert astats.alive() == 0
47 assert bstats.alive() == 0
48 assert astats.values() == [
"1",
"2",
"42",
"43"]
49 assert bstats.values() == []
50 assert astats.default_constructions == 0
51 assert bstats.default_constructions == 1
52 assert astats.copy_constructions == 0
53 assert bstats.copy_constructions == 0
56 assert astats.copy_assignments == 2
57 assert bstats.copy_assignments == 0
58 assert astats.move_assignments == 0
59 assert bstats.move_assignments == 0
63 from collections
import OrderedDict
65 from pybind11_tests.modules
import OD
67 assert OD
is OrderedDict
71 """Pydoc needs to be able to provide help() for everything inside a pybind11 module"""
76 assert pybind11_tests.__name__ ==
"pybind11_tests"
77 assert pybind11_tests.__doc__ ==
"pybind11 test module"
78 assert pydoc.text.docmodule(pybind11_tests)
82 """Registering two things with the same name"""
84 assert m.duplicate_registration() == []
88 """Test that all the keys in the builtin modules have type str.
90 Previous versions of pybind11 would add a unicode key in python 2.
92 assert all(
type(k) == str
for k
in dir(builtins))
95 @pytest.mark.xfail(
"env.PYPY", reason=
"PyModule_GetName()")
97 sm = m.def_submodule(m, b
"ScratchSubModuleName")
98 assert sm.__name__ == m.__name__ +
"." +
"ScratchSubModuleName"
99 malformed_utf8 = b
"\x80"
102 pytest.skip(
"Sufficiently exercised on platforms other than PyPy.")
105 sm_name_orig = sm.__name__
106 sm.__name__ = malformed_utf8
111 with pytest.raises(SystemError):
112 m.def_submodule(sm, b
"SubSubModuleName")
115 sm.__name__ = sm_name_orig
117 with pytest.raises(UnicodeDecodeError):
118 m.def_submodule(sm, malformed_utf8)