def test_inheritance(msg):
    from pybind11_tests import Pet, Dog, Rabbit, Hamster, Chimera, dog_bark, pet_name_species

    roger = Rabbit('Rabbit')
    assert roger.name() + " is a " + roger.species() == "Rabbit is a parrot"
    assert pet_name_species(roger) == "Rabbit is a parrot"

    polly = Pet('Polly', 'parrot')
    assert polly.name() + " is a " + polly.species() == "Polly is a parrot"
    assert pet_name_species(polly) == "Polly is a parrot"

    molly = Dog('Molly')
    assert molly.name() + " is a " + molly.species() == "Molly is a dog"
    assert pet_name_species(molly) == "Molly is a dog"

    fred = Hamster('Fred')
    assert fred.name() + " is a " + fred.species() == "Fred is a rodent"

    assert dog_bark(molly) == "Woof!"

    with pytest.raises(TypeError) as excinfo:
        dog_bark(polly)
    assert msg(excinfo.value) == """
        dog_bark(): incompatible function arguments. The following argument types are supported:
            1. (arg0: m.Dog) -> str

        Invoked with: <m.Pet object at 0>
    """

    with pytest.raises(TypeError) as excinfo:
        Chimera("lion", "goat")
    assert "No constructor defined!" in str(excinfo.value)
def test_isinstance():
    from pybind11_tests import test_isinstance, Pet, Dog

    objects = [tuple(), dict(), Pet("Polly", "parrot")] + [Dog("Molly")] * 4
    expected = (True, True, True, True, True, False, False)
    if test_isinstance(objects) != expected:
        raise AssertionError
Example #3
0
def test_inheritance(msg):
    from pybind11_tests import Pet, Dog, Rabbit, dog_bark, pet_name_species

    roger = Rabbit('Rabbit')
    assert roger.name() + " is a " + roger.species() == "Rabbit is a parrot"
    assert pet_name_species(roger) == "Rabbit is a parrot"

    polly = Pet('Polly', 'parrot')
    assert polly.name() + " is a " + polly.species() == "Polly is a parrot"
    assert pet_name_species(polly) == "Polly is a parrot"

    molly = Dog('Molly')
    assert molly.name() + " is a " + molly.species() == "Molly is a dog"
    assert pet_name_species(molly) == "Molly is a dog"

    assert dog_bark(molly) == "Woof!"

    with pytest.raises(TypeError) as excinfo:
        dog_bark(polly)
    assert msg(excinfo.value) == """
Example #4
0
def test_inheritance(msg):
    from pybind11_tests import Pet, Dog, Rabbit, Hamster, dog_bark, pet_name_species

    roger = Rabbit('Rabbit')
    assert roger.name() + " is a " + roger.species() == "Rabbit is a parrot"
    assert pet_name_species(roger) == "Rabbit is a parrot"

    polly = Pet('Polly', 'parrot')
    assert polly.name() + " is a " + polly.species() == "Polly is a parrot"
    assert pet_name_species(polly) == "Polly is a parrot"

    molly = Dog('Molly')
    assert molly.name() + " is a " + molly.species() == "Molly is a dog"
    assert pet_name_species(molly) == "Molly is a dog"

    fred = Hamster('Fred')
    assert fred.name() + " is a " + fred.species() == "Fred is a rodent"

    assert dog_bark(molly) == "Woof!"

    with pytest.raises(TypeError) as excinfo:
        dog_bark(polly)
    assert msg(excinfo.value) == """
def test_inheritance(msg):
    from pybind11_tests import Pet, Dog, Rabbit, Hamster, dog_bark, pet_name_species

    roger = Rabbit('Rabbit')
    if roger.name() + " is a " + roger.species() != "Rabbit is a parrot":
        raise AssertionError
    if pet_name_species(roger) != "Rabbit is a parrot":
        raise AssertionError

    polly = Pet('Polly', 'parrot')
    if polly.name() + " is a " + polly.species() != "Polly is a parrot":
        raise AssertionError
    if pet_name_species(polly) != "Polly is a parrot":
        raise AssertionError

    molly = Dog('Molly')
    if molly.name() + " is a " + molly.species() != "Molly is a dog":
        raise AssertionError
    if pet_name_species(molly) != "Molly is a dog":
        raise AssertionError

    fred = Hamster('Fred')
    if fred.name() + " is a " + fred.species() != "Fred is a rodent":
        raise AssertionError

    if dog_bark(molly) != "Woof!":
        raise AssertionError

    with pytest.raises(TypeError) as excinfo:
        dog_bark(polly)
    if msg(excinfo.value) != """
        dog_bark(): incompatible function arguments. The following argument types are supported:
            1. (arg0: m.Dog) -> str

        Invoked with: <m.Pet object at 0>
    """:
        raise AssertionError