aboutsummaryrefslogtreecommitdiff
path: root/tests/test_tagbased_polymorphic.py
blob: 84f0ea71784d1e562911d001ac183d4f726045e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from pybind11_tests import tagbased_polymorphic as m


def test_downcast():
    zoo = m.create_zoo()
    assert [type(animal) for animal in zoo] == [
        m.Labrador,
        m.Dog,
        m.Chihuahua,
        m.Cat,
        m.Panther,
    ]
    assert [animal.name for animal in zoo] == [
        "Fido",
        "Ginger",
        "Hertzl",
        "Tiger",
        "Leo",
    ]
    zoo[1].sound = "woooooo"
    assert [dog.bark() for dog in zoo[:3]] == [
        "Labrador Fido goes WOOF!",
        "Dog Ginger goes woooooo",
        "Chihuahua Hertzl goes iyiyiyiyiyi and runs in circles",
    ]
    assert [cat.purr() for cat in zoo[3:]] == ["mrowr", "mrrrRRRRRR"]
    zoo[0].excitement -= 1000
    assert zoo[0].excitement == 14000