Tests py::init_factory() wrapper with various upcasting and downcasting returns
()
| 106 | |
| 107 | @pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC") |
| 108 | def test_init_factory_casting(): |
| 109 | """Tests py::init_factory() wrapper with various upcasting and downcasting returns""" |
| 110 | |
| 111 | cstats = [ |
| 112 | ConstructorStats.get(c) |
| 113 | for c in [m.TestFactory3, m.TestFactory4, m.TestFactory5] |
| 114 | ] |
| 115 | cstats[0].alive() # force gc |
| 116 | n_inst = ConstructorStats.detail_reg_inst() |
| 117 | |
| 118 | # Construction from derived references: |
| 119 | a = m.TestFactory3(tag.pointer, tag.TF4, 4) |
| 120 | assert a.value == "4" |
| 121 | b = m.TestFactory3(tag.shared_ptr, tag.TF4, 5) |
| 122 | assert b.value == "5" |
| 123 | c = m.TestFactory3(tag.pointer, tag.TF5, 6) |
| 124 | assert c.value == "6" |
| 125 | d = m.TestFactory3(tag.shared_ptr, tag.TF5, 7) |
| 126 | assert d.value == "7" |
| 127 | |
| 128 | assert ConstructorStats.detail_reg_inst() == n_inst + 4 |
| 129 | |
| 130 | # Shared a lambda with TF3: |
| 131 | e = m.TestFactory4(tag.pointer, tag.TF4, 8) |
| 132 | assert e.value == "8" |
| 133 | |
| 134 | assert ConstructorStats.detail_reg_inst() == n_inst + 5 |
| 135 | assert [i.alive() for i in cstats] == [5, 3, 2] |
| 136 | |
| 137 | del a |
| 138 | assert [i.alive() for i in cstats] == [4, 2, 2] |
| 139 | assert ConstructorStats.detail_reg_inst() == n_inst + 4 |
| 140 | |
| 141 | del b, c, e |
| 142 | assert [i.alive() for i in cstats] == [1, 0, 1] |
| 143 | assert ConstructorStats.detail_reg_inst() == n_inst + 1 |
| 144 | |
| 145 | del d |
| 146 | assert [i.alive() for i in cstats] == [0, 0, 0] |
| 147 | assert ConstructorStats.detail_reg_inst() == n_inst |
| 148 | |
| 149 | assert [i.values() for i in cstats] == [ |
| 150 | ["4", "5", "6", "7", "8"], |
| 151 | ["4", "5", "8"], |
| 152 | ["6", "7"], |
| 153 | ] |
| 154 | |
| 155 | |
| 156 | @pytest.mark.skipif("env.GRAALPY", reason="Cannot reliably trigger GC") |
nothing calls this directly
no test coverage detected