| 195 | |
| 196 | |
| 197 | def 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 | |
| 232 | def test_inheritance_init(msg): |