-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_ATE_Converter.py
More file actions
399 lines (364 loc) · 28.1 KB
/
test_ATE_Converter.py
File metadata and controls
399 lines (364 loc) · 28.1 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
import unittest
import sys
import os
#getting the name of the directory where this file is
current = os.path.dirname(os.path.realpath(__file__))
#getting the parent directory name where the current directory is
parent = os.path.dirname(current)
#adding the parent directory to the sys.path.
sys.path.append(parent)
from AstToEcoreConverter import ProjectEcoreGraph
from pyecore.resources import ResourceSet
from NodeFeatures import NodeTypes
from test_utils import check_path_exists
# puts xmi files when
test_output_dir = 'test_results/unit_tests'
class TestATEConv(unittest.TestCase):
def test_package(self):
"""
Unit test recovered by hand.
in Dir 'test_package' is a Dir named 'my_package'
I do not know why she named it this way :(
If this testcase fail, remove tests/unit_tests/test_package/my_package/.gitkeep
"""
repo = 'unit_tests/test_package'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(len(ecore_graph.packages), 1, 'wrong number of packages')
self.assertEqual(ecore_graph.packages[0].eClass.name, NodeTypes.PACKAGE.value, 'package is wrong type')
self.assertEqual(ecore_graph.packages[0].tName, 'my_package', 'wrong package name')
self.assertEqual(len(ecore_graph.packages[0].subpackages), 0, 'package should not have subpackage')
self.assertEqual(len(ecore_graph.modules), 0, 'wrong number of modules')
self.assertEqual(len(ecore_graph.classes), 0, 'wrong number of classes')
self.assertEqual(len(ecore_graph.methods), 0, 'wrong number of methods')
def test_subpackage(self):
"""
Unit test recovered by hand.
in Dir 'test_subpackage' is a Dir named 'parent' is a Dir named 'child'
I do not know why she named it this way :(
If this testcase fail, remove tests/unit_tests/test_subpackage/parent/child/.gitkeep
"""
repo = 'unit_tests/test_subpackage'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(len(ecore_graph.packages), 1, 'wrong number of packages')
self.assertEqual(ecore_graph.packages[0].tName, 'parent', 'wrong package name')
self.assertEqual(ecore_graph.packages[0].eClass.name, NodeTypes.PACKAGE.value, 'package is wrong type')
self.assertEqual(ecore_graph.packages[0].subpackages[0].tName, 'child', 'wrong submodule name')
self.assertEqual(ecore_graph.packages[0].subpackages[0].eClass.name, NodeTypes.PACKAGE.value, 'package is wrong type')
self.assertEqual(len(ecore_graph.modules), 0, 'wrong number of modules')
self.assertEqual(len(ecore_graph.classes), 0, 'wrong number of classes')
self.assertEqual(len(ecore_graph.methods), 0, 'wrong number of methods')
def test_module(self):
repo = 'unit_tests/test_module'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False,test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(len(ecore_graph.modules), 1, 'wrong number of modules')
self.assertEqual(ecore_graph.modules[0].eClass.name, NodeTypes.MODULE.value, 'module is wrong type')
self.assertEqual(ecore_graph.modules[0].location, 'unit_tests/test_module/my_module', 'wrong module location')
self.assertIsNone(ecore_graph.modules[0].namespace, 'namespace should be empty')
self.assertEqual(len(ecore_graph.modules[0].contains), 0, 'module should not contain any')
def test_multiple_modules(self):
repo = 'unit_tests/test_multiple_modules'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False,test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(len(ecore_graph.modules), 2, 'wrong number of modules')
self.assertEqual(ecore_graph.modules[0].eClass.name, NodeTypes.MODULE.value, 'module is wrong type')
self.assertEqual(ecore_graph.modules[0].location, 'unit_tests/test_multiple_modules/first_module', 'wrong module location')
self.assertIsNone(ecore_graph.modules[0].namespace, 'namespace should be empty')
self.assertEqual(len(ecore_graph.modules[0].contains), 0, 'module should not contain any')
self.assertEqual(ecore_graph.modules[1].eClass.name, NodeTypes.MODULE.value, 'module is wrong type')
self.assertEqual(ecore_graph.modules[1].location, 'unit_tests/test_multiple_modules/second_module', 'wrong module location')
self.assertIsNone(ecore_graph.modules[1].namespace, 'namespace should be empty')
self.assertEqual(len(ecore_graph.modules[1].contains), 0, 'module should not contain any')
def test_module_in_package(self):
repo = 'unit_tests/test_module_in_package'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False,test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(len(ecore_graph.packages), 1, 'wrong number of packages')
self.assertEqual(len(ecore_graph.modules), 1, 'wrong number of modules')
self.assertEqual(ecore_graph.packages[0].eClass.name, NodeTypes.PACKAGE.value, 'package is wrong type')
self.assertEqual(ecore_graph.packages[0].tName, 'my_package', 'wrong package name')
self.assertEqual(ecore_graph.modules[0].eClass.name, NodeTypes.MODULE.value, 'module is wrong type')
self.assertEqual(ecore_graph.modules[0].location, 'unit_tests/test_module_in_package/my_package/my_module', 'wrong module location')
self.assertEqual(ecore_graph.modules[0].namespace.eClass.name, NodeTypes.PACKAGE.value, 'namespace should contain package')
self.assertEqual(ecore_graph.modules[0].namespace.tName, 'my_package', 'wrong package name')
def test_class(self):
repo = 'unit_tests/test_class'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(len(ecore_graph.classes), 1, 'wrong number of classes')
self.assertEqual(ecore_graph.classes[0].tName, 'MyTestClass', 'wrong class name')
self.assertEqual(len(ecore_graph.modules[0].contains), 1, 'class should be contained in module')
self.assertEqual(ecore_graph.modules[0].contains[0].eClass.name, NodeTypes.CLASS.value, 'class should be in module, wrong object type')
def test_child_class(self):
repo = 'unit_tests/test_child_class'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(len(ecore_graph.classes[0].childClasses), 1, 'wrong number of child classes')
self.assertEqual(ecore_graph.classes[0].childClasses[0].tName, 'FirstChild', 'wrong name of child class')
def test_method(self):
repo = 'unit_tests/test_method'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(len(ecore_graph.methods), 1, 'wrong number of methods')
self.assertEqual(ecore_graph.methods[0].tName, 'my_test_method', 'wrong method name')
self.assertEqual(ecore_graph.methods[0].eClass.name, NodeTypes.METHOD.value, 'method is wrong type')
self.assertEqual(ecore_graph.methods[0].signatures[0].eClass.name, NodeTypes.METHOD_SIGNATURE.value, 'method signature is wrong type')
self.assertEqual(ecore_graph.modules[0].contains[0].eClass.name, NodeTypes.METHOD_DEFINITION.value, 'method definition is wrong type')
self.assertEqual(ecore_graph.modules[0].contains[0].signature.method.tName, 'my_test_method', 'edge method def to method wrong')
#test defining a method inside a class
def test_method_in_class(self):
repo = 'unit_tests/test_method_in_class'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(ecore_graph.modules[0].contains[0].eClass.name, NodeTypes.CLASS.value, 'class is wrong type')
self.assertEqual(ecore_graph.modules[0].contains[0].tName, 'MyTestClass', 'class name wrong')
self.assertEqual(len(ecore_graph.modules[0].contains[0].defines), 1, 'class should define one method')
self.assertEqual(ecore_graph.modules[0].contains[0].defines[0].eClass.name, NodeTypes.METHOD_DEFINITION.value, 'method in class is wrong type')
self.assertEqual(ecore_graph.modules[0].contains[0].defines[0].signature.method.tName, 'my_test_method', 'wrong method name')
#test defining multiple methods inside a class
def test_multiple_methods_in_class(self):
repo = 'unit_tests/test_multiple_methods_in_class'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(ecore_graph.modules[0].contains[0].eClass.name, NodeTypes.CLASS.value, 'class is wrong type')
self.assertEqual(ecore_graph.modules[0].contains[0].tName, 'MyTestClass', 'class name wrong')
self.assertEqual(len(ecore_graph.modules[0].contains[0].defines), 2, 'class should define two methods')
self.assertEqual(ecore_graph.modules[0].contains[0].defines[0].eClass.name, NodeTypes.METHOD_DEFINITION.value, 'first method in class is wrong type')
self.assertEqual(ecore_graph.modules[0].contains[0].defines[0].signature.method.tName, 'my_test_method', 'wrong method name')
self.assertEqual(ecore_graph.modules[0].contains[0].defines[1].eClass.name, NodeTypes.METHOD_DEFINITION.value, 'second method in class is wrong type')
self.assertEqual(ecore_graph.modules[0].contains[0].defines[1].signature.method.tName, 'my_second_method', 'wrong method name')
def test_parameter(self):
repo = 'unit_tests/test_parameter'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(len(ecore_graph.methods[0].signatures[0].parameters), 1, 'wrong number of parameters')
self.assertEqual(ecore_graph.methods[0].signatures[0].parameters[0].eClass.name, NodeTypes.PARAMETER.value, 'parameter is wrong type')
def test_multiple_parameter(self):
repo = 'unit_tests/test_multiple_parameter'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False)
ecore_graph = graph.get_graph()
self.assertEqual(len(ecore_graph.methods[0].signatures[0].parameters), 2, 'wrong number of parameters')
self.assertEqual(ecore_graph.methods[0].signatures[0].parameters[0].eClass.name, NodeTypes.PARAMETER.value, 'parameter is wrong type')
self.assertEqual(ecore_graph.methods[0].signatures[0].parameters[0].next.eClass.name, NodeTypes.PARAMETER.value, 'parameter should have next parameter set')
self.assertEqual(ecore_graph.methods[0].signatures[0].parameters[1].eClass.name, NodeTypes.PARAMETER.value, 'parameter is wrong type')
self.assertEqual(ecore_graph.methods[0].signatures[0].parameters[1].previous.eClass.name, NodeTypes.PARAMETER.value, 'parameter should have previous parameter set')
#test call of method by another method, both in same module
def test_module_internal_method_call(self):
repo = 'unit_tests/test_module_internal_method_call'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(ecore_graph.modules[0].contains[1].signature.method.tName, 'caller_func', 'caller method has wrong name')
self.assertEqual(len(ecore_graph.modules[0].contains[1].accessing), 1, 'call object is missing')
self.assertEqual(ecore_graph.modules[0].contains[1].accessing[0].eClass.name, NodeTypes.CALL.value, 'call is wrong type')
self.assertIsNotNone(ecore_graph.modules[0].contains[1].accessing[0].target, 'target is missing')
self.assertEqual(ecore_graph.modules[0].contains[1].accessing[0].target.signature.method.tName, 'called_func', 'target has wrong method name')
#test importing a method from another module in the repo
def test_internal_method_imports(self):
repo = 'unit_tests/test_internal_method_imports'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(ecore_graph.modules[1].contains[0].signature.method.tName, 'method_two', 'wrong method name using the import')
self.assertEqual(ecore_graph.modules[1].contains[0].accessing[0].eClass.name, NodeTypes.CALL.value, 'imported method cannot be used, import did not work')
self.assertEqual(ecore_graph.modules[1].contains[0].accessing[0].target.signature.method.tName, 'one_method', 'imported method name wrong')
#test importing a method from a class in another module in the repo
def test_internal_class_imports(self):
repo = 'unit_tests/test_internal_class_imports'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(ecore_graph.modules[1].contains[0].signature.method.tName, 'method_two', 'wrong method name using the import')
self.assertEqual(ecore_graph.modules[1].contains[0].accessing[0].eClass.name, NodeTypes.CALL.value, 'imported method cannot be used, import did not work')
self.assertEqual(ecore_graph.modules[1].contains[0].accessing[0].target.signature.method.tName, 'one_method', 'imported method name wrong')
self.assertEqual(ecore_graph.modules[0].contains[0].defines[0].accessedBy[0].source.signature.method.tName, 'method_two', 'source method for call is wrong')
#test calling a function from an imported module from another package
def test_internal_method_imports_package(self):
repo = 'unit_tests/test_internal_method_imports_package'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(ecore_graph.modules[0].contains[0].signature.method.tName, 'method_two', 'wrong method name using the import')
self.assertEqual(ecore_graph.modules[0].contains[0].accessing[0].eClass.name, NodeTypes.CALL.value, 'imported method cannot be used, import did not work')
self.assertEqual(ecore_graph.modules[0].contains[0].accessing[0].target.signature.method.tName, 'one_method', 'imported method name wrong')
self.assertEqual(ecore_graph.modules[1].contains[0].accessedBy[0].source.signature.method.tName, 'method_two', 'call source is wrong')
#test calling a function from an imported class from another package
def test_internal_method_class_imports_package(self):
repo = 'unit_tests/test_internal_method_class_imports_package'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(ecore_graph.modules[0].contains[0].signature.method.tName, 'method_two', 'wrong method name using the import')
self.assertEqual(ecore_graph.modules[0].contains[0].accessing[0].eClass.name, NodeTypes.CALL.value, 'imported method cannot be used, import did not work')
self.assertEqual(ecore_graph.modules[0].contains[0].accessing[0].target.signature.method.tName, 'one_method', 'imported method name wrong')
self.assertEqual(ecore_graph.modules[1].contains[0].defines[0].accessedBy[0].source.signature.method.tName, 'method_two', 'call source is wrong')
#test call of method in a class by another method not in the class, both in same module
def test_module_internal_class_call(self):
repo = 'unit_tests/test_module_internal_class_call'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertIsNotNone(ecore_graph.modules[0].contains[0].defines[0].accessedBy, 'call source is missing')
self.assertEqual(len(ecore_graph.modules[0].contains[1].accessing), 1, 'call object is missing')
self.assertEqual(ecore_graph.modules[0].contains[1].accessing[0].target.signature.method.tName, 'called_func', 'target has wrong name')
self.assertEqual(ecore_graph.modules[0].contains[1].signature.method.tName, 'caller_func', 'caller method has wrong name')
self.assertEqual(ecore_graph.modules[0].contains[1].accessing[0].eClass.name, NodeTypes.CALL.value, 'call is wrong type')
self.assertIsNotNone(ecore_graph.modules[0].contains[1].accessing[0].target, 'target is missing')
#test call of method in a class by another method, both in same class
def test_class_internal_method_call(self):
repo = 'unit_tests/test_class_internal_method_call'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(ecore_graph.modules[0].contains[0].defines[1].accessing[0].eClass.name, NodeTypes.CALL.value, 'call is wrong type')
self.assertEqual(ecore_graph.modules[0].contains[0].defines[1].accessing[0].target.signature.method.tName, 'called_func', 'target has wrong method name')
self.assertEqual(ecore_graph.modules[0].contains[0].defines[0].accessedBy[0].source.signature.method.tName, 'caller_func', 'source has wrong method name')
#test call for method in multiple packages(subpackage)
def test_internal_method_imports_multiple_packages(self):
repo = 'unit_tests/test_internal_method_imports_multiple_packages'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(ecore_graph.modules[0].contains[0].signature.method.tName, 'method_two', 'wrong method name using the import')
self.assertEqual(ecore_graph.modules[0].contains[0].accessing[0].eClass.name, NodeTypes.CALL.value, 'imported method cannot be used, import did not work')
self.assertEqual(ecore_graph.modules[0].contains[0].accessing[0].target.signature.method.tName, 'one_method', 'imported method name wrong')
self.assertEqual(ecore_graph.modules[2].contains[0].accessedBy[0].source.signature.method.tName, 'method_two', 'call source is wrong')
#test call for method in class in multiple packages(subpackage)
def test_internal_method_class_imports_multiple_packages(self):
repo = 'unit_tests/test_internal_method_class_imports_multiple_packages'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(ecore_graph.modules[0].contains[0].signature.method.tName, 'method_two', 'wrong method name using the import')
self.assertEqual(ecore_graph.modules[0].contains[0].accessing[0].eClass.name, NodeTypes.CALL.value, 'imported method cannot be used, import did not work')
self.assertEqual(ecore_graph.modules[0].contains[0].accessing[0].target.signature.method.tName, 'one_method', 'imported method name wrong')
self.assertEqual(ecore_graph.modules[2].contains[0].defines[0].accessedBy[0].source.signature.method.tName, 'method_two', 'call source is wrong')
#test importing external library, one module, one method
def test_call_external_library(self):
repo = 'unit_tests/test_call_external_library'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(ecore_graph.packages[0].tName, 'numpy_ExternalLibrary', 'imported library package is missing')
self.assertEqual(ecore_graph.modules[1].namespace.tName, 'numpy_ExternalLibrary', 'imported library module and package edge wrong')
self.assertEqual(len(ecore_graph.modules), 2, 'wrong number of modules')
self.assertEqual(ecore_graph.modules[1].location, 'numpy_ExternalLibrary', 'imported library has wrong name')
self.assertEqual(ecore_graph.modules[0].contains[0].accessing[0].eClass.name, NodeTypes.CALL.value, 'call object is wrong type')
self.assertEqual(ecore_graph.modules[0].contains[0].accessing[0].target.signature.method.tName, 'array_ExternalLibrary', 'target has wrong name')
self.assertEqual(ecore_graph.modules[1].contains[0].accessedBy[0].source.signature.method.tName, 'one_method', 'source has wrong name')
#test importing multiple packages/subpackages from external library
def test_call_external_library_submodule(self):
repo = 'unit_tests/test_call_external_library_submodule'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(len(ecore_graph.packages), 2, 'wrong number of packages')
self.assertEqual(ecore_graph.packages[1].tName, 'torch_geometric_ExternalLibrary', 'import with length>2 has wrong package name')
self.assertEqual(ecore_graph.modules[2].namespace.tName, 'torch_geometric_ExternalLibrary', 'wrong modules namespace')
self.assertEqual(ecore_graph.modules[2].contains[0].signature.method.tName, 'global_mean_pool_ExternalLibrary', 'wrong method name in imported module')
self.assertEqual(ecore_graph.modules[2].contains[0].accessedBy[0].eClass.name, NodeTypes.CALL.value, 'wrong object type')
#test importing class with a method (external libraries)
def test_call_external_library_class(self):
repo = 'unit_tests/test_call_external_library_class'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(ecore_graph.packages[0].tName, 'torch_ExternalLibrary', 'wrong package name for import')
self.assertEqual(len(ecore_graph.packages), 1, 'wrong number of imported packages')
self.assertEqual(len(ecore_graph.packages[0].subpackages), 1, 'subpackage wrong number')
self.assertEqual(ecore_graph.packages[0].subpackages[0].tName, 'utils_ExternalLibrary', 'subpackages wrong name')
self.assertEqual(ecore_graph.packages[0].subpackages[0].parent.tName, 'torch_ExternalLibrary', 'parent package wrong')
self.assertEqual(len(ecore_graph.modules), 2, 'wrong umber of modules')
self.assertEqual(ecore_graph.modules[1].location, 'data_ExternalLibrary', 'imported module from external library has wrong name')
self.assertEqual(len(ecore_graph.modules[1].contains), 2, 'wrong number of imported methods/classes')
self.assertEqual(ecore_graph.modules[1].contains[0].signature.method.tName, 'Dataset_ExternalLibrary', 'method wrong name')
self.assertEqual(ecore_graph.modules[1].contains[0].accessedBy[0].eClass.name, NodeTypes.CALL.value, 'call is missing')
self.assertEqual(ecore_graph.modules[1].contains[1].eClass.name, NodeTypes.CLASS.value, 'class is missing')
self.assertEqual(ecore_graph.modules[1].contains[1].tName, 'Dataset', 'class has wrong name')
#self.assertEqual(ecore_graph.modules[1].contains[1].tLib, False, 'flag for imported class from external library not set to False')
self.assertEqual(ecore_graph.modules[1].contains[1].defines[0].signature.method.tName, '__len___ExternalLibrary', 'method in class has wrong name')
self.assertEqual(ecore_graph.modules[1].contains[1].defines[0].accessedBy[0].eClass.name, NodeTypes.CALL.value, 'call is missing')
#test importing class with multiple methods (external libraries)
def test_call_external_library_class_multiple_methods(self):
repo = 'unit_tests/test_call_external_library_class_multiple_methods'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(ecore_graph.modules[1].contains[1].defines[1].signature.method.tName, '__getitem___ExternalLibrary', 'second class method has wrong name')
self.assertEqual(ecore_graph.modules[1].contains[1].defines[1].accessedBy[0].eClass.name, NodeTypes.CALL.value, 'call is missing')
#test importing multiple methods in one module (external libraries)
def test_call_external_library_multiple_methods(self):
repo = 'unit_tests/test_call_external_library_multiple_methods'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(ecore_graph.modules[1].contains[1].signature.method.tName, 'max_ExternalLibrary', 'second method in imported module wrong name')
self.assertEqual(ecore_graph.modules[1].contains[1].accessedBy[0].eClass.name, NodeTypes.CALL.value, 'call is missing')
#test imported packages (and subpackages) with multiple modules (external libraries)
def test_call_external_library_multiple_modules_same_package(self):
repo = 'unit_tests/test_call_external_library_multiple_modules_same_package'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(len(ecore_graph.modules), 3, 'wrong number of modules')
self.assertEqual(ecore_graph.modules[1].namespace.tName, 'utils_ExternalLibrary', 'wrong subpackage name in imported module')
self.assertEqual(ecore_graph.modules[2].namespace.tName, 'utils_ExternalLibrary', 'wrong subpackage name in imported module')
self.assertEqual(ecore_graph.modules[2].location, 'benchmark_ExternalLibrary', 'wrong name for imported module')
self.assertEqual(ecore_graph.modules[2].contains[0].signature.method.tName, 'Timer_ExternalLibrary', 'wrong method name in imported module')
self.assertEqual(ecore_graph.modules[2].contains[0].accessedBy[0].eClass.name, NodeTypes.CALL.value, 'call is missing')
#test imported packages with multiple subpackages (external libraries)
def test_call_external_library_multiple_subpackages(self):
repo = 'unit_tests/test_call_external_library_multiple_subpackages'
check_path_exists(repo)
resource_set = ResourceSet()
graph = ProjectEcoreGraph(resource_set, repo, False, test_output_dir)
ecore_graph = graph.get_graph()
self.assertEqual(len(ecore_graph.packages[0].subpackages), 2, 'wrong number of subpackages')
self.assertEqual(ecore_graph.packages[0].subpackages[0].tName, 'utils_ExternalLibrary', 'wrong subpackage name')
self.assertEqual(ecore_graph.packages[0].subpackages[1].tName, 'cuda_ExternalLibrary', 'wrong subpackage name')
self.assertEqual(ecore_graph.modules[2].location, 'random_ExternalLibrary', 'wrong module location in second subpackage')
self.assertEqual(ecore_graph.modules[2].contains[0].signature.method.tName, 'Tensor_ExternalLibrary', 'wrong method name in module in second subpackage')
self.assertEqual(ecore_graph.modules[2].contains[0].accessedBy[0].eClass.name, NodeTypes.CALL.value, 'call is missing')
if __name__ == "__main__":
unittest.main()