MCPcopy Create free account
hub / github.com/pybind/pybind11 / test_nested

Function test_nested

tests/test_operator_overloading.py:104–139  ·  view source on GitHub ↗

#328: first member in a class can't be used in operators

()

Source from the content-addressed store, hash-verified

102
103
104def test_nested():
105 """#328: first member in a class can't be used in operators"""
106
107 a = m.NestA()
108 b = m.NestB()
109 c = m.NestC()
110
111 a += 10
112 assert m.get_NestA(a) == 13
113 b.a += 100
114 assert m.get_NestA(b.a) == 103
115 c.b.a += 1000
116 assert m.get_NestA(c.b.a) == 1003
117 b -= 1
118 assert m.get_NestB(b) == 3
119 c.b -= 3
120 assert m.get_NestB(c.b) == 1
121 c *= 7
122 assert m.get_NestC(c) == 35
123
124 abase = a.as_base()
125 assert abase.value == -2
126 a.as_base().value += 44
127 assert abase.value == 42
128 assert c.b.a.as_base().value == -2
129 c.b.a.as_base().value += 44
130 assert c.b.a.as_base().value == 42
131
132 del c
133 pytest.gc_collect()
134 del a # Shouldn't delete while abase is still alive
135 pytest.gc_collect()
136
137 assert abase.value == 42
138 del abase, b
139 pytest.gc_collect()
140
141
142def test_overriding_eq_reset_hash():

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected