4 from pybind11_tests
import ConstructorStats
5 from pybind11_tests
import modules
as m
6 from pybind11_tests.modules
import subsubmodule
as ms
12 assert pybind11_tests.__name__ ==
"pybind11_tests" 13 assert pybind11_tests.modules.__name__ ==
"pybind11_tests.modules" 15 pybind11_tests.modules.subsubmodule.__name__
16 ==
"pybind11_tests.modules.subsubmodule" 18 assert m.__name__ ==
"pybind11_tests.modules" 19 assert ms.__name__ ==
"pybind11_tests.modules.subsubmodule" 21 assert ms.submodule_func() ==
"submodule_func()" 26 assert str(b.get_a1()) ==
"A[1]" 27 assert str(b.a1) ==
"A[1]" 28 assert str(b.get_a2()) ==
"A[2]" 29 assert str(b.a2) ==
"A[2]" 33 assert str(b.get_a1()) ==
"A[42]" 34 assert str(b.a1) ==
"A[42]" 35 assert str(b.get_a2()) ==
"A[43]" 36 assert str(b.a2) ==
"A[43]" 39 assert astats.alive() == 2
40 assert bstats.alive() == 1
42 assert astats.alive() == 0
43 assert bstats.alive() == 0
44 assert astats.values() == [
"1",
"2",
"42",
"43"]
45 assert bstats.values() == []
46 assert astats.default_constructions == 0
47 assert bstats.default_constructions == 1
48 assert astats.copy_constructions == 0
49 assert bstats.copy_constructions == 0
52 assert astats.copy_assignments == 2
53 assert bstats.copy_assignments == 0
54 assert astats.move_assignments == 0
55 assert bstats.move_assignments == 0
59 from collections
import OrderedDict
61 from pybind11_tests.modules
import OD
63 assert OD
is OrderedDict
64 assert str(OD([(1,
"a"), (2,
"b")])) ==
"OrderedDict([(1, 'a'), (2, 'b')])" 68 """Pydoc needs to be able to provide help() for everything inside a pybind11 module""" 73 assert pybind11_tests.__name__ ==
"pybind11_tests" 74 assert pybind11_tests.__doc__ ==
"pybind11 test module" 75 assert pydoc.text.docmodule(pybind11_tests)
79 """Registering two things with the same name""" 81 assert m.duplicate_registration() == []
85 """Test that all the keys in the builtin modules have type str. 87 Previous versions of pybind11 would add a unicode key in python 2. 89 if hasattr(__builtins__,
"keys"):
90 keys = __builtins__.keys()
92 keys = __builtins__.__dict__.keys()
94 assert {
type(k)
for k
in keys} == {str}
97 @pytest.mark.xfail(
"env.PYPY", reason=
"PyModule_GetName()")
99 sm = m.def_submodule(m, b
"ScratchSubModuleName")
100 assert sm.__name__ == m.__name__ +
"." +
"ScratchSubModuleName" 101 malformed_utf8 = b
"\x80" 104 pytest.skip(
"Sufficiently exercised on platforms other than PyPy.")
107 sm_name_orig = sm.__name__
108 sm.__name__ = malformed_utf8
110 with pytest.raises(Exception):
115 m.def_submodule(sm, b
"SubSubModuleName")
118 sm.__name__ = sm_name_orig
120 with pytest.raises(UnicodeDecodeError):
121 m.def_submodule(sm, malformed_utf8)
bool hasattr(handle obj, handle name)
def test_reference_internal()
def test_def_submodule_failures()
static ConstructorStats & get(std::type_index type)
def test_nested_modules()
def test_duplicate_registration()
def test_builtin_key_type()