Dean Moldovan | a0c1ccf | 2016-08-12 13:50:00 +0200 | [diff] [blame] | 1 | |
Dean Moldovan | 665e880 | 2016-08-12 22:28:31 +0200 | [diff] [blame] | 2 | def test_nested_modules(): |
Dean Moldovan | a0c1ccf | 2016-08-12 13:50:00 +0200 | [diff] [blame] | 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 | |
Dean Moldovan | 665e880 | 2016-08-12 22:28:31 +0200 | [diff] [blame] | 9 | assert submodule_func() == "submodule_func()" |
Dean Moldovan | a0c1ccf | 2016-08-12 13:50:00 +0200 | [diff] [blame] | 10 | |
| 11 | |
| 12 | def 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 | |
| 49 | def 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')])" |
Dean Moldovan | 1769ea4 | 2017-03-15 15:38:14 +0100 | [diff] [blame] | 55 | |
| 56 | |
| 57 | def 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 | |
Dean Moldovan | 83e328f | 2017-06-09 00:44:49 +0200 | [diff] [blame] | 62 | assert pybind11_tests.__name__ == "pybind11_tests" |
Dean Moldovan | 443ab59 | 2017-04-24 01:51:44 +0200 | [diff] [blame] | 63 | assert pybind11_tests.__doc__ == "pybind11 test module" |
Dean Moldovan | 1769ea4 | 2017-03-15 15:38:14 +0100 | [diff] [blame] | 64 | assert pydoc.text.docmodule(pybind11_tests) |
Dean Moldovan | bdfb50f | 2017-06-07 16:52:50 +0200 | [diff] [blame] | 65 | |
| 66 | |
| 67 | def test_duplicate_registration(): |
| 68 | """Registering two things with the same name""" |
| 69 | from pybind11_tests import duplicate_registration |
| 70 | |
| 71 | assert duplicate_registration() == [] |