blob: b55490cf6eadc2575d7751381ce363862022ebc4 [file] [log] [blame]
Dean Moldovan382db5b2016-08-13 00:37:50 +02001import pytest
2
3
4def test_inheritance(msg):
5 from pybind11_tests import Pet, Dog, Rabbit, dog_bark, pet_name_species
6
7 roger = Rabbit('Rabbit')
8 assert roger.name() + " is a " + roger.species() == "Rabbit is a parrot"
9 assert pet_name_species(roger) == "Rabbit is a parrot"
10
11 polly = Pet('Polly', 'parrot')
12 assert polly.name() + " is a " + polly.species() == "Polly is a parrot"
13 assert pet_name_species(polly) == "Polly is a parrot"
14
15 molly = Dog('Molly')
16 assert molly.name() + " is a " + molly.species() == "Molly is a dog"
17 assert pet_name_species(molly) == "Molly is a dog"
18
19 assert dog_bark(molly) == "Woof!"
20
21 with pytest.raises(TypeError) as excinfo:
22 dog_bark(polly)
23 assert msg(excinfo.value) == """
24 Incompatible function arguments. The following argument types are supported:
25 1. (arg0: m.Dog) -> str
26 Invoked with: <m.Pet object at 0>
27 """
Dean Moldovana0c1ccf2016-08-12 13:50:00 +020028
29
30def test_automatic_upcasting():
31 from pybind11_tests import return_class_1, return_class_2, return_none
32
33 assert type(return_class_1()).__name__ == "DerivedClass1"
34 assert type(return_class_2()).__name__ == "DerivedClass2"
35 assert type(return_none()).__name__ == "NoneType"