-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest_profiles.py
157 lines (114 loc) · 5.74 KB
/
test_profiles.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import pytest
from os import path
from pyecore.resources import ResourceSet
import pyecore.ecore as ecore
import pyuml2.types as types
import pyuml2.uml as uml
import pyuml2.standard as standard
import pyuml2.profile_utils as utils
@pytest.fixture
def rset():
rset = ResourceSet()
rset.metamodel_registry[types.nsURI] = types
rset.metamodel_registry[uml.nsURI] = uml
ecore_uri = 'http://www.eclipse.org/uml2/schemas/Ecore/5'
rset.metamodel_registry[ecore_uri] = ecore
rset.metamodel_registry[standard.nsURI] = standard
return rset
def test_class_ismetaclass(rset):
mm_file = path.join('profiles', 'UML.metamodel.uml')
uml_resource = rset.get_resource(mm_file)
uml_root = uml_resource.contents[0]
for o in uml_root.packagedElement:
if isinstance(o, uml.Class):
assert o.is_metaclass() is True
def test_package_ownedstereotype(rset):
# uml_resource = rset.get_resource('profiles/UML.metamodel.uml')
profile_file = path.join('profiles', 'Standard.profile.uml')
standard_prof_resource = rset.get_resource(profile_file)
standard_prof = standard_prof_resource.contents[0]
assert len(standard_prof.ownedStereotype) > 0
assert len(standard_prof.get_owned_stereotypes()) > 0
stereotypes = [x for x in standard_prof.packagedElement
if isinstance(x, uml.Stereotype)]
for stereotype in stereotypes:
assert stereotype in standard_prof.ownedStereotype
def test_utils_get_stereotypefromapplication(rset):
profile_file = path.join('tests', 'profiles', 'testProfile.profile.uml')
profile_resource = rset.get_resource(profile_file)
profile = profile_resource.contents[0]
static = profile.getEAnnotation(utils.UML_20_URI).contents[0]
rset.metamodel_registry[static.nsURI] = static
applied_file = path.join('tests', 'profiles', 'applied.uml')
applied_resource = rset.get_resource(applied_file)
stereotype_application = applied_resource.contents[-1]
stereotype = utils.get_stereotype_from_application(stereotype_application)
assert stereotype is profile.packagedElement[0]
def test_element_get_appliedstereotypes(rset):
profile_file = path.join('tests', 'profiles', 'testProfile.profile.uml')
profile_resource = rset.get_resource(profile_file)
profile = profile_resource.contents[0]
static = profile.getEAnnotation(utils.UML_20_URI).contents[0]
rset.metamodel_registry[static.nsURI] = static
applied_file = path.join('tests', 'profiles', 'applied.uml')
applied_resource = rset.get_resource(applied_file)
applied_root = applied_resource.contents[0]
c = applied_root.packagedElement[0]
assert len(c.get_applied_stereotypes()) == 1
stereotype = profile.packagedElement[0]
assert stereotype in c.get_applied_stereotypes()
def test_element_get_appliedstereotypes_deserialized_profile(rset):
profile_file = path.join('tests', 'profiles', 'testProfile.profile.uml')
profile_resource = rset.get_resource(profile_file)
profile = profile_resource.contents[0]
applied_file = path.join('tests', 'profiles', 'applied.uml')
applied_resource = rset.get_resource(applied_file)
applied_root = applied_resource.contents[0]
c = applied_root.packagedElement[0]
assert len(c.get_applied_stereotypes()) == 1
stereotype = profile.packagedElement[0]
assert stereotype in c.get_applied_stereotypes()
def test_element_get_appliedstereotypes_schema_location(rset):
applied_file = path.join('tests', 'profiles', 'applied.uml')
applied_resource = rset.get_resource(applied_file)
applied_root = applied_resource.contents[0]
c = applied_root.packagedElement[0]
assert len(c.get_applied_stereotypes()) == 1
stereotype = c.get_applied_stereotypes()[0]
assert stereotype.name == "FirstStereotype"
assert isinstance(stereotype, uml.Stereotype)
assert stereotype.qualifiedName == 'testProfile::FirstStereotype'
t_value = stereotype.ownedAttribute[1]
assert t_value.qualifiedName == 'testProfile::FirstStereotype::newName'
def test_element_get_appliedstereotype_qualifiedName(rset):
applied_file = path.join('tests', 'profiles', 'applied.uml')
applied_resource = rset.get_resource(applied_file)
applied_root = applied_resource.contents[0]
c = applied_root.packagedElement[0]
assert len(c.get_applied_stereotypes()) == 1
stereotype = c.get_applied_stereotype('testProfile::FirstStereotype')
assert stereotype.name == "FirstStereotype"
assert isinstance(stereotype, uml.Stereotype)
assert stereotype.qualifiedName == 'testProfile::FirstStereotype'
assert c.get_applied_stereotype('testProfile::FirstStereotypeAA') is None
def test_element_get_stereotypeapplications(rset):
profile_file = path.join('tests', 'profiles', 'testProfile.profile.uml')
profile_resource = rset.get_resource(profile_file)
profile = profile_resource.contents[0]
static = profile.getEAnnotation(utils.UML_20_URI).contents[0]
rset.metamodel_registry[static.nsURI] = static
applied_file = path.join('tests', 'profiles', 'applied.uml')
applied_resource = rset.get_resource(applied_file)
applied_root = applied_resource.contents[0]
c = applied_root.packagedElement[0]
assert len(c.get_stereotype_applications()) == 1
assert c.get_stereotype_applications()
def test_element_get_stereotypeapplications_deserialized_profile(rset):
profile_file = path.join('tests', 'profiles', 'testProfile.profile.uml')
rset.get_resource(profile_file)
applied_file = path.join('tests', 'profiles', 'applied.uml')
applied_resource = rset.get_resource(applied_file)
applied_root = applied_resource.contents[0]
c = applied_root.packagedElement[0]
assert len(c.get_stereotype_applications()) == 1
assert c.get_stereotype_applications()