|
@@ -1,465 +0,0 @@
|
|
|
-import unittest
|
|
|
-
|
|
|
-from utils import *
|
|
|
-import sys
|
|
|
-
|
|
|
-sys.path.append("wrappers")
|
|
|
-from modelverse import *
|
|
|
-
|
|
|
-model_hierarchy = \
|
|
|
- {"formalisms/": {"SimpleClassDiagrams": {},
|
|
|
- "TypeMapping": {},
|
|
|
- "Tracability": {},
|
|
|
- "ProcessModel": {},
|
|
|
- "ActionLanguage": {},
|
|
|
- "ManualOperation": {},
|
|
|
- "Bottom": {},
|
|
|
- },
|
|
|
- "models/": {"conformance_mv": {},
|
|
|
- },
|
|
|
- "administration/": {"core": {},
|
|
|
- "CoreFormalism": {},
|
|
|
- },
|
|
|
- "users/": {"admin/": {}
|
|
|
- },
|
|
|
- "type mappings/": {"formalisms/": {"SimpleClassDiagrams": {},
|
|
|
- "TypeMapping": {},
|
|
|
- "Tracability": {},
|
|
|
- "ProcessModel": {},
|
|
|
- "ActionLanguage": {},
|
|
|
- "ManualOperation": {},
|
|
|
- "Bottom": {},
|
|
|
- },
|
|
|
- "models/": {"conformance_mv": {},
|
|
|
- },
|
|
|
- "administration/": {"core": {},
|
|
|
- "CoreFormalism": {},
|
|
|
- },
|
|
|
- "users/": {"admin/": {}
|
|
|
- },
|
|
|
- },
|
|
|
- }
|
|
|
-
|
|
|
-def get_model_list(location):
|
|
|
- try:
|
|
|
- location_parts = location.split("/")
|
|
|
- current = model_hierarchy
|
|
|
- while location_parts:
|
|
|
- l = location_parts.pop(0)
|
|
|
- if l != "":
|
|
|
- current = current[l + "/"]
|
|
|
- return set(current.keys())
|
|
|
- except:
|
|
|
- return set([])
|
|
|
-
|
|
|
-def compare_locations(location, extra_to_default):
|
|
|
- assert model_list(location) == get_model_list(location) | set(extra_to_default)
|
|
|
-
|
|
|
-def compare_unordered_lists(got, expected):
|
|
|
- assert len(got) == len(expected)
|
|
|
- for i in got:
|
|
|
- assert i in expected
|
|
|
- for i in expected:
|
|
|
- assert i in got
|
|
|
-
|
|
|
-class TestModelverseCore(unittest.TestCase):
|
|
|
- def setUp(self):
|
|
|
- self.proc, self.address = start_mvc()
|
|
|
- init(self.address)
|
|
|
- login("admin", "admin")
|
|
|
-
|
|
|
- def tearDown(self):
|
|
|
- try:
|
|
|
- kill(self.proc)
|
|
|
- except:
|
|
|
- print("Got exception during teardown.")
|
|
|
-
|
|
|
- def test_list(self):
|
|
|
- compare_locations("", set())
|
|
|
- compare_locations("formalisms", set())
|
|
|
- compare_locations("models", set())
|
|
|
- compare_locations("administration", set())
|
|
|
- compare_locations("type mappings", set())
|
|
|
- compare_locations("type mappings/formalisms", set())
|
|
|
- compare_locations("type mappings/administration", set())
|
|
|
- compare_locations("type mappings/models", set())
|
|
|
-
|
|
|
- def test_list_full(self):
|
|
|
- assert model_list_full("") == set([("formalisms/", "admin", "admin", "221"),
|
|
|
- ("models/", "admin", "admin", "221"),
|
|
|
- ("administration/", "admin", "admin", "110"),
|
|
|
- ("type mappings/", "admin", "admin", "221"),
|
|
|
- ("users/", "admin", "admin", "221"),
|
|
|
- ])
|
|
|
-
|
|
|
- def test_model_add_empty(self):
|
|
|
- model_add("formalisms/Empty", "formalisms/SimpleClassDiagrams")
|
|
|
- compare_locations("formalisms", set(["Empty"]))
|
|
|
- compare_locations("type mappings/formalisms", set(["Empty"]))
|
|
|
- assert model_list_full("formalisms") == set([(name, "admin", "admin", "221") for name in get_model_list("formalisms")]) | \
|
|
|
- set([("Empty", "admin", "nobody", "200")])
|
|
|
- assert model_list_full("type mappings/formalisms") == set([(name, "admin", "admin", "221") for name in get_model_list("type mappings/formalisms")]) | \
|
|
|
- set([("Empty", "admin", "nobody", "200")])
|
|
|
-
|
|
|
- def test_model_verify(self):
|
|
|
- assert verify("formalisms/SimpleClassDiagrams", "formalisms/SimpleClassDiagrams") == "OK"
|
|
|
-
|
|
|
- def test_model_empty_instantiate(self):
|
|
|
- model_add("formalisms/Empty", "formalisms/SimpleClassDiagrams")
|
|
|
- instantiate("formalisms/Empty", "Class", ID="A")
|
|
|
- assert element_list("formalisms/Empty") == set([("A", "Class")])
|
|
|
- compare_locations("formalisms", set(["Empty"]))
|
|
|
- compare_locations("type mappings/formalisms", set(["Empty"]))
|
|
|
-
|
|
|
- def test_model_overwrite(self):
|
|
|
- model_add("formalisms/Empty", "formalisms/SimpleClassDiagrams")
|
|
|
- assert element_list("formalisms/Empty") == set([])
|
|
|
- instantiate("formalisms/Empty", "Class", ID="A")
|
|
|
- assert element_list("formalisms/Empty") == set([("A", "Class")])
|
|
|
- model_overwrite("formalisms/Empty")
|
|
|
- assert element_list("formalisms/Empty") == set([])
|
|
|
- compare_locations("formalisms", set(["Empty"]))
|
|
|
- compare_locations("type mappings/formalisms", set(["Empty"]))
|
|
|
- assert element_list("formalisms/Empty") == set([])
|
|
|
-
|
|
|
- instantiate("formalisms/Empty", "Class", ID="B")
|
|
|
- compare_locations("formalisms", set(["Empty"]))
|
|
|
- compare_locations("type mappings/formalisms", set(["Empty"]))
|
|
|
-
|
|
|
- def test_transform_add_MT(self):
|
|
|
- model_add("formalisms/PetriNet", "formalisms/SimpleClassDiagrams", open("integration/code/petrinets.mvc", "r").read())
|
|
|
- compare_locations("formalisms", set(["PetriNet"]))
|
|
|
- compare_locations("type mappings/formalisms", set(["PetriNet"]))
|
|
|
- transformation_add_MT({"PetriNet": "formalisms/PetriNet"}, {}, "models/print_pn", open("integration/code/pn_print.mvc").read())
|
|
|
-
|
|
|
- compare_locations("formalisms", set(["PetriNet"]))
|
|
|
- compare_locations("models", set(["print_pn"]))
|
|
|
- compare_locations("RAMified/models", set(["print_pn"]))
|
|
|
- compare_locations("merged/models", set(["print_pn"]))
|
|
|
- compare_locations("type mappings/formalisms", set(["PetriNet"]))
|
|
|
- compare_locations("type mappings/models", set(["print_pn"]))
|
|
|
- compare_locations("type mappings/RAMified/models", set(["print_pn"]))
|
|
|
- compare_locations("type mappings/merged/models", set(["print_pn"]))
|
|
|
-
|
|
|
- def test_transform_add_MT_pn_print_exec(self):
|
|
|
- log = []
|
|
|
-
|
|
|
- def callback(value):
|
|
|
- log.append(value)
|
|
|
-
|
|
|
- model_add("formalisms/PetriNet", "formalisms/SimpleClassDiagrams", open("integration/code/pn_runtime.mvc", "r").read())
|
|
|
- model_add("models/my_pn", "formalisms/PetriNet", open("integration/code/pn_runtime_model.mvc", "r").read())
|
|
|
- compare_locations("models", set(["my_pn"]))
|
|
|
- compare_locations("type mappings/models", set(["my_pn"]))
|
|
|
-
|
|
|
- transformation_add_MT({"PetriNet": "formalisms/PetriNet"}, {}, "models/print_pn", open("integration/code/pn_print.mvc").read())
|
|
|
- compare_locations("models", set(["my_pn", "print_pn"]))
|
|
|
- compare_locations("type mappings/models", set(["my_pn", "print_pn"]))
|
|
|
-
|
|
|
- assert transformation_execute_MT("models/print_pn", {"PetriNet": "models/my_pn"}, {}, callback) == True
|
|
|
-
|
|
|
- assert set(log) == set(['"p1" --> 1',
|
|
|
- '"p2" --> 2',
|
|
|
- '"p3" --> 3'])
|
|
|
-
|
|
|
- def test_transform_add_MT_pn_simulate(self):
|
|
|
- """
|
|
|
- This method tests the execution of a somewhat realistic use of the Modelverse and its core functions, through the use of a simple Petri nets example.
|
|
|
- First, Petri net metamodels are created for both the design language and the runtime language.
|
|
|
- Both languages only differ marginally from each other, with the runtime language only adding information on the currently selected transition for execution.
|
|
|
- Afterwards, a trivial Petri net model is created in the design language.
|
|
|
- This part tests the domain-specific and meta-modelling concepts of the Modelverse.
|
|
|
-
|
|
|
- After all models are created, transformations are defined to map between both languages: from design to runtime, and vice versa.
|
|
|
- Additional transformations are created for in-place model simulation and the printing of a Petri net model.
|
|
|
- This tests the modification of models, through the use of model transformations.
|
|
|
- Due to the use of a separate design and runtime language, we test exogenous transformations.
|
|
|
- The simulation transformation takes a single step in the Petri net model, by firing one of the applicable transitions, and therefore tests endogenous transformations.
|
|
|
- """
|
|
|
- log = []
|
|
|
-
|
|
|
- def callback(value):
|
|
|
- log.append(value)
|
|
|
-
|
|
|
- model_add("formalisms/PetriNet", "formalisms/SimpleClassDiagrams", open("integration/code/pn_design.mvc", "r").read())
|
|
|
- model_add("formalisms/PetriNet_Runtime", "formalisms/SimpleClassDiagrams", open("integration/code/pn_runtime.mvc", "r").read())
|
|
|
-
|
|
|
- model_add("models/my_pn", "formalisms/PetriNet", open("integration/code/pn_design_model.mvc", "r").read())
|
|
|
-
|
|
|
- def add_tracability_D2R():
|
|
|
- instantiate(None, "Association", ("PetriNet/Place", "PetriNet_Runtime/Place"), ID="D2R_PlaceLink")
|
|
|
- instantiate(None, "Association", ("PetriNet/Transition", "PetriNet_Runtime/Transition"), ID="D2R_TransitionLink")
|
|
|
-
|
|
|
- def add_tracability_R2D():
|
|
|
- instantiate(None, "Association", ("PetriNet_Runtime/Place", "PetriNet/Place"), ID="R2D_PlaceLink")
|
|
|
- instantiate(None, "Association", ("PetriNet_Runtime/Transition", "PetriNet/Transition"), ID="R2D_TransitionLink")
|
|
|
-
|
|
|
- transformation_add_MT({"PetriNet": "formalisms/PetriNet"}, {}, "models/print_pn", open("integration/code/pn_print.mvc").read())
|
|
|
- transformation_add_MT({"PetriNet": "formalisms/PetriNet"}, {"PetriNet_Runtime": "formalisms/PetriNet_Runtime"}, "models/pn_design_to_runtime", open("integration/code/pn_design_to_runtime.mvc").read(), add_tracability_D2R)
|
|
|
- transformation_add_MT({"PetriNet_Runtime": "formalisms/PetriNet_Runtime"}, {"PetriNet_Runtime": "formalisms/PetriNet_Runtime"}, "models/pn_simulate", open("integration/code/pn_simulate.mvc").read())
|
|
|
- transformation_add_MT({"PetriNet_Runtime": "formalisms/PetriNet_Runtime"}, {"PetriNet": "formalisms/PetriNet"}, "models/pn_runtime_to_design", open("integration/code/pn_runtime_to_design.mvc").read(), add_tracability_R2D)
|
|
|
-
|
|
|
- log = []
|
|
|
- assert transformation_execute_MT("models/print_pn", {"PetriNet": "models/my_pn"}, {}, callback) == True
|
|
|
- assert set(log) == set(['"p1" --> 1',
|
|
|
- '"p2" --> 2',
|
|
|
- '"p3" --> 3'])
|
|
|
-
|
|
|
- assert transformation_execute_MT("models/pn_design_to_runtime", {"PetriNet": "models/my_pn"}, {"PetriNet_Runtime": "models/my_pn_RT"}) == True
|
|
|
- assert transformation_execute_MT("models/pn_simulate", {"PetriNet_Runtime": "models/my_pn_RT"}, {"PetriNet_Runtime": "models/my_pn_RT"}) == True
|
|
|
- assert transformation_execute_MT("models/pn_runtime_to_design", {"PetriNet_Runtime": "models/my_pn_RT"}, {"PetriNet": "models/my_pn"}) == True
|
|
|
-
|
|
|
- log = []
|
|
|
- assert transformation_execute_MT("models/print_pn", {"PetriNet": "models/my_pn"}, {}, callback) == True
|
|
|
- assert set(log) == set(['"p1" --> 0',
|
|
|
- '"p2" --> 1',
|
|
|
- '"p3" --> 5'])
|
|
|
-
|
|
|
- def test_transform_add_AL_pn_simulate(self):
|
|
|
- log = []
|
|
|
-
|
|
|
- def callback(value):
|
|
|
- log.append(value)
|
|
|
-
|
|
|
- model_add("formalisms/PetriNet", "formalisms/SimpleClassDiagrams", open("integration/code/pn_design.mvc", "r").read())
|
|
|
- model_add("formalisms/PetriNet_Runtime", "formalisms/SimpleClassDiagrams", open("integration/code/pn_runtime.mvc", "r").read())
|
|
|
-
|
|
|
- model_add("models/my_pn", "formalisms/PetriNet", open("integration/code/pn_design_model.mvc", "r").read())
|
|
|
-
|
|
|
- def add_tracability_D2R():
|
|
|
- instantiate(None, "Association", ("PetriNet/Place", "PetriNet_Runtime/Place"), ID="D2R_PlaceLink")
|
|
|
- instantiate(None, "Association", ("PetriNet/Transition", "PetriNet_Runtime/Transition"), ID="D2R_TransitionLink")
|
|
|
-
|
|
|
- def add_tracability_R2D():
|
|
|
- instantiate(None, "Association", ("PetriNet_Runtime/Place", "PetriNet/Place"), ID="R2D_PlaceLink")
|
|
|
- instantiate(None, "Association", ("PetriNet_Runtime/Transition", "PetriNet/Transition"), ID="R2D_TransitionLink")
|
|
|
-
|
|
|
- transformation_add_MT({"PetriNet": "formalisms/PetriNet"}, {}, "models/print_pn", open("integration/code/pn_print.mvc").read())
|
|
|
- transformation_add_MT({"PetriNet": "formalisms/PetriNet"}, {"PetriNet_Runtime": "formalisms/PetriNet_Runtime"}, "models/pn_design_to_runtime", open("integration/code/pn_design_to_runtime.mvc").read(), add_tracability_D2R)
|
|
|
- transformation_add_AL({"PetriNet_Runtime": "formalisms/PetriNet_Runtime"}, {"PetriNet_Runtime": "formalisms/PetriNet_Runtime"}, "models/pn_simulate", open("integration/code/pn_simulate.alc").read())
|
|
|
- transformation_add_MT({"PetriNet_Runtime": "formalisms/PetriNet_Runtime"}, {"PetriNet": "formalisms/PetriNet"}, "models/pn_runtime_to_design", open("integration/code/pn_runtime_to_design.mvc").read(), add_tracability_R2D)
|
|
|
-
|
|
|
- log = []
|
|
|
- assert transformation_execute_MT("models/print_pn", {"PetriNet": "models/my_pn"}, {}, callback) == True
|
|
|
- assert set(log) == set(['"p1" --> 1',
|
|
|
- '"p2" --> 2',
|
|
|
- '"p3" --> 3'])
|
|
|
-
|
|
|
- assert transformation_execute_MT("models/pn_design_to_runtime", {"PetriNet": "models/my_pn"}, {"PetriNet_Runtime": "models/my_pn_RT"}) == True
|
|
|
- assert transformation_execute_AL("models/pn_simulate", {"PetriNet_Runtime": "models/my_pn_RT"}, {"PetriNet_Runtime": "models/my_pn_RT"}) == True
|
|
|
- assert transformation_execute_MT("models/pn_runtime_to_design", {"PetriNet_Runtime": "models/my_pn_RT"}, {"PetriNet": "models/my_pn"}) == True
|
|
|
-
|
|
|
- log = []
|
|
|
- assert transformation_execute_MT("models/print_pn", {"PetriNet": "models/my_pn"}, {}, callback) == True
|
|
|
- assert set(log) == set(['"p1" --> 0',
|
|
|
- '"p2" --> 1',
|
|
|
- '"p3" --> 5'])
|
|
|
-
|
|
|
- def test_transform_add_MANUAL_pn_simulate(self):
|
|
|
- log = []
|
|
|
-
|
|
|
- def callback(value):
|
|
|
- log.append(value)
|
|
|
-
|
|
|
- def manual_callback():
|
|
|
- p1 = instantiate(None, "PetriNet_Runtime/Place")
|
|
|
- attr_assign(None, p1, "tokens", 1)
|
|
|
- attr_assign(None, p1, "name", "p1")
|
|
|
- p2 = instantiate(None, "PetriNet_Runtime/Place")
|
|
|
- attr_assign(None, p2, "tokens", 2)
|
|
|
- attr_assign(None, p2, "name", "p2")
|
|
|
- p3 = instantiate(None, "PetriNet_Runtime/Place")
|
|
|
- attr_assign(None, p3, "tokens", 3)
|
|
|
- attr_assign(None, p3, "name", "p3")
|
|
|
- t1 = instantiate(None, "PetriNet_Runtime/Transition")
|
|
|
- attr_assign(None, t1, "name", "t1")
|
|
|
- attr_assign(None, t1, "executing", False)
|
|
|
- p2t1 = instantiate(None, "PetriNet_Runtime/P2T", (p1, t1))
|
|
|
- attr_assign(None, p2t1, "weight", 1)
|
|
|
- p2t2 = instantiate(None, "PetriNet_Runtime/P2T", (p2, t1))
|
|
|
- attr_assign(None, p2t2, "weight", 1)
|
|
|
- t2p1 = instantiate(None, "PetriNet_Runtime/T2P", (t1, p3))
|
|
|
- attr_assign(None, t2p1, "weight", 2)
|
|
|
-
|
|
|
- model_add("formalisms/PetriNet", "formalisms/SimpleClassDiagrams", open("integration/code/pn_design.mvc", "r").read())
|
|
|
- model_add("formalisms/PetriNet_Runtime", "formalisms/SimpleClassDiagrams", open("integration/code/pn_runtime.mvc", "r").read())
|
|
|
-
|
|
|
- model_add("models/my_pn", "formalisms/PetriNet", open("integration/code/pn_design_model.mvc", "r").read())
|
|
|
-
|
|
|
- def add_tracability_D2R():
|
|
|
- instantiate(None, "Association", ("PetriNet/Place", "PetriNet_Runtime/Place"), ID="D2R_PlaceLink")
|
|
|
- instantiate(None, "Association", ("PetriNet/Transition", "PetriNet_Runtime/Transition"), ID="D2R_TransitionLink")
|
|
|
-
|
|
|
- def add_tracability_R2D():
|
|
|
- instantiate(None, "Association", ("PetriNet_Runtime/Place", "PetriNet/Place"), ID="R2D_PlaceLink")
|
|
|
- instantiate(None, "Association", ("PetriNet_Runtime/Transition", "PetriNet/Transition"), ID="R2D_TransitionLink")
|
|
|
-
|
|
|
- transformation_add_MT({"PetriNet": "formalisms/PetriNet"}, {}, "models/print_pn", open("integration/code/pn_print.mvc").read())
|
|
|
- transformation_add_MANUAL({"PetriNet": "formalisms/PetriNet"}, {"PetriNet_Runtime": "formalisms/PetriNet_Runtime"}, "models/pn_design_to_runtime", add_tracability_D2R)
|
|
|
- transformation_add_AL({"PetriNet_Runtime": "formalisms/PetriNet_Runtime"}, {"PetriNet_Runtime": "formalisms/PetriNet_Runtime"}, "models/pn_simulate", open("integration/code/pn_simulate.alc").read())
|
|
|
- transformation_add_MT({"PetriNet_Runtime": "formalisms/PetriNet_Runtime"}, {"PetriNet": "formalisms/PetriNet"}, "models/pn_runtime_to_design", open("integration/code/pn_runtime_to_design.mvc").read(), add_tracability_R2D)
|
|
|
-
|
|
|
- log = []
|
|
|
- assert transformation_execute_MT("models/print_pn", {"PetriNet": "models/my_pn"}, {}, callback) == True
|
|
|
- assert set(log) == set(['"p1" --> 1',
|
|
|
- '"p2" --> 2',
|
|
|
- '"p3" --> 3'])
|
|
|
-
|
|
|
- assert transformation_execute_MANUAL("models/pn_design_to_runtime", {"PetriNet": "models/my_pn"}, {"PetriNet_Runtime": "models/my_pn_RT"}, manual_callback) == True
|
|
|
- assert transformation_execute_AL("models/pn_simulate", {"PetriNet_Runtime": "models/my_pn_RT"}, {"PetriNet_Runtime": "models/my_pn_RT"}) == True
|
|
|
- assert transformation_execute_MT("models/pn_runtime_to_design", {"PetriNet_Runtime": "models/my_pn_RT"}, {"PetriNet": "models/my_pn"}) == True
|
|
|
-
|
|
|
- log = []
|
|
|
- assert transformation_execute_MT("models/print_pn", {"PetriNet": "models/my_pn"}, {}, callback) == True
|
|
|
- assert set(log) == set(['"p1" --> 0',
|
|
|
- '"p2" --> 1',
|
|
|
- '"p3" --> 5'])
|
|
|
-
|
|
|
- def test_process_model_trivial_pn_bigmain(self):
|
|
|
- model_add("formalisms/PetriNet", "formalisms/SimpleClassDiagrams", open("integration/code/pn_design.mvc", "r").read())
|
|
|
- model_add("formalisms/ReachabilityGraph", "formalisms/SimpleClassDiagrams", open("integration/code/reachability_graph.mvc", "r").read())
|
|
|
- model_add("models/pn_reachability", "formalisms/ProcessModel", open("integration/code/pm_pn_reachability.mvc", "r").read())
|
|
|
- transformation_add_MT({}, {"PetriNet": "formalisms/PetriNet"}, "models/initialize_PN", open("integration/code/initialize_PN.mvc", "r").read())
|
|
|
- transformation_add_MANUAL({"PetriNet": "formalisms/PetriNet"}, {"PetriNet": "formalisms/PetriNet"}, "models/refine_PN")
|
|
|
- transformation_add_AL({"PetriNet": "formalisms/PetriNet"}, {"ReachabilityGraph": "formalisms/ReachabilityGraph"}, "models/reachability", open("integration/code/reachability.alc", "r").read())
|
|
|
- transformation_add_MT({"ReachabilityGraph": "formalisms/ReachabilityGraph"}, {}, "models/reachability_print", open("integration/code/reachabilitygraph_print.mvc", 'r').read())
|
|
|
-
|
|
|
- def callback_refine_PN():
|
|
|
- p1 = instantiate(None, "PetriNet/Place")
|
|
|
- attr_assign(None, p1, "name", "p1")
|
|
|
- attr_assign(None, p1, "tokens", 1)
|
|
|
-
|
|
|
- t1 = instantiate(None, "PetriNet/Transition")
|
|
|
- attr_assign(None, t1, "name", "t1")
|
|
|
-
|
|
|
- p2t = instantiate(None, "PetriNet/P2T", (p1, t1))
|
|
|
- attr_assign(None, p2t, "weight", 1)
|
|
|
-
|
|
|
- log = set([])
|
|
|
- def callback_print(value):
|
|
|
- log.add(value)
|
|
|
-
|
|
|
- process_execute("models/pn_reachability", "my_", {"models/refine_PN": callback_refine_PN, "models/reachability_print": callback_print})
|
|
|
-
|
|
|
- assert log == set(['"0": {"p1": 1, }',
|
|
|
- '"1": {"p1": 0, }',
|
|
|
- '"0" --["t1"]--> "1"'])
|
|
|
-
|
|
|
- def test_process_model_trivial_pn_subfunction(self):
|
|
|
- model_add("formalisms/PetriNet", "formalisms/SimpleClassDiagrams", open("integration/code/pn_design.mvc", "r").read())
|
|
|
- model_add("formalisms/ReachabilityGraph", "formalisms/SimpleClassDiagrams", open("integration/code/reachability_graph.mvc", "r").read())
|
|
|
- model_add("models/pn_reachability", "formalisms/ProcessModel", open("integration/code/pm_pn_reachability.mvc", "r").read())
|
|
|
- transformation_add_MT({}, {"PetriNet": "formalisms/PetriNet"}, "models/initialize_PN", open("integration/code/initialize_PN.mvc", "r").read())
|
|
|
- transformation_add_MANUAL({"PetriNet": "formalisms/PetriNet"}, {"PetriNet": "formalisms/PetriNet"}, "models/refine_PN")
|
|
|
- transformation_add_AL({"PetriNet": "formalisms/PetriNet"}, {"ReachabilityGraph": "formalisms/ReachabilityGraph"}, "models/reachability", open("integration/code/reachability_subfunction.alc", "r").read())
|
|
|
- transformation_add_MT({"ReachabilityGraph": "formalisms/ReachabilityGraph"}, {}, "models/reachability_print", open("integration/code/reachabilitygraph_print.mvc", 'r').read())
|
|
|
-
|
|
|
- def callback_refine_PN():
|
|
|
- p1 = instantiate(None, "PetriNet/Place")
|
|
|
- attr_assign(None, p1, "name", "p1")
|
|
|
- attr_assign(None, p1, "tokens", 1)
|
|
|
-
|
|
|
- t1 = instantiate(None, "PetriNet/Transition")
|
|
|
- attr_assign(None, t1, "name", "t1")
|
|
|
-
|
|
|
- p2t = instantiate(None, "PetriNet/P2T", (p1, t1))
|
|
|
- attr_assign(None, p2t, "weight", 1)
|
|
|
-
|
|
|
- log = set([])
|
|
|
- def callback_print(value):
|
|
|
- log.add(value)
|
|
|
-
|
|
|
- process_execute("models/pn_reachability", "my_", {"models/refine_PN": callback_refine_PN, "models/reachability_print": callback_print})
|
|
|
-
|
|
|
- assert log == set(['"0": {"p1": 1, }',
|
|
|
- '"1": {"p1": 0, }',
|
|
|
- '"0" --["t1"]--> "1"'])
|
|
|
-
|
|
|
- def test_render(self):
|
|
|
- model_add("formalisms/CausalBlockDiagrams", "formalisms/SimpleClassDiagrams", open("integration/code/cbd_design.mvc", 'r').read())
|
|
|
- model_add("formalisms/MM_rendered_graphical", "formalisms/SimpleClassDiagrams", open("models/MM_rendered_graphical.mvc", 'r').read())
|
|
|
- model_add("models/my_CBD", "formalisms/CausalBlockDiagrams", open("integration/code/my_cbd.mvc", 'r').read())
|
|
|
-
|
|
|
- def add_tracability():
|
|
|
- instantiate(None, "Association", ("abstract/Block", "rendered/Group"), ID="TracabilityLink")
|
|
|
-
|
|
|
- transformation_add_MT({"abstract": "formalisms/CausalBlockDiagrams", "rendered": "formalisms/MM_rendered_graphical"}, {"abstract": "formalisms/CausalBlockDiagrams", "rendered": "formalisms/MM_rendered_graphical"}, "models/render_graphical_CBD", open("models/CBD_mapper.mvc", 'r').read(), add_tracability)
|
|
|
- result = model_render("models/my_CBD", "models/render_graphical_CBD")
|
|
|
- assert len(result) == 23
|
|
|
-
|
|
|
- def test_switch_MM(self):
|
|
|
- model_add("formalisms/PetriNet", "formalisms/SimpleClassDiagrams", open("integration/code/pn_design.mvc", "r").read())
|
|
|
- model_add("models/my_pn", "formalisms/PetriNet", open("integration/code/pn_design_model.mvc", "r").read())
|
|
|
-
|
|
|
- alter_context("formalisms/PetriNet", "formalisms/SimpleClassDiagrams")
|
|
|
- alter_context("models/my_pn", "formalisms/PetriNet")
|
|
|
-
|
|
|
- got = element_list_nice("formalisms/PetriNet")
|
|
|
- expected = \
|
|
|
- [{'id': 'Natural', 'type': 'SimpleAttribute', 'constraint': None},
|
|
|
- {'id': 'String', 'type': 'SimpleAttribute', 'constraint': None},
|
|
|
- {'id': 'Place', 'type': 'Class', 'lower_cardinality': None, 'upper_cardinality': None, 'constraint': None},
|
|
|
- {'id': 'Place_tokens', 'type': 'AttributeLink', '__source': 'Place', '__target': 'Natural', 'name': 'tokens', 'optional': False, 'constraint': None},
|
|
|
- {'id': 'Place_name', 'type': 'AttributeLink', '__source': 'Place', '__target': 'String', 'name': 'name', 'optional': False, 'constraint': None},
|
|
|
- {'id': 'Transition', 'type': 'Class', 'lower_cardinality': None, 'upper_cardinality': None, 'constraint': None},
|
|
|
- {'id': 'Transition_name', 'type': 'AttributeLink', '__source': 'Transition', '__target': 'String', 'name': 'name', 'optional': False, 'constraint': None},
|
|
|
- {'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': None},
|
|
|
- {'id': 'P2T_weight', 'type': 'AttributeLink', '__source': 'P2T', '__target': 'Natural', 'name': 'weight', 'optional': False, 'constraint': None},
|
|
|
- {'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': None},
|
|
|
- {'id': 'T2P_weight', 'type': 'AttributeLink', '__source': 'T2P', '__target': 'Natural', 'name': 'weight', 'optional': False, 'constraint': None}
|
|
|
- ]
|
|
|
- compare_unordered_lists(got, expected)
|
|
|
-
|
|
|
- got = element_list_nice("models/my_pn")
|
|
|
- expected = \
|
|
|
- [{'id': 'p1', 'type': 'Place', 'tokens': 1, 'name': 'p1'},
|
|
|
- {'id': 'p2', 'type': 'Place', 'tokens': 2, 'name': 'p2'},
|
|
|
- {'id': 'p3', 'type': 'Place', 'tokens': 3, 'name': 'p3'},
|
|
|
- {'id': 't1', 'type': 'Transition', 'name': 't1'},
|
|
|
- {'id': '__0', 'type': 'P2T', '__source': 'p1', '__target': 't1', 'weight': 1},
|
|
|
- {'id': '__1', 'type': 'P2T', '__source': 'p2', '__target': 't1', 'weight': 1},
|
|
|
- {'id': '__2', 'type': 'T2P', '__source': 't1', '__target': 'p3', 'weight': 2}
|
|
|
- ]
|
|
|
- compare_unordered_lists(got, expected)
|
|
|
-
|
|
|
- alter_context("formalisms/PetriNet", "formalisms/Bottom")
|
|
|
- alter_context("models/my_pn", "formalisms/Bottom")
|
|
|
-
|
|
|
- count_nodes = 0
|
|
|
- count_edges = 0
|
|
|
- for entry in element_list_nice("formalisms/PetriNet"):
|
|
|
- assert entry["type"] in ["Node", "Edge"]
|
|
|
- if entry["type"] == "Node":
|
|
|
- assert len(entry) == 2
|
|
|
- count_nodes += 1
|
|
|
- else:
|
|
|
- assert len(entry) == 4
|
|
|
- count_edges += 1
|
|
|
- assert count_nodes == 14
|
|
|
- assert count_edges == 17
|
|
|
-
|
|
|
- count_nodes = 0
|
|
|
- count_edges = 0
|
|
|
- for entry in element_list_nice("models/my_pn"):
|
|
|
- assert entry["type"] in ["Node", "Edge"]
|
|
|
- if entry["type"] == "Node":
|
|
|
- assert len(entry) == 2
|
|
|
- count_nodes += 1
|
|
|
- else:
|
|
|
- assert len(entry) == 4
|
|
|
- count_edges += 1
|
|
|
- assert count_nodes == 14
|
|
|
- assert count_edges == 13
|
|
|
-
|
|
|
- alter_context("formalisms/PetriNet", "formalisms/PetriNet")
|
|
|
- alter_context("models/my_pn", "formalisms/SimpleClassDiagrams")
|
|
|
- try:
|
|
|
- element_list_nice("formalisms/PetriNet")
|
|
|
- self.fail()
|
|
|
- except:
|
|
|
- pass
|
|
|
- try:
|
|
|
- element_list_nice("models/my_pn")
|
|
|
- self.fail()
|
|
|
- except:
|
|
|
- pass
|