Browse Source

Fixes for Windows

Yentl Van Tendeloo 3 years ago
parent
commit
e898f1b5b4
2 changed files with 167 additions and 181 deletions
  1. 1 10
      kernel/modelverse_kernel/main.py
  2. 166 171
      unit/test_all.py

+ 1 - 10
kernel/modelverse_kernel/main.py

@@ -324,7 +324,7 @@ class ModelverseKernel(object):
 
             param_list = "{" + ", ".join(["'%s': %s" % (k, v) for k, v in param_list.items()]) + "}"
             actual_computation = "$$INDENT$$%s, = yield [('CALL_ARGS', [_mvk.execute_jit, (_root, %s['id'], _taskname, %s)])]\n" % (value, func_name, param_list)
-                
+
             if indent == 0:
                 # No indent, meaning that we use it inline
                 # Therefore, we output the prev and value individually
@@ -334,7 +334,6 @@ class ModelverseKernel(object):
                 # Therefore, we only do the yield
                 prev, instruction = prev_func_name + computation, actual_computation.replace("$$INDENT$$", "  " * indent)
 
-
         elif inst_type["value"] == "access":
             value, = yield [("RD", [inst, "var"])]
             (prev, instruction), = yield [("CALL_ARGS", [self.print_instruction, (value, 0, nested_indent)])]
@@ -375,7 +374,6 @@ class ModelverseKernel(object):
             print("Ignoring mutable or unreadable: %s" % suggested_name)
             raise jit.JitCompilationFailedException("FAIL")
 
-        #print("Reading function: %s" % suggested_name)
         (prev, printed), = yield [("CALL_ARGS", [self.print_instruction, (inst, 1)])]
         preamble = "  _mvk = kwargs['mvk']\n" + \
                    "  _root = kwargs['task_root']\n" + \
@@ -385,13 +383,10 @@ class ModelverseKernel(object):
                    "    _globs, = yield [('RD', [kwargs['task_root'], 'globals'])]\n" + \
                    "    _mvk.jit.cache[_taskname]['_globs'] = _globs\n"
         printed = preamble + prev + printed
-        #print("Total printed function: ")
         if params:
             func = "def " + suggested_name + "(" + ", ".join([chr(ord('a') + i) for i in range(len(params))]) + ", **kwargs):\n" + "".join(["  var_%s = %s\n" % (param, chr(ord('a') + i)) for i, param in enumerate(params)]) + printed
         else:
             func = "def " + suggested_name + "(**kwargs):\n" + printed
-        
-        #print(func)
 
         try:
             # Try to write out the generated code
@@ -462,7 +457,6 @@ class ModelverseKernel(object):
             result, = yield [("RD", [params['a']['id'], params['b']['value']])]
             result = {'id': result}
         else:
-            #print("CALL " + str(self.jit.get_global_name(inst)) + " --> " + params)
             results = yield [("CALL_KWARGS", [compiled_func, params])]
             if results is None:
                 raise Exception("%s: primitive finished without returning a value!" % (self.debug_info[taskname]))
@@ -477,9 +471,6 @@ class ModelverseKernel(object):
                 ("RD", [task_frame, "prev"]),
                 ("RD", [task_frame, primitive_functions.EXCEPTION_RETURN_KEY])]
 
-            #if self.debug_info[self.taskname]:
-            #    self.debug_info[self.taskname].pop()
-
             if "id" not in result:
                 result['id'], = yield [("CNV", [result['value']])]
 

+ 166 - 171
unit/test_all.py

@@ -19,11 +19,161 @@ def null_operation(model):
 
 def model_is_empty_operation(model):
     assert model is None
