forked from kljohann/genpybind-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_hierarchy_test.py
54 lines (49 loc) · 1.68 KB
/
class_hierarchy_test.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pytest
import pyclass_hierarchy as m
def test_base():
obj = m.Base()
assert obj.from_base() is True
assert obj.overloaded(5) is True
assert obj.overloaded(5, 7) is True
assert obj.base_field == 0
obj.base_field = 42
assert obj.base_field == 42
def test_derived_public():
obj = m.DerivedPublic()
assert isinstance(obj, m.DerivedPublic)
assert isinstance(obj, m.Base)
assert obj.from_base() is True
assert obj.overloaded(5) is False
with pytest.raises(TypeError, match="incompatible function arguments"):
obj.overloaded(5, 7)
assert obj.base_field == 0
obj.base_field = 42
assert obj.base_field == 42
def test_derived_private():
obj = m.DerivedPrivate()
assert isinstance(obj, m.DerivedPrivate)
assert not isinstance(obj, m.Base)
assert not hasattr(obj, "from_base")
assert obj.overloaded(5) is False
with pytest.raises(TypeError, match="incompatible function arguments"):
obj.overloaded(5, 7)
assert not hasattr(obj, "base_field")
def test_derived_inline():
obj = m.DerivedInline()
assert isinstance(obj, m.DerivedInline)
assert not isinstance(obj, m.Base)
assert obj.from_base() is True
assert obj.overloaded(5) is False
with pytest.raises(TypeError, match="incompatible function arguments"):
obj.overloaded(5, 7)
assert obj.base_field == 0
obj.base_field = 42
assert obj.base_field == 42
def test_derived_multiple():
obj = m.DerivedMultiple()
assert isinstance(obj, m.DerivedMultiple)
assert isinstance(obj, m.Base)
assert isinstance(obj, m.OtherBase)
assert obj.base_field == 0
obj.base_field = 42
assert obj.base_field == 42