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

Function test_inheritance

tests/test_class.py:197–229  ·  view source on GitHub ↗
(msg)

Source from the content-addressed store, hash-verified

195
196
197def test_inheritance(msg):
198 roger = m.Rabbit("Rabbit")
199 assert roger.name() + " is a " + roger.species() == "Rabbit is a parrot"
200 assert m.pet_name_species(roger) == "Rabbit is a parrot"
201
202 polly = m.Pet("Polly", "parrot")
203 assert polly.name() + " is a " + polly.species() == "Polly is a parrot"
204 assert m.pet_name_species(polly) == "Polly is a parrot"
205
206 molly = m.Dog("Molly")
207 assert molly.name() + " is a " + molly.species() == "Molly is a dog"
208 assert m.pet_name_species(molly) == "Molly is a dog"
209
210 fred = m.Hamster("Fred")
211 assert fred.name() + " is a " + fred.species() == "Fred is a rodent"
212
213 assert m.dog_bark(molly) == "Woof!"
214
215 with pytest.raises(TypeError) as excinfo:
216 m.dog_bark(polly)
217 assert (
218 msg(excinfo.value)
219 == """
220 dog_bark(): incompatible function arguments. The following argument types are supported:
221 1. (arg0: m.class_.Dog) -> str
222
223 Invoked with: <m.class_.Pet object at 0>
224 """
225 )
226
227 with pytest.raises(TypeError) as excinfo:
228 m.Chimera("lion", "goat")
229 assert "No constructor defined!" in str(excinfo.value)
230
231
232def test_inheritance_init(msg):

Callers

nothing calls this directly

Calls 9

nameMethod · 0.95
speciesMethod · 0.95
msgFunction · 0.85
strClass · 0.85
RabbitMethod · 0.80
HamsterMethod · 0.80
ChimeraMethod · 0.80
PetMethod · 0.45
DogMethod · 0.45

Tested by

no test coverage detected