Scarab  v2.9.0
Project 8 C++ Utility Library
test_modules.py
Go to the documentation of this file.
1 from pybind11_tests import modules as m
2 from pybind11_tests.modules import subsubmodule as ms
3 from pybind11_tests import ConstructorStats
4 
5 
7  import pybind11_tests
8  assert pybind11_tests.__name__ == "pybind11_tests"
9  assert pybind11_tests.modules.__name__ == "pybind11_tests.modules"
10  assert pybind11_tests.modules.subsubmodule.__name__ == "pybind11_tests.modules.subsubmodule"
11  assert m.__name__ == "pybind11_tests.modules"
12  assert ms.__name__ == "pybind11_tests.modules.subsubmodule"
13 
14  assert ms.submodule_func() == "submodule_func()"
15 
16 
18  b = ms.B()
19  assert str(b.get_a1()) == "A[1]"
20  assert str(b.a1) == "A[1]"
21  assert str(b.get_a2()) == "A[2]"
22  assert str(b.a2) == "A[2]"
23 
24  b.a1 = ms.A(42)
25  b.a2 = ms.A(43)
26  assert str(b.get_a1()) == "A[42]"
27  assert str(b.a1) == "A[42]"
28  assert str(b.get_a2()) == "A[43]"
29  assert str(b.a2) == "A[43]"
30 
31  astats, bstats = ConstructorStats.get(ms.A), ConstructorStats.get(ms.B)
32  assert astats.alive() == 2
33  assert bstats.alive() == 1
34  del b
35  assert astats.alive() == 0
36  assert bstats.alive() == 0
37  assert astats.values() == ['1', '2', '42', '43']
38  assert bstats.values() == []
39  assert astats.default_constructions == 0
40  assert bstats.default_constructions == 1
41  assert astats.copy_constructions == 0
42  assert bstats.copy_constructions == 0
43  # assert astats.move_constructions >= 0 # Don't invoke any
44  # assert bstats.move_constructions >= 0 # Don't invoke any
45  assert astats.copy_assignments == 2
46  assert bstats.copy_assignments == 0
47  assert astats.move_assignments == 0
48  assert bstats.move_assignments == 0
49 
50 
52  from pybind11_tests.modules import OD
53  from collections import OrderedDict
54 
55  assert OD is OrderedDict
56  assert str(OD([(1, 'a'), (2, 'b')])) == "OrderedDict([(1, 'a'), (2, 'b')])"
57 
58 
59 def test_pydoc():
60  """Pydoc needs to be able to provide help() for everything inside a pybind11 module"""
61  import pybind11_tests
62  import pydoc
63 
64  assert pybind11_tests.__name__ == "pybind11_tests"
65  assert pybind11_tests.__doc__ == "pybind11 test module"
66  assert pydoc.text.docmodule(pybind11_tests)
67 
68 
70  """Registering two things with the same name"""
71 
72  assert m.duplicate_registration() == []
static ConstructorStats & get(std::type_index type)
def test_importing()
Definition: test_modules.py:51
def test_reference_internal()
Definition: test_modules.py:17
def test_nested_modules()
Definition: test_modules.py:6
def test_pydoc()
Definition: test_modules.py:59
def test_duplicate_registration()
Definition: test_modules.py:69
return os str()