test_all.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. import unittest
  2. import sys
  3. try:
  4. from unit.utils import *
  5. import unit.log_output as log_output
  6. except ImportError: #for Python2
  7. from utils import *
  8. import log_output as log_output
  9. sys.path.append("wrappers")
  10. from modelverse import *
  11. import threading
  12. model_hierarchy = \
  13. {"formalisms/": {"SimpleClassDiagrams": {},
  14. "TypeMapping": {},
  15. "Tracability": {},
  16. "ProcessModel": {},
  17. "ActionLanguage": {},
  18. "ManualOperation": {},
  19. "Bottom": {},
  20. },
  21. "models/": {"conformance_mv": {},
  22. },
  23. "administration/": {"core": {},
  24. "CoreFormalism": {},
  25. },
  26. "users/": {"admin/": {}
  27. },
  28. "type mappings/": {"formalisms/": {"SimpleClassDiagrams": {},
  29. "TypeMapping": {},
  30. "Tracability": {},
  31. "ProcessModel": {},
  32. "ActionLanguage": {},
  33. "ManualOperation": {},
  34. "Bottom": {},
  35. },
  36. "models/": {"conformance_mv": {},
  37. },
  38. "administration/": {"core": {},
  39. "CoreFormalism": {},
  40. },
  41. "users/": {"admin/": {}
  42. },
  43. },
  44. }
  45. def verify_clean():
  46. compare_locations("", set())
  47. compare_locations("models", set())
  48. compare_locations("formalisms", set())
  49. compare_locations("administration", set())
  50. compare_locations("type mappings", set())
  51. compare_locations("type mappings/models", set())
  52. compare_locations("type mappings/formalisms", set())
  53. compare_locations("type mappings/administration", set())
  54. def get_model_list(location):
  55. try:
  56. location_parts = location.split("/")
  57. current = model_hierarchy
  58. while location_parts:
  59. l = location_parts.pop(0)
  60. if l != "":
  61. current = current[l + "/"]
  62. return set(current.keys())
  63. except:
  64. return set([])
  65. def compare_locations(location, extra_to_default):
  66. assert model_list(location) == get_model_list(location) | set(extra_to_default)
  67. def compare_unordered_lists(got, expected):
  68. assert len(got) == len(expected)
  69. for i in got:
  70. assert i in expected
  71. for i in expected:
  72. assert i in got
  73. class TestModelverse(unittest.TestCase):
  74. proc = None
  75. def runTest(self):
  76. pass
  77. @classmethod
  78. def setUpClass(self):
  79. TestModelverse.proc, address = start_mvc()
  80. init(address)
  81. login("admin", "admin")
  82. @classmethod
  83. def tearDownClass(self):
  84. try:
  85. kill(TestModelverse.proc)
  86. except:
  87. print("Got exception during teardown.")
  88. def setUp(self):
  89. verify_clean()
  90. folder_create("test")
  91. folder_create("type mappings/test")
  92. def tearDown(self):
  93. model_delete("test")
  94. model_delete("type mappings/test")
  95. verify_clean()
  96. pass
  97. def test_op_model_list(self):
  98. assert model_list("") == set(["formalisms/",
  99. "models/",
  100. "administration/",
  101. "type mappings/",
  102. "users/",
  103. "test/",
  104. ])
  105. assert model_list("formalisms") == set(["SimpleClassDiagrams",
  106. "ActionLanguage",
  107. "TypeMapping",
  108. "Tracability",
  109. "ProcessModel",
  110. "ManualOperation",
  111. "Bottom",
  112. ])
  113. assert model_list("formalisms/") == set(["SimpleClassDiagrams",
  114. "ActionLanguage",
  115. "TypeMapping",
  116. "Tracability",
  117. "ProcessModel",
  118. "ManualOperation",
  119. "Bottom",
  120. ])
  121. def test_op_model_list_full(self):
  122. assert model_list_full("") == set([("formalisms/", "admin", "admin", "221"),
  123. ("models/", "admin", "admin", "221"),
  124. ("administration/", "admin", "admin", "110"),
  125. ("type mappings/", "admin", "admin", "221"),
  126. ("users/", "admin", "admin", "221"),
  127. ("test/", "admin", "nobody", "200"),
  128. ])
  129. assert model_list_full("formalisms") == set([("SimpleClassDiagrams", "admin", "admin", "221"),
  130. ("ActionLanguage", "admin", "admin", "221"),
  131. ("TypeMapping", "admin", "admin", "221"),
  132. ("Tracability", "admin", "admin", "221"),
  133. ("ProcessModel", "admin", "admin", "221"),
  134. ("ManualOperation", "admin", "admin", "221"),
  135. ("Bottom", "admin", "admin", "221"),
  136. ])
  137. assert model_list_full("formalisms/") == set([("SimpleClassDiagrams", "admin", "admin", "221"),
  138. ("ActionLanguage", "admin", "admin", "221"),
  139. ("TypeMapping", "admin", "admin", "221"),
  140. ("Tracability", "admin", "admin", "221"),
  141. ("ProcessModel", "admin", "admin", "221"),
  142. ("ManualOperation", "admin", "admin", "221"),
  143. ("Bottom", "admin", "admin", "221"),
  144. ])
  145. """
  146. def test_op_model_add(self):
  147. def test_op_model_move(self):
  148. def test_op_model_delete(self):
  149. def test_op_verify(self):
  150. def test_op_model_overwrite(self):
  151. def test_op_user_delete(self):
  152. def test_op_model_render(self):
  153. def test_op_transformation_between(self):
  154. def test_op_transformation_add_MT(self):
  155. def test_op_transformation_add_AL(self):
  156. def test_op_transformation_add_MANUAL(self):
  157. def test_op_transformation_execute_MT(self):
  158. def test_op_transformation_execute_AL(self):
  159. def test_op_transformation_execute_MANUAL(self):
  160. def test_op_transformation_signature(self):
  161. def test_op_process_signature(self):
  162. def test_op_permission_modify(self):
  163. def test_op_permission_group(self):
  164. def test_op_permission_owner(self):
  165. def test_op_group_create(self):
  166. def test_op_group_delete(self):
  167. def test_op_group_owner_add(self):
  168. def test_op_group_owner_delete(self):
  169. def test_op_group_join(self):
  170. def test_op_group_kick(self):
  171. def test_op_group_list(self):
  172. def test_op_admin_promote(self):
  173. def test_op_admin_demote(self):
  174. def test_op_conformance_delete(self):
  175. def test_op_conformance_add(self):
  176. def test_op_folder_create(self):
  177. def test_op_model_types(self):
  178. def test_op_alter_context(self):
  179. def test_op_element_list(self):
  180. def test_op_element_list_nice(self):
  181. def test_op_types(self):
  182. def test_op_types_full(self):
  183. def test_op_read_info(self):
  184. def test_op_read_attrs(self):
  185. def test_op_instantiate(self):
  186. def test_op_delete_element(self):
  187. def test_op_attr_assign(self):
  188. def test_op_attr_assign_code(self):
  189. def test_op_attr_delete(self):
  190. def test_op_AL_text(self):
  191. def test_op_read_outgoing(self):
  192. def test_op_read_incoming(self):
  193. def test_op_read_association_source(self):
  194. def test_op_read_association_destination(self):
  195. def test_op_conections_between(self):
  196. def test_op_define_attribute(self):
  197. def test_op_all_instances(self):
  198. """
  199. def test_modelling(self):
  200. # Add a model
  201. model_add("test/Empty", "formalisms/SimpleClassDiagrams")
  202. # Check that it exists
  203. compare_locations("test", set(["Empty"]))
  204. compare_locations("type mappings/test", set(["Empty"]))
  205. # Check that it conforms
  206. assert verify("test/Empty", "formalisms/SimpleClassDiagrams") == "OK"
  207. # Check for permissions
  208. assert model_list_full("test") == set([(name, "admin", "admin", "221") for name in get_model_list("test")]) | \
  209. set([("Empty", "admin", "nobody", "200")])
  210. assert model_list_full("type mappings/test") == set([(name, "admin", "admin", "221") for name in get_model_list("type mappings/test")]) | \
  211. set([("Empty", "admin", "nobody", "200")])
  212. # Instantiate it further
  213. model_add("test/my_empty", "test/Empty")
  214. assert verify("test/my_empty", "test/Empty") == "OK"
  215. # Check that it exists
  216. compare_locations("test", set(["my_empty", "Empty"]))
  217. compare_locations("type mappings/test", set(["my_empty", "Empty"]))
  218. # Check that an instantiate of "A" fails
  219. try:
  220. res = instantiate("test/my_empty", "A")
  221. assert False
  222. except UnknownIdentifier:
  223. assert verify("test/Empty", "formalisms/SimpleClassDiagrams") == "OK"
  224. # Create something in the formalism
  225. instantiate("test/Empty", "Class", ID="A")
  226. attr_assign("test/Empty", "A", "name", "A")
  227. assert verify("test/Empty", "formalisms/SimpleClassDiagrams") == "OK"
  228. # Now instantiate that in the model as well, which now works
  229. instantiate("test/my_empty", "A")
  230. assert verify("test/my_empty", "test/Empty") == "OK"
  231. def test_overwrite(self):
  232. model_add("test/Empty", "formalisms/SimpleClassDiagrams")
  233. assert element_list("test/Empty") == set([])
  234. instantiate("test/Empty", "Class", ID="A")
  235. assert element_list("test/Empty") == set([("A", "Class")])
  236. model_overwrite("test/Empty", "")
  237. assert element_list("test/Empty") == set([])
  238. compare_locations("test", set(["Empty"]))
  239. compare_locations("type mappings/test", set(["Empty"]))
  240. assert element_list("test/Empty") == set([])
  241. instantiate("test/Empty", "Class", ID="B")
  242. compare_locations("test", set(["Empty"]))
  243. compare_locations("type mappings/test", set(["Empty"]))
  244. def test_operations(self):
  245. log = []
  246. def manual_callback(model):
  247. p1 = instantiate(model, "PetriNet_Runtime/Place")
  248. p2 = instantiate(model, "PetriNet_Runtime/Place")
  249. p3 = instantiate(model, "PetriNet_Runtime/Place")
  250. t1 = instantiate(model, "PetriNet_Runtime/Transition")
  251. p2t1 = instantiate(model, "PetriNet_Runtime/P2T", (p1, t1))
  252. p2t2 = instantiate(model, "PetriNet_Runtime/P2T", (p2, t1))
  253. t2p1 = instantiate(model, "PetriNet_Runtime/T2P", (t1, p3))
  254. attr_assign(model, p1, "tokens", 1)
  255. attr_assign(model, p1, "name", "p1")
  256. attr_assign(model, p2, "tokens", 2)
  257. attr_assign(model, p2, "name", "p2")
  258. attr_assign(model, p3, "tokens", 3)
  259. attr_assign(model, p3, "name", "p3")
  260. attr_assign(model, t1, "name", "t1")
  261. attr_assign(model, t1, "executing", False)
  262. attr_assign(model, p2t1, "weight", 1)
  263. attr_assign(model, p2t2, "weight", 1)
  264. attr_assign(model, t2p1, "weight", 2)
  265. model_add("test/PetriNet", "formalisms/SimpleClassDiagrams", open("integration/code/pn_design.mvc", "r").read())
  266. model_add("test/PetriNet_Runtime", "formalisms/SimpleClassDiagrams", open("integration/code/pn_runtime.mvc", "r").read())
  267. model_add("test/my_pn", "test/PetriNet", open("integration/code/pn_design_model.mvc", "r").read())
  268. def add_tracability_D2R(model):
  269. instantiate(model, "Association", ("PetriNet/Place", "PetriNet_Runtime/Place"), ID="D2R_PlaceLink")
  270. instantiate(model, "Association", ("PetriNet/Transition", "PetriNet_Runtime/Transition"), ID="D2R_TransitionLink")
  271. def add_tracability_R2D(model):
  272. instantiate(model, "Association", ("PetriNet_Runtime/Place", "PetriNet/Place"), ID="R2D_PlaceLink")
  273. instantiate(model, "Association", ("PetriNet_Runtime/Transition", "PetriNet/Transition"), ID="R2D_TransitionLink")
  274. transformation_add_MT({"PetriNet": "test/PetriNet"}, {}, "test/print_pn", open("integration/code/pn_print.mvc").read())
  275. transformation_add_MANUAL({"PetriNet": "test/PetriNet"}, {"PetriNet_Runtime": "test/PetriNet_Runtime"}, "test/pn_design_to_runtime", add_tracability_D2R)
  276. transformation_add_AL({"PetriNet_Runtime": "test/PetriNet_Runtime"}, {"PetriNet_Runtime": "test/PetriNet_Runtime"}, "test/pn_simulate", open("integration/code/pn_simulate.alc").read())
  277. transformation_add_MT({"PetriNet_Runtime": "test/PetriNet_Runtime"}, {"PetriNet": "test/PetriNet"}, "test/pn_runtime_to_design", open("integration/code/pn_runtime_to_design.mvc").read(), add_tracability_R2D)
  278. log = []
  279. ctrl = log_output.Controller(log, keep_running=False)
  280. thrd = threading.Thread(target=ctrl.start)
  281. thrd.daemon = True
  282. thrd.start()
  283. assert transformation_execute_MT("test/print_pn", {"PetriNet": "test/my_pn"}, {}, (ctrl, "inp", "outp")) == True
  284. thrd.join()
  285. assert set(log) == set(['"p1" --> 1',
  286. '"p2" --> 2',
  287. '"p3" --> 3'])
  288. assert transformation_execute_MANUAL("test/pn_design_to_runtime", {"PetriNet": "test/my_pn"}, {"PetriNet_Runtime": "test/my_pn_RT"}, manual_callback) == True
  289. assert transformation_execute_AL("test/pn_simulate", {"PetriNet_Runtime": "test/my_pn_RT"}, {"PetriNet_Runtime": "test/my_pn_RT"}) == True
  290. assert transformation_execute_MT("test/pn_runtime_to_design", {"PetriNet_Runtime": "test/my_pn_RT"}, {"PetriNet": "test/my_pn"}) == True
  291. log = []
  292. ctrl = log_output.Controller(log, keep_running=False)
  293. thrd = threading.Thread(target=ctrl.start)
  294. thrd.daemon = True
  295. thrd.start()
  296. assert transformation_execute_MT("test/print_pn", {"PetriNet": "test/my_pn"}, {}, (ctrl, "inp", "outp")) == True
  297. thrd.join()
  298. assert set(log) == set(['"p1" --> 0',
  299. '"p2" --> 1',
  300. '"p3" --> 5'])
  301. model_delete("RAMified")
  302. model_delete("merged")
  303. model_delete(".tmp")
  304. model_delete("type mappings/RAMified")
  305. model_delete("type mappings/merged")
  306. model_delete("type mappings/.tmp")
  307. def test_process_model_trivial_pn_subfunction(self):
  308. model_add("test/PetriNet", "formalisms/SimpleClassDiagrams", open("integration/code/pn_design.mvc", "r").read())
  309. model_add("test/ReachabilityGraph", "formalisms/SimpleClassDiagrams", open("integration/code/reachability_graph.mvc", "r").read())
  310. model_add("test/pn_reachability", "formalisms/ProcessModel", open("integration/code/pm_pn_reachability.mvc", "r").read())
  311. transformation_add_MT({}, {"PetriNet": "test/PetriNet"}, "test/initialize_PN", open("integration/code/initialize_PN.mvc", "r").read())
  312. transformation_add_MANUAL({"PetriNet": "test/PetriNet"}, {"PetriNet": "test/PetriNet"}, "test/refine_PN")
  313. transformation_add_AL({"PetriNet": "test/PetriNet"}, {"ReachabilityGraph": "test/ReachabilityGraph"}, "test/reachability", open("integration/code/reachability_subfunction.alc", "r").read())
  314. transformation_add_MT({"ReachabilityGraph": "test/ReachabilityGraph"}, {}, "test/reachability_print", open("integration/code/reachabilitygraph_print.mvc", 'r').read())
  315. def callback_refine_PN(model):
  316. p1 = instantiate(model, "PetriNet/Place")
  317. attr_assign(model, p1, "name", "p1")
  318. attr_assign(model, p1, "tokens", 1)
  319. t1 = instantiate(model, "PetriNet/Transition")
  320. attr_assign(model, t1, "name", "t1")
  321. p2t = instantiate(model, "PetriNet/P2T", (p1, t1))
  322. attr_assign(model, p2t, "weight", 1)
  323. log = []
  324. ctrl = log_output.Controller(log, keep_running=False)
  325. thrd = threading.Thread(target=ctrl.start)
  326. thrd.daemon = True
  327. thrd.start()
  328. process_execute("test/pn_reachability", {}, {"test/refine_PN": callback_refine_PN, "test/reachability_print": (ctrl, "inp", "outp")})
  329. thrd.join()
  330. assert set(log) == set(['"0": {"p1": 1}',
  331. '"1": {"p1": 0}',
  332. '"0" --["t1"]--> "1"'])
  333. model_delete(".tmp")
  334. model_delete("RAMified")
  335. model_delete("merged")
  336. model_delete("type mappings/RAMified")
  337. model_delete("type mappings/merged")
  338. model_delete("type mappings/.tmp")
  339. def test_render(self):
  340. model_add("test/CausalBlockDiagrams", "formalisms/SimpleClassDiagrams", open("integration/code/cbd_design.mvc", 'r').read())
  341. model_add("test/MM_rendered_graphical", "formalisms/SimpleClassDiagrams", open("integration/code/MM_rendered_graphical.mvc", 'r').read())
  342. model_add("test/my_CBD", "test/CausalBlockDiagrams", open("integration/code/my_cbd.mvc", 'r').read())
  343. def add_tracability(model):
  344. instantiate(model, "Association", ("abstract/Block", "rendered/Group"), ID="TracabilityLink")
  345. transformation_add_MT({"abstract": "test/CausalBlockDiagrams", "rendered": "test/MM_rendered_graphical"}, {"abstract": "test/CausalBlockDiagrams", "rendered": "test/MM_rendered_graphical"}, "test/render_graphical_CBD", open("integration/code/CBD_mapper.mvc", 'r').read(), add_tracability)
  346. result = model_render("test/my_CBD", "test/render_graphical_CBD", "test/my_perceptualized_CBD")
  347. assert len(result) == 23
  348. model_delete("RAMified")
  349. model_delete("merged")
  350. model_delete("type mappings/RAMified")
  351. model_delete("type mappings/merged")
  352. model_delete("tracability")
  353. model_delete("type mappings/tracability")
  354. def test_SCCD_basic(self):
  355. model_add("test/SCCD", "formalisms/SimpleClassDiagrams", open("integration/code/SCCD.mvc", 'r').read())
  356. model_add("test/SCCD_Trace", "formalisms/SimpleClassDiagrams", open("integration/code/SCCD_Trace.mvc", 'r').read())
  357. model_add("test/my_SCCD", "test/SCCD", open("integration/code/SCCD_all.mvc", 'r').read())
  358. transformation_add_AL({"SCCD": "test/SCCD"}, {"trace": "test/SCCD_Trace"}, "test/SCCD_execute_afap", open("integration/code/SCCD_execute.alc", 'r').read().replace("afap = False", "afap = True"))
  359. transformation_execute_AL("test/SCCD_execute_afap", {"SCCD": "test/my_SCCD"}, {"trace": "test/my_SCCD_trace"})
  360. alter_context("test/my_SCCD_trace", "test/SCCD_Trace")
  361. lst = element_list_nice("test/my_SCCD_trace")
  362. model_delete("merged")
  363. model_delete("type mappings/merged")
  364. lst.sort(key=lambda i: (i["timestamp"], i["name"]))
  365. result = [(i["timestamp"], str(i["name"])) for i in lst if i["name"] not in ["updateTimerValue", "updateTimerColour", "resetTimer"]]
  366. assert result == [(5.0, "displayRed"),
  367. (20.0, "displayYellow"),
  368. (20.5, "displayNone"),
  369. (21.0, "displayYellow"),
  370. (21.5, "displayNone"),
  371. (22.0, "displayYellow"),
  372. (22.5, "displayNone"),
  373. (23.0, "displayYellow"),
  374. (23.5, "displayNone"),
  375. (24.0, "displayYellow"),
  376. (24.5, "displayNone"),
  377. (25.0, "displayYellow"),
  378. (25.5, "displayNone"),
  379. (26.0, "displayYellow"),
  380. (26.5, "displayNone"),
  381. (27.0, "displayYellow"),
  382. (27.5, "displayNone"),
  383. (28.0, "displayYellow"),
  384. (28.5, "displayNone"),
  385. (29.0, "displayYellow"),
  386. (29.4, "displayNone"),
  387. (29.4, "displayRed"),
  388. (89.4, "displayGreen"),
  389. (129.4, "displayNone"),
  390. (129.4, "displayRed"),
  391. (139.4, "displayYellow"),
  392. (139.9, "displayNone"),
  393. (140.4, "displayYellow"),
  394. (140.9, "displayNone"),
  395. (141.4, "displayYellow"),
  396. (141.9, "displayNone"),
  397. (142.4, "displayYellow"),
  398. (142.9, "displayNone"),
  399. (143.4, "displayYellow"),
  400. (143.9, "displayNone"),
  401. (144.4, "displayYellow"),
  402. (144.9, "displayNone"),
  403. (145.4, "displayYellow"),
  404. (145.9, "displayNone"),
  405. (146.4, "displayYellow"),
  406. (146.9, "displayNone"),
  407. (147.4, "displayYellow"),
  408. (147.9, "displayNone"),
  409. (148.4, "displayYellow"),
  410. ]
  411. def test_switch_MM(self):
  412. model_add("test/PetriNet", "formalisms/SimpleClassDiagrams", open("integration/code/pn_design.mvc", "r").read())
  413. model_add("test/my_pn", "test/PetriNet", open("integration/code/pn_design_model.mvc", "r").read())
  414. got = element_list_nice("test/PetriNet")
  415. expected = \
  416. [{'__id': 'Natural', '__type': 'SimpleAttribute', 'constraint': {'AL': ''}, 'name': 'Natural'},
  417. {'__id': 'String', '__type': 'SimpleAttribute', 'constraint': {'AL': ''}, 'name': 'String'},
  418. {'__id': 'Place', '__type': 'Class', 'lower_cardinality': None, 'upper_cardinality': None, 'constraint': {'AL': ''}, 'name': 'Place', 'abstract': None},
  419. {'__id': 'Place_tokens', '__type': 'AttributeLink', '__source': 'Place', '__target': 'Natural', 'name': 'tokens', 'optional': False, 'constraint': {'AL': ''}},
  420. {'__id': 'Place_name', '__type': 'AttributeLink', '__source': 'Place', '__target': 'String', 'name': 'name', 'optional': False, 'constraint': {'AL': ''}},
  421. {'__id': 'Transition', '__type': 'Class', 'lower_cardinality': None, 'upper_cardinality': None, 'constraint': {'AL': ''}, 'name': 'Transition', 'abstract': None},
  422. {'__id': 'Transition_name', '__type': 'AttributeLink', '__source': 'Transition', '__target': 'String', 'name': 'name', 'optional': False, 'constraint': {'AL': ''}},
  423. {'__id': 'P2T', '__type': 'Association', '__source': 'Place', '__target': 'Transition', 'source_lower_cardinality': None, 'target_lower_cardinality': None, 'source_upper_cardinality': None, 'target_upper_cardinality': None, 'constraint': {'AL': ''}, 'name': 'P2T'},
  424. {'__id': 'P2T_weight', '__type': 'AttributeLink', '__source': 'P2T', '__target': 'Natural', 'name': 'weight', 'optional': False, 'constraint': {'AL': ''}},
  425. {'__id': 'T2P', '__type': 'Association', '__source': 'Transition', '__target': 'Place', 'source_lower_cardinality': None, 'target_lower_cardinality': None, 'source_upper_cardinality': None, 'target_upper_cardinality': None, 'constraint': {'AL': ''}, 'name': 'T2P'},
  426. {'__id': 'T2P_weight', '__type': 'AttributeLink', '__source': 'T2P', '__target': 'Natural', 'name': 'weight', 'optional': False, 'constraint': {'AL': ''}},
  427. ]
  428. compare_unordered_lists(got, expected)
  429. got = element_list_nice("test/my_pn")
  430. expected = \
  431. [{'__id': 'p1', '__type': 'Place', 'tokens': 1, 'name': 'p1'},
  432. {'__id': 'p2', '__type': 'Place', 'tokens': 2, 'name': 'p2'},
  433. {'__id': 'p3', '__type': 'Place', 'tokens': 3, 'name': 'p3'},
  434. {'__id': 't1', '__type': 'Transition', 'name': 't1'},
  435. {'__id': '__0', '__type': 'P2T', '__source': 'p1', '__target': 't1', 'weight': 1},
  436. {'__id': '__1', '__type': 'P2T', '__source': 'p2', '__target': 't1', 'weight': 1},
  437. {'__id': '__2', '__type': 'T2P', '__source': 't1', '__target': 'p3', 'weight': 2}
  438. ]
  439. compare_unordered_lists(got, expected)
  440. alter_context("test/PetriNet", "formalisms/Bottom")
  441. alter_context("test/my_pn", "formalisms/Bottom")
  442. count_nodes = 0
  443. count_edges = 0
  444. for entry in element_list_nice("test/PetriNet"):
  445. print(entry)
  446. assert entry["__type"] in ["Node", "Edge"]
  447. if entry["__type"] == "Node":
  448. assert len(entry) == 2
  449. count_nodes += 1
  450. else:
  451. assert len(entry) == 4
  452. count_edges += 1
  453. assert count_nodes == 20
  454. assert count_edges == 23
  455. count_nodes = 0
  456. count_edges = 0
  457. for entry in element_list_nice("test/my_pn"):
  458. assert entry["__type"] in ["Node", "Edge"]
  459. if entry["__type"] == "Node":
  460. assert len(entry) == 2
  461. count_nodes += 1
  462. else:
  463. assert len(entry) == 4
  464. count_edges += 1
  465. assert count_nodes == 14
  466. assert count_edges == 13
  467. alter_context("test/PetriNet", "test/PetriNet")
  468. alter_context("test/my_pn", "formalisms/SimpleClassDiagrams")
  469. try:
  470. element_list_nice("test/PetriNet")
  471. self.fail()
  472. except:
  473. pass
  474. try:
  475. element_list_nice("test/my_pn")
  476. self.fail()
  477. except:
  478. pass