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


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:46:03