+    
+def ops_manual_callback(model):
+    p1 = instantiate(model, "PetriNet_Runtime/Place")
+    p2 = instantiate(model, "PetriNet_Runtime/Place")
+    p3 = instantiate(model, "PetriNet_Runtime/Place")
+    t1 = instantiate(model, "PetriNet_Runtime/Transition")
+    p2t1 = instantiate(model, "PetriNet_Runtime/P2T", (p1, t1))
+    p2t2 = instantiate(model, "PetriNet_Runtime/P2T", (p2, t1))
+    t2p1 = instantiate(model, "PetriNet_Runtime/T2P", (t1, p3))
+    attr_assign(model, p1, "tokens", 1)
+    attr_assign(model, p1, "name", "p1")
+    attr_assign(model, p2, "tokens", 2)
+    attr_assign(model, p2, "name", "p2")
+    attr_assign(model, p3, "tokens", 3)
+    attr_assign(model, p3, "name", "p3")
+    attr_assign(model, t1, "name", "t1")
+    attr_assign(model, t1, "executing", False)
+    attr_assign(model, p2t1, "weight", 1)
+    attr_assign(model, p2t2, "weight", 1)
+    attr_assign(model, t2p1, "weight", 2)
+
+def pn_subfunc_callback_refine_PN(model):
+    p1 = instantiate(model, "PetriNet/Place")
+    attr_assign(model, p1, "name", "p1")
+    attr_assign(model, p1, "tokens", 1)
+
+    t1 = instantiate(model, "PetriNet/Transition")
+    attr_assign(model, t1, "name", "t1")
+
+    p2t = instantiate(model, "PetriNet/P2T", (p1, t1))
+    attr_assign(model, p2t, "weight", 1)
+
+def render_add_tracability(model):
+    instantiate(model, "Association", ("abstract/Block", "rendered/Group"), ID="TracabilityLink")
+            
+def ops_add_tracability_D2R(model):
+    instantiate(model, "Association", ("PetriNet/Place", "PetriNet_Runtime/Place"), ID="D2R_PlaceLink")
+    instantiate(model, "Association", ("PetriNet/Transition", "PetriNet_Runtime/Transition"), ID="D2R_TransitionLink")
 
+def ops_add_tracability_R2D(model):
+    instantiate(model, "Association", ("PetriNet_Runtime/Place", "PetriNet/Place"), ID="R2D_PlaceLink")
+    instantiate(model, "Association", ("PetriNet_Runtime/Transition", "PetriNet/Transition"), ID="R2D_TransitionLink")
+            
 def operation_exec_1(model):
     assert model is not None
     assert [{"__id": "MODEL_A/__0", "__type": "MODEL_A/A", "name": None}] == element_list_nice(model)
     instantiate(model, "MODEL_B/B")
