forked from kljohann/genpybind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase-classes_test.py
59 lines (47 loc) · 1.84 KB
/
base-classes_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
55
56
57
58
59
# SPDX-FileCopyrightText: 2024 Johann Klähn <[email protected]>
#
# SPDX-License-Identifier: MIT
import base_classes as m
from helpers import get_user_mro
def test_classes_are_present():
for name in [
"Base",
"CRTP_DerivedCRTP_",
"Derived",
"DerivedCRTP",
"DerivedFromHidden",
"DerivedPrivate",
"DerivedProtected",
]:
assert hasattr(m, name)
assert not hasattr(m, "Hidden")
def test_mro():
assert get_user_mro(m.Derived) == [m.Derived, m.Base]
assert get_user_mro(m.DerivedCRTP) == [m.DerivedCRTP, m.CRTP_DerivedCRTP_]
assert get_user_mro(m.DerivedPrivate) == [m.DerivedPrivate]
assert get_user_mro(m.DerivedProtected) == [m.DerivedProtected]
def test_isinstance():
derived = m.Derived()
assert isinstance(derived, m.Derived)
assert isinstance(derived, m.Base)
assert not isinstance(derived, m.DerivedCRTP)
assert not isinstance(derived, m.CRTP_DerivedCRTP_)
derived_crtp = m.DerivedCRTP()
assert not isinstance(derived_crtp, m.Derived)
assert not isinstance(derived_crtp, m.Base)
assert isinstance(derived_crtp, m.DerivedCRTP)
assert isinstance(derived_crtp, m.CRTP_DerivedCRTP_)
derived_private = m.DerivedPrivate()
assert not isinstance(derived_private, m.Base)
assert isinstance(derived_private, m.DerivedPrivate)
derived_protected = m.DerivedProtected()
assert not isinstance(derived_protected, m.Base)
assert isinstance(derived_protected, m.DerivedProtected)
def test_can_be_derived_from_abstract_base():
inst = m.DerivedFromAbstract()
assert isinstance(inst, m.Abstract)
assert inst.abstract() == 7
assert inst.defined_in_base() == 5
assert inst.overridden() is True
assert m.Abstract.static_method() == m.DerivedFromAbstract.static_method()
assert m.Abstract.static_method() is True