-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathtest_hierarchy_traveling.py
78 lines (66 loc) · 2.26 KB
/
test_hierarchy_traveling.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Copyright 2014-2017 Insight Software Consortium.
# Copyright 2004-2009 Roman Yakovenko.
# Distributed under the Boost Software License, Version 1.0.
# See http://www.boost.org/LICENSE_1_0.txt
import os
from . import autoconfig
from pygccxml import parser
from pygccxml import declarations
__code = os.linesep.join([
'struct a{};',
'struct b{};',
'struct c{};',
'struct d : public a{};',
'struct e : public a, public b{};',
'struct f{};',
'struct g : public d, public f{};',
'struct h : public f{};',
'struct i : public h, public g{};'])
__recursive_bases = {
'a': set(),
'b': set(),
'c': set(),
'd': {'a'},
'e': {'a', 'b'},
'f': set(),
'g': {'d', 'f', 'a'},
'h': {'f'},
'i': {'h', 'g', 'd', 'f', 'a'}}
__recursive_derived = {
'a': {'d', 'e', 'g', 'i'},
'b': {'e'},
'c': set(),
'd': {'g', 'i'},
'e': set(),
'f': {'g', 'h', 'i'},
'g': {'i'},
'h': {'i'},
'i': set()}
def test_recursive_bases():
config = autoconfig.cxx_parsers_cfg.config.clone()
src_reader = parser.source_reader_t(config)
decls = declarations.make_flatten(src_reader.read_string(__code))
classes = [
inst for inst in decls if isinstance(inst, declarations.class_t)]
for class_ in classes:
assert class_.name in __recursive_bases
all_bases = class_.recursive_bases
control_bases = __recursive_bases[class_.name]
assert len(control_bases) == len(all_bases)
all_bases_names = [hi.related_class.name for hi in all_bases]
assert set(all_bases_names) == control_bases
def test_recursive_derived():
config = autoconfig.cxx_parsers_cfg.config.clone()
src_reader = parser.source_reader_t(config)
decls = declarations.make_flatten(src_reader.read_string(__code))
classes = [
inst for inst in decls if isinstance(
inst,
declarations.class_t)]
for class_ in classes:
assert class_.name in __recursive_derived
all_derived = class_.recursive_derived
control_derived = __recursive_derived[class_.name]
assert len(control_derived) == len(all_derived)
all_derived_names = [hi.related_class.name for hi in all_derived]
assert set(all_derived_names) == control_derived