+    
+def operation_MAN_0(model):
+    # Check if both are present
+    lst = element_list_nice(model)
+    assert len(lst) == 6
+    assert {"__id": "MODEL_A/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_A/A", "__type": "Class", "name": "A", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_A/A_name", "__type": "AttributeLink", "__source": "MODEL_A/A", "__target": "MODEL_A/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/B", "__type": "Class", "name": "B", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/B_name", "__type": "AttributeLink", "__source": "MODEL_B/B", "__target": "MODEL_B/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
+
+    # Do minor merge operation
+    instantiate(model, "Association", edge=("MODEL_A/A", "MODEL_B/B"), ID="trace")
+
+    # Check again
+    lst = element_list_nice(model)
+    assert len(lst) == 7
+    assert {"__id": "MODEL_A/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_A/A", "__type": "Class", "name": "A", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_A/A_name", "__type": "AttributeLink", "__source": "MODEL_A/A", "__target": "MODEL_A/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/B", "__type": "Class", "name": "B", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/B_name", "__type": "AttributeLink", "__source": "MODEL_B/B", "__target": "MODEL_B/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
+    assert {"__id": "trace", "__type": "Association", "__source": "MODEL_A/A", "__target": "MODEL_B/B", "name": None, "source_lower_cardinality": None, "source_upper_cardinality": None, "target_lower_cardinality": None, "target_upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}, "lower_cardinality": None, "upper_cardinality": None} in lst
+
+def operation_MAN_1(model):
+    # Check if both are present
+    lst = element_list_nice(model)
+    assert len(lst) == 6
+    assert {"__id": "MODEL_A/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_A/A", "__type": "Class", "name": "A", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_A/A_name", "__type": "AttributeLink", "__source": "MODEL_A/A", "__target": "MODEL_A/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/B", "__type": "Class", "name": "B", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/B_name", "__type": "AttributeLink", "__source": "MODEL_B/B", "__target": "MODEL_B/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
+            
+def operation_MT_0(model):
+    # Check if both are present
+    lst = element_list_nice(model)
+    assert len(lst) == 6
+    assert {"__id": "MODEL_A/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_A/A", "__type": "Class", "name": "A", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_A/A_name", "__type": "AttributeLink", "__source": "MODEL_A/A", "__target": "MODEL_A/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/B", "__type": "Class", "name": "B", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/B_name", "__type": "AttributeLink", "__source": "MODEL_B/B", "__target": "MODEL_B/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
+
+    # Do minor merge operation
+    instantiate(model, "Association", edge=("MODEL_A/A", "MODEL_B/B"), ID="trace")
+
+    # Check again
+    lst = element_list_nice(model)
+    assert len(lst) == 7
+    assert {"__id": "MODEL_A/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_A/A", "__type": "Class", "name": "A", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_A/A_name", "__type": "AttributeLink", "__source": "MODEL_A/A", "__target": "MODEL_A/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/B", "__type": "Class", "name": "B", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/B_name", "__type": "AttributeLink", "__source": "MODEL_B/B", "__target": "MODEL_B/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
+    assert {"__id": "trace", "__type": "Association", "__source": "MODEL_A/A", "__target": "MODEL_B/B", "name": None, "source_lower_cardinality": None, "source_upper_cardinality": None, "target_lower_cardinality": None, "target_upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}, "lower_cardinality": None, "upper_cardinality": None} in lst
+
+def operation_MT_1(model):
+    # Check if both are present
+    lst = element_list_nice(model)
+    assert len(lst) == 6
+    assert {"__id": "MODEL_A/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_A/A", "__type": "Class", "name": "A", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_A/A_name", "__type": "AttributeLink", "__source": "MODEL_A/A", "__target": "MODEL_A/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/B", "__type": "Class", "name": "B", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/B_name", "__type": "AttributeLink", "__source": "MODEL_B/B", "__target": "MODEL_B/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
+
+def operation_AL_0(model):
+    # Check if both are present
+    lst = element_list_nice(model)
+    assert len(lst) == 6
+    assert {"__id": "MODEL_A/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_A/A", "__type": "Class", "name": "A", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_A/A_name", "__type": "AttributeLink", "__source": "MODEL_A/A", "__target": "MODEL_A/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/B", "__type": "Class", "name": "B", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/B_name", "__type": "AttributeLink", "__source": "MODEL_B/B", "__target": "MODEL_B/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
+
+    # Do minor merge operation
+    instantiate(model, "Association", edge=("MODEL_A/A", "MODEL_B/B"), ID="trace")
+
+    # Check again
+    lst = element_list_nice(model)
+    assert len(lst) == 7
+    assert {"__id": "MODEL_A/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_A/A", "__type": "Class", "name": "A", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_A/A_name", "__type": "AttributeLink", "__source": "MODEL_A/A", "__target": "MODEL_A/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/B", "__type": "Class", "name": "B", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/B_name", "__type": "AttributeLink", "__source": "MODEL_B/B", "__target": "MODEL_B/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
+    assert {"__id": "trace", "__type": "Association", "__source": "MODEL_A/A", "__target": "MODEL_B/B", "name": None, "source_lower_cardinality": None, "source_upper_cardinality": None, "target_lower_cardinality": None, "target_upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}, "lower_cardinality": None, "upper_cardinality": None} in lst
+
+def operation_AL_1(model):
+    # Check if both are present
+    lst = element_list_nice(model)
+    assert len(lst) == 6
+    assert {"__id": "MODEL_A/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_A/A", "__type": "Class", "name": "A", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_A/A_name", "__type": "AttributeLink", "__source": "MODEL_A/A", "__target": "MODEL_A/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/B", "__type": "Class", "name": "B", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
+    assert {"__id": "MODEL_B/B_name", "__type": "AttributeLink", "__source": "MODEL_B/B", "__target": "MODEL_B/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
 
 model_hierarchy = \
             {"formalisms/": {"SimpleClassDiagrams": {},
@@ -4065,45 +4215,8 @@ class TestModelverse(unittest.TestCase):
         transformation_add_MANUAL({"MODEL_A": "users/user/test/A"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/c")
 
         # Add a transformation with normal signature and merged metamodel changes
-        def operation(model):
-            # Check if both are present
-            lst = element_list_nice(model)
-            assert len(lst) == 6
-            assert {"__id": "MODEL_A/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_A/A", "__type": "Class", "name": "A", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_A/A_name", "__type": "AttributeLink", "__source": "MODEL_A/A", "__target": "MODEL_A/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/B", "__type": "Class", "name": "B", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/B_name", "__type": "AttributeLink", "__source": "MODEL_B/B", "__target": "MODEL_B/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
-
-            # Do minor merge operation
-            instantiate(model, "Association", edge=("MODEL_A/A", "MODEL_B/B"), ID="trace")
-
-            # Check again
-            lst = element_list_nice(model)
-            assert len(lst) == 7
-            assert {"__id": "MODEL_A/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_A/A", "__type": "Class", "name": "A", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_A/A_name", "__type": "AttributeLink", "__source": "MODEL_A/A", "__target": "MODEL_A/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/B", "__type": "Class", "name": "B", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/B_name", "__type": "AttributeLink", "__source": "MODEL_B/B", "__target": "MODEL_B/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
-            assert {"__id": "trace", "__type": "Association", "__source": "MODEL_A/A", "__target": "MODEL_B/B", "name": None, "source_lower_cardinality": None, "source_upper_cardinality": None, "target_lower_cardinality": None, "target_upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}, "lower_cardinality": None, "upper_cardinality": None} in lst
-
-        transformation_add_MANUAL({"MODEL_A": "users/user/test/A"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/d", operation)
-        
-        def operation(model):
-            # Check if both are present
-            lst = element_list_nice(model)
-            assert len(lst) == 6
-            assert {"__id": "MODEL_A/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_A/A", "__type": "Class", "name": "A", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_A/A_name", "__type": "AttributeLink", "__source": "MODEL_A/A", "__target": "MODEL_A/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/B", "__type": "Class", "name": "B", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/B_name", "__type": "AttributeLink", "__source": "MODEL_B/B", "__target": "MODEL_B/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
-
-        transformation_add_MANUAL({"MODEL_A": "users/user/test/A", "MODEL_B": "users/user/test/B"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/e", operation)
+        transformation_add_MANUAL({"MODEL_A": "users/user/test/A"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/d", operation_MAN_0)
+        transformation_add_MANUAL({"MODEL_A": "users/user/test/A", "MODEL_B": "users/user/test/B"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/e", operation_MAN_1)
 
         try:
             transformation_add_MANUAL({"MODEL_A": "users/user/test/A", "MODEL_B": "users/user/test/B"}, {"MODEL_B": "users/user/test/A"}, "users/user/test/f")
@@ -4116,9 +4229,7 @@ class TestModelverse(unittest.TestCase):
 
         # Add a transformation with empty signature and a callback
         try:
-            def operation(model):
-                pass
-            transformation_add_MANUAL({}, {}, "users/user/test/h", operation)
+            transformation_add_MANUAL({}, {}, "users/user/test/h", null_operation)
             self.fail()
         except CallbackOnEmptySignature:
             assert "h" not in model_list("users/user/test")
@@ -4204,45 +4315,10 @@ class TestModelverse(unittest.TestCase):
         transformation_add_AL({"MODEL_A": "users/user/test/A"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/c", default_function)
 
         # Add a transformation with normal signature and merged metamodel changes
-        def operation(model):
-            # Check if both are present
-            lst = element_list_nice(model)
-            assert len(lst) == 6
-            assert {"__id": "MODEL_A/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_A/A", "__type": "Class", "name": "A", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_A/A_name", "__type": "AttributeLink", "__source": "MODEL_A/A", "__target": "MODEL_A/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/B", "__type": "Class", "name": "B", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/B_name", "__type": "AttributeLink", "__source": "MODEL_B/B", "__target": "MODEL_B/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
-
-            # Do minor merge operation
-            instantiate(model, "Association", edge=("MODEL_A/A", "MODEL_B/B"), ID="trace")
-
-            # Check again
-            lst = element_list_nice(model)
-            assert len(lst) == 7
-            assert {"__id": "MODEL_A/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_A/A", "__type": "Class", "name": "A", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_A/A_name", "__type": "AttributeLink", "__source": "MODEL_A/A", "__target": "MODEL_A/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/B", "__type": "Class", "name": "B", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/B_name", "__type": "AttributeLink", "__source": "MODEL_B/B", "__target": "MODEL_B/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
-            assert {"__id": "trace", "__type": "Association", "__source": "MODEL_A/A", "__target": "MODEL_B/B", "name": None, "source_lower_cardinality": None, "source_upper_cardinality": None, "target_lower_cardinality": None, "target_upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}, "lower_cardinality": None, "upper_cardinality": None} in lst
-
-        transformation_add_AL({"MODEL_A": "users/user/test/A"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/d", default_function, operation)
-        
-        def operation(model):
-            # Check if both are present
-            lst = element_list_nice(model)
-            assert len(lst) == 6
-            assert {"__id": "MODEL_A/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_A/A", "__type": "Class", "name": "A", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_A/A_name", "__type": "AttributeLink", "__source": "MODEL_A/A", "__target": "MODEL_A/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/B", "__type": "Class", "name": "B", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/B_name", "__type": "AttributeLink", "__source": "MODEL_B/B", "__target": "MODEL_B/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
 
-        transformation_add_AL({"MODEL_A": "users/user/test/A", "MODEL_B": "users/user/test/B"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/e", default_function, operation)
+
+        transformation_add_AL({"MODEL_A": "users/user/test/A"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/d", default_function, operation_AL_0)
+        transformation_add_AL({"MODEL_A": "users/user/test/A", "MODEL_B": "users/user/test/B"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/e", default_function, operation_AL_1)
 
         try:
             transformation_add_AL({"MODEL_A": "users/user/test/A", "MODEL_B": "users/user/test/B"}, {"MODEL_B": "users/user/test/A"}, "users/user/test/f", default_function)
@@ -4255,9 +4331,7 @@ class TestModelverse(unittest.TestCase):
 
         # Add a transformation with empty signature and a callback
         try:
-            def operation(model):
-                pass
-            transformation_add_AL({}, {}, "users/user/test/h", default_function, operation)
+            transformation_add_AL({}, {}, "users/user/test/h", default_function, null_operation)
             self.fail()
         except CallbackOnEmptySignature:
             assert "h" not in model_list("users/user/test")
@@ -4350,45 +4424,10 @@ class TestModelverse(unittest.TestCase):
         transformation_add_MT({"MODEL_A": "users/user/test/A"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/c", default_function)
 
         # Add a transformation with normal signature and merged metamodel changes
-        def operation(model):
-            # Check if both are present
-            lst = element_list_nice(model)
-            assert len(lst) == 6
-            assert {"__id": "MODEL_A/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_A/A", "__type": "Class", "name": "A", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_A/A_name", "__type": "AttributeLink", "__source": "MODEL_A/A", "__target": "MODEL_A/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/B", "__type": "Class", "name": "B", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/B_name", "__type": "AttributeLink", "__source": "MODEL_B/B", "__target": "MODEL_B/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
-
-            # Do minor merge operation
-            instantiate(model, "Association", edge=("MODEL_A/A", "MODEL_B/B"), ID="trace")
-
-            # Check again
-            lst = element_list_nice(model)
-            assert len(lst) == 7
-            assert {"__id": "MODEL_A/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_A/A", "__type": "Class", "name": "A", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_A/A_name", "__type": "AttributeLink", "__source": "MODEL_A/A", "__target": "MODEL_A/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/B", "__type": "Class", "name": "B", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/B_name", "__type": "AttributeLink", "__source": "MODEL_B/B", "__target": "MODEL_B/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
-            assert {"__id": "trace", "__type": "Association", "__source": "MODEL_A/A", "__target": "MODEL_B/B", "name": None, "source_lower_cardinality": None, "source_upper_cardinality": None, "target_lower_cardinality": None, "target_upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}, "lower_cardinality": None, "upper_cardinality": None} in lst
-
-        transformation_add_MT({"MODEL_A": "users/user/test/A"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/d", default_function, operation)
-        
-        def operation(model):
-            # Check if both are present
-            lst = element_list_nice(model)
-            assert len(lst) == 6
-            assert {"__id": "MODEL_A/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_A/A", "__type": "Class", "name": "A", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_A/A_name", "__type": "AttributeLink", "__source": "MODEL_A/A", "__target": "MODEL_A/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/String", "__type": "SimpleAttribute", "name": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/B", "__type": "Class", "name": "B", "lower_cardinality": None, "upper_cardinality": None, "abstract": None, "constraint": {"AL": ""}} in lst
-            assert {"__id": "MODEL_B/B_name", "__type": "AttributeLink", "__source": "MODEL_B/B", "__target": "MODEL_B/String", "name": "name", "optional": False, "constraint": {"AL": ""}} in lst
+        transformation_add_MT({"MODEL_A": "users/user/test/A"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/d", default_function, operation_MT_0)
+
 
-        transformation_add_MT({"MODEL_A": "users/user/test/A", "MODEL_B": "users/user/test/B"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/e", default_function, operation)
+        transformation_add_MT({"MODEL_A": "users/user/test/A", "MODEL_B": "users/user/test/B"}, {"MODEL_B": "users/user/test/B"}, "users/user/test/e", default_function, operation_MT_1)
 
         try:
             transformation_add_MT({"MODEL_A": "users/user/test/A", "MODEL_B": "users/user/test/B"}, {"MODEL_B": "users/user/test/A"}, "users/user/test/f", default_function)
@@ -4405,9 +4444,7 @@ class TestModelverse(unittest.TestCase):
 
         # Add a transformation with empty signature and a callback
         try:
-            def operation(model):
-                pass
-            transformation_add_MT({}, {}, "users/user/test/h", default_function, operation)
+            transformation_add_MT({}, {}, "users/user/test/h", default_function, null_operation)
             self.fail()
         except CallbackOnEmptySignature:
             assert "h" not in model_list("users/user/test")
@@ -5407,43 +5444,14 @@ class TestModelverse(unittest.TestCase):
     def test_operations(self):
         log = []
 
-        def manual_callback(model):
-            p1 = instantiate(model, "PetriNet_Runtime/Place")
-            p2 = instantiate(model, "PetriNet_Runtime/Place")
-            p3 = instantiate(model, "PetriNet_Runtime/Place")
-            t1 = instantiate(model, "PetriNet_Runtime/Transition")
-            p2t1 = instantiate(model, "PetriNet_Runtime/P2T", (p1, t1))
-            p2t2 = instantiate(model, "PetriNet_Runtime/P2T", (p2, t1))
-            t2p1 = instantiate(model, "PetriNet_Runtime/T2P", (t1, p3))
-            attr_assign(model, p1, "tokens", 1)
-            attr_assign(model, p1, "name", "p1")
-            attr_assign(model, p2, "tokens", 2)
-            attr_assign(model, p2, "name", "p2")
-            attr_assign(model, p3, "tokens", 3)
-            attr_assign(model, p3, "name", "p3")
-            attr_assign(model, t1, "name", "t1")
-            attr_assign(model, t1, "executing", False)
-            attr_assign(model, p2t1, "weight", 1)
-            attr_assign(model, p2t2, "weight", 1)
-            attr_assign(model, t2p1, "weight", 2)
-
         model_add("users/user/test/PetriNet", "formalisms/SimpleClassDiagrams", open("integration/code/pn_design.mvc", "r").read())
         model_add("users/user/test/PetriNet_Runtime", "formalisms/SimpleClassDiagrams", open("integration/code/pn_runtime.mvc", "r").read())
-
         model_add("users/user/test/my_pn", "users/user/test/PetriNet", open("integration/code/pn_design_model.mvc", "r").read())
 
-        def add_tracability_D2R(model):
-            instantiate(model, "Association", ("PetriNet/Place", "PetriNet_Runtime/Place"), ID="D2R_PlaceLink")
-            instantiate(model, "Association", ("PetriNet/Transition", "PetriNet_Runtime/Transition"), ID="D2R_TransitionLink")
-
-        def add_tracability_R2D(model):
-            instantiate(model, "Association", ("PetriNet_Runtime/Place", "PetriNet/Place"), ID="R2D_PlaceLink")
-            instantiate(model, "Association", ("PetriNet_Runtime/Transition", "PetriNet/Transition"), ID="R2D_TransitionLink")
-
         transformation_add_MT({"PetriNet": "users/user/test/PetriNet"}, {}, "users/user/test/print_pn", open("integration/code/pn_print.mvc").read())
-        transformation_add_MANUAL({"PetriNet": "users/user/test/PetriNet"}, {"PetriNet_Runtime": "users/user/test/PetriNet_Runtime"}, "users/user/test/pn_design_to_runtime", add_tracability_D2R)
+        transformation_add_MANUAL({"PetriNet": "users/user/test/PetriNet"}, {"PetriNet_Runtime": "users/user/test/PetriNet_Runtime"}, "users/user/test/pn_design_to_runtime", ops_add_tracability_D2R)
         transformation_add_AL({"PetriNet_Runtime": "users/user/test/PetriNet_Runtime"}, {"PetriNet_Runtime": "users/user/test/PetriNet_Runtime"}, "users/user/test/pn_simulate", open("integration/code/pn_simulate.alc").read())
-        transformation_add_MT({"PetriNet_Runtime": "users/user/test/PetriNet_Runtime"}, {"PetriNet": "users/user/test/PetriNet"}, "users/user/test/pn_runtime_to_design", open("integration/code/pn_runtime_to_design.mvc").read(), add_tracability_R2D)
+        transformation_add_MT({"PetriNet_Runtime": "users/user/test/PetriNet_Runtime"}, {"PetriNet": "users/user/test/PetriNet"}, "users/user/test/pn_runtime_to_design", open("integration/code/pn_runtime_to_design.mvc").read(), ops_add_tracability_R2D)
 
         log = []
         ctrl = log_output.Controller(log, keep_running=False)
@@ -5457,7 +5465,7 @@ class TestModelverse(unittest.TestCase):
                                 '"p2" --> 2',
                                 '"p3" --> 3'])
 
-        assert transformation_execute_MANUAL("users/user/test/pn_design_to_runtime", {"PetriNet": "users/user/test/my_pn"}, {"PetriNet_Runtime": "users/user/test/my_pn_RT"}, manual_callback) == True
+        assert transformation_execute_MANUAL("users/user/test/pn_design_to_runtime", {"PetriNet": "users/user/test/my_pn"}, {"PetriNet_Runtime": "users/user/test/my_pn_RT"}, ops_manual_callback) == True
         assert transformation_execute_AL("users/user/test/pn_simulate", {"PetriNet_Runtime": "users/user/test/my_pn_RT"}, {"PetriNet_Runtime": "users/user/test/my_pn_RT"}) == True
         assert transformation_execute_MT("users/user/test/pn_runtime_to_design", {"PetriNet_Runtime": "users/user/test/my_pn_RT"}, {"PetriNet": "users/user/test/my_pn"}) == True
 
@@ -5482,16 +5490,6 @@ class TestModelverse(unittest.TestCase):
         transformation_add_AL({"PetriNet": "users/user/test/PetriNet"}, {"ReachabilityGraph": "users/user/test/ReachabilityGraph"}, "users/user/test/reachability", open("integration/code/reachability_subfunction.alc", "r").read())
         transformation_add_MT({"ReachabilityGraph": "users/user/test/ReachabilityGraph"}, {}, "users/user/test/reachability_print", open("integration/code/reachabilitygraph_print.mvc", 'r').read())
 
-        def callback_refine_PN(model):
-            p1 = instantiate(model, "PetriNet/Place")
-            attr_assign(model, p1, "name", "p1")
-            attr_assign(model, p1, "tokens", 1)
-
-            t1 = instantiate(model, "PetriNet/Transition")
-            attr_assign(model, t1, "name", "t1")
-
-            p2t = instantiate(model, "PetriNet/P2T", (p1, t1))
-            attr_assign(model, p2t, "weight", 1)
 
         log = []
         ctrl = log_output.Controller(log, keep_running=False)
@@ -5499,7 +5497,7 @@ class TestModelverse(unittest.TestCase):
         thrd.daemon = True
         thrd.start()
 
-        process_execute("users/user/test/pn_reachability", {}, {"users/user/test/refine_PN": callback_refine_PN, "users/user/test/reachability_print": (ctrl, "inp", "outp")})
+        process_execute("users/user/test/pn_reachability", {}, {"users/user/test/refine_PN": pn_subfunc_callback_refine_PN, "users/user/test/reachability_print": (ctrl, "inp", "outp")})
         thrd.join()
 
         assert set(log) == set(['"0": {"p1": 1}',
@@ -5511,10 +5509,7 @@ class TestModelverse(unittest.TestCase):
         model_add("users/user/test/MM_rendered_graphical", "formalisms/SimpleClassDiagrams", open("integration/code/MM_rendered_graphical.mvc", 'r').read())
         model_add("users/user/test/my_CBD", "users/user/test/CausalBlockDiagrams", open("integration/code/my_cbd.mvc", 'r').read())
 
-        def add_tracability(model):
-            instantiate(model, "Association", ("abstract/Block", "rendered/Group"), ID="TracabilityLink")
-
-        transformation_add_MT({"abstract": "users/user/test/CausalBlockDiagrams", "rendered": "users/user/test/MM_rendered_graphical"}, {"abstract": "users/user/test/CausalBlockDiagrams", "rendered": "users/user/test/MM_rendered_graphical"}, "users/user/test/render_graphical_CBD", open("integration/code/CBD_mapper.mvc", 'r').read(), add_tracability)
+        transformation_add_MT({"abstract": "users/user/test/CausalBlockDiagrams", "rendered": "users/user/test/MM_rendered_graphical"}, {"abstract": "users/user/test/CausalBlockDiagrams", "rendered": "users/user/test/MM_rendered_graphical"}, "users/user/test/render_graphical_CBD", open("integration/code/CBD_mapper.mvc", 'r').read(), render_add_tracability)
         result = model_render("users/user/test/my_CBD", "users/user/test/render_graphical_CBD", "users/user/test/my_perceptualized_CBD")
 
         assert len(result) == 23