Parcourir la source

Fix all tests and make them (slightly) more restrictive

Yentl Van Tendeloo il y a 8 ans
Parent
commit
8868b6a09e

+ 37 - 12
bootstrap/core_algorithm.alc

@@ -342,13 +342,16 @@ String function create_folders(user_id : String, folder_name : String):
 			cummul = string_join(cummul + "/", elem)
 
 		if (get_entry_id(cummul) == ""):
-			// Element does not exist yet!
-			new_entry = instantiate_node(core, "Folder", "")
-			instantiate_attribute(core, new_entry, "name", cummul)
-			instantiate_attribute(core, new_entry, "permissions", "200")
-			instantiate_link(core, "contains", "", prev, new_entry)
-			instantiate_link(core, "group", "", new_entry, get_group_id("nobody"))
-			instantiate_link(core, "owner", "", new_entry, user_id)
+			if (allow_write(user_id, prev)):
+				// Element does not exist yet!
+				new_entry = instantiate_node(core, "Folder", "")
+				instantiate_attribute(core, new_entry, "name", cummul)
+				instantiate_attribute(core, new_entry, "permissions", "200")
+				instantiate_link(core, "contains", "", prev, new_entry)
+				instantiate_link(core, "group", "", new_entry, get_group_id("nobody"))
+				instantiate_link(core, "owner", "", new_entry, user_id)
+			else:
+				return read_root()!
 
 		prev = get_entry_id(cummul)
 		i = i + 1
@@ -381,8 +384,6 @@ String function export_typing(model : Element, name : String, user_id : String):
 	instance_of = instantiate_link(core, "instanceOf", "", result, get_entry_id("formalisms/TypeMapping"))
 	instantiate_link(core, "semantics", "", instance_of, get_entry_id("models/conformance_mv"))
 
-	log("Stored new typing: " + result)
-
 	return result!
 
 Void function model_create(model : Element, name : String, user_id : String, type_id : String, kind : String):
@@ -1202,13 +1203,29 @@ String function cmd_model_modify(user_id : String, model_name : String, metamode
 	else:
 		return "Model not found: " + model_name!
 
+Void function model_delete(model_id : String):
+	if (read_type(core, model_id) == "Folder"):
+		// Folder, so delete all containing elements as well!
+		Element elems
+		elems = allAssociationDestinations(core, model_id, "contains")
+		while (set_len(elems) > 0):
+			model_delete(set_pop(elems))
+
+		// Delete self
+		model_delete_element(core, model_id)
+	else:
+		// Only delete this element
+		model_delete_element(core, model_id)
+	
+	return!
+
 String function cmd_model_delete(user_id : String, model_name : String):
 	String model_id
 	model_id = get_entry_id(model_name)
 
 	if (model_id != ""):
 		if (allow_write(user_id, model_id)):
-			model_delete_element(core, model_id)
+			model_delete(model_id)
 			return "Success"!
 		else:
 			return "Permission denied to model: " + model_name!
@@ -1876,6 +1893,15 @@ String function cmd_element_list_nice(user_id : String, model_name : String, met
 	else:
 		return "No such model: " + model_name!
 
+String function cmd_folder_create(user_id : String, folder_name : String):
+	if (get_entry_id(folder_name) == ""):
+		if (element_neq(create_folders(user_id, folder_name), read_root())):
+			return "Success"!
+		else:
+			return "Permission denied to folder: " + folder_name!
+	else:
+		return "Folder alreay exists: " + folder_name!
+
 Void function user_function_skip_init(user_id : String):
 	String cmd
 	String result
@@ -1979,8 +2005,7 @@ Void function user_function_skip_init(user_id : String):
 			// as the current user will have been deleted
 			return !
 		elif (cmd == "folder_create"):
-			// TODO (see create_folders operation)
-			cmd = "FAIL"
+			output(cmd_folder_create(user_id, single_input("Folder name?")))
 		elif (cmd == "add_conformance"):
 			// TODO
 			cmd = "FAIL"

+ 8 - 8
integration/code/pm_pn_reachability.mvc

@@ -1,25 +1,25 @@
 Start start {}
 Finish finish {}
 Exec initializePN {
-    name = "models/initialize_PN"
+    name = "test/initialize_PN"
 }
 Exec refinePN {
-    name = "models/refine_PN"
+    name = "test/refine_PN"
 }
 Exec reachability {
-    name = "models/reachability"
+    name = "test/reachability"
 }
 Exec reachability_print{
-    name = "models/reachability_print"
+    name = "test/reachability_print"
 }
 
 Data pn {
-    name = "models/pn"
-    type = "formalisms/PetriNet"
+    name = "test/pn"
+    type = "test/PetriNet"
 }
 Data reachability_graph {
-    name = "models/reachability"
-    type = "formalisms/ReachabilityGraph"
+    name = "test/reachability"
+    type = "test/ReachabilityGraph"
 }
 
 Next (start, initializePN) {}

+ 8 - 0
integration/test_powerwindow.py

@@ -169,6 +169,11 @@ class TestPowerWindow(unittest.TestCase):
         cb_query = get_function("models/query_model.mvc")
         cb_arch = get_function("models/architecture_model.mvc")
 
+        self.error_path = None
+
+        def got_path(path):
+            self.error_path = path
+
         callbacks = {
                 "models/revise_req": cb_req,
                 "models/revise_plant": cb_plant,
@@ -176,6 +181,7 @@ class TestPowerWindow(unittest.TestCase):
                 "models/revise_control": cb_ctrl,
                 "models/revise_query": cb_query,
                 "models/revise_architecture": cb_arch,
+                "models/bfs": got_path,
             }
 
         try:
@@ -187,3 +193,5 @@ class TestPowerWindow(unittest.TestCase):
         if called != 11:
             print(called)
             raise Exception("Not executed sufficiently:" + str(called))
+
+        assert self.error_path != None

+ 0 - 1
models/bfs.alc

@@ -36,7 +36,6 @@ Boolean function bfs(model : Element):
 			// Found an error path!
 			log("Found error path!")
 			log(list_to_string(path))
-			output("Found error path:")
 			output(list_to_string(path))
 			break!
 

+ 26 - 8
unit/test_all.py

@@ -104,6 +104,7 @@ class TestModelverse(unittest.TestCase):
                                            ("administration/", "admin", "admin", "110"),
                                            ("type mappings/", "admin", "admin", "221"),
                                            ("users/", "admin", "admin", "221"),
+                                           ("test/", "admin", "nobody", "200"),
                                           ])
 
     def test_modelling(self):
@@ -165,8 +166,6 @@ class TestModelverse(unittest.TestCase):
         compare_locations("type mappings/test", set(["Empty"]))
 
     def test_operations(self):
-        folder_create("test")
-
         log = []
 
         def callback(value):
@@ -226,10 +225,15 @@ class TestModelverse(unittest.TestCase):
                                 '"p2" --> 1',
                                 '"p3" --> 5'])
 
+        model_delete("RAMified")
+        model_delete("merged")
+        model_delete("type mappings/RAMified")
+        model_delete("type mappings/merged")
+
     def test_process_model_trivial_pn_subfunction(self):
         model_add("test/PetriNet", "formalisms/SimpleClassDiagrams", open("integration/code/pn_design.mvc", "r").read())
         model_add("test/ReachabilityGraph", "formalisms/SimpleClassDiagrams", open("integration/code/reachability_graph.mvc", "r").read())
-        model_add("test/pn_reachability", "test/ProcessModel", open("integration/code/pm_pn_reachability.mvc", "r").read())
+        model_add("test/pn_reachability", "formalisms/ProcessModel", open("integration/code/pm_pn_reachability.mvc", "r").read())
         transformation_add_MT({}, {"PetriNet": "test/PetriNet"}, "test/initialize_PN", open("integration/code/initialize_PN.mvc", "r").read())
         transformation_add_MANUAL({"PetriNet": "test/PetriNet"}, {"PetriNet": "test/PetriNet"}, "test/refine_PN")
         transformation_add_AL({"PetriNet": "test/PetriNet"}, {"ReachabilityGraph": "test/ReachabilityGraph"}, "test/reachability", open("integration/code/reachability_subfunction.alc", "r").read())
@@ -250,24 +254,38 @@ class TestModelverse(unittest.TestCase):
         def callback_print(value):
             log.add(value)
 
-        process_execute("test/pn_reachability", "my_", {"test/refine_PN": callback_refine_PN, "test/reachability_print": callback_print})
+        process_execute("test/pn_reachability", "", {"test/refine_PN": callback_refine_PN, "test/reachability_print": callback_print})
 
         assert log == set(['"0": {"p1": 1, }',
                            '"1": {"p1": 0, }',
                            '"0" --["t1"]--> "1"'])
 
+        model_delete("RAMified")
+        model_delete("merged")
+        model_delete("type mappings/RAMified")
+        model_delete("type mappings/merged")
+
     def test_render(self):
         model_add("test/CausalBlockDiagrams", "formalisms/SimpleClassDiagrams", open("integration/code/cbd_design.mvc", 'r').read())
-        model_add("test/MM_rendered_graphical", "formalisms/SimpleClassDiagrams", open("test/MM_rendered_graphical.mvc", 'r').read())
+        model_add("test/MM_rendered_graphical", "formalisms/SimpleClassDiagrams", open("models/MM_rendered_graphical.mvc", 'r').read())
         model_add("test/my_CBD", "test/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": "test/CausalBlockDiagrams", "rendered": "test/MM_rendered_graphical"}, {"abstract": "test/CausalBlockDiagrams", "rendered": "test/MM_rendered_graphical"}, "test/render_graphical_CBD", open("test/CBD_mapper.mvc", 'r').read(), add_tracability)
+        transformation_add_MT({"abstract": "test/CausalBlockDiagrams", "rendered": "test/MM_rendered_graphical"}, {"abstract": "test/CausalBlockDiagrams", "rendered": "test/MM_rendered_graphical"}, "test/render_graphical_CBD", open("models/CBD_mapper.mvc", 'r').read(), add_tracability)
         result = model_render("test/my_CBD", "test/render_graphical_CBD")
         assert len(result) == 23
 
+        model_delete("RAMified")
+        model_delete("merged")
+        model_delete("type mappings/RAMified")
+        model_delete("type mappings/merged")
+        model_delete("rendered")
+        model_delete("tracability")
+        model_delete("type mappings/rendered")
+        model_delete("type mappings/tracability")
+
     def test_switch_MM(self):
         model_add("test/PetriNet", "formalisms/SimpleClassDiagrams", open("integration/code/pn_design.mvc", "r").read())
         model_add("test/my_pn", "test/PetriNet", open("integration/code/pn_design_model.mvc", "r").read())
@@ -303,8 +321,8 @@ class TestModelverse(unittest.TestCase):
             ]
         compare_unordered_lists(got, expected)
 
-        alter_context("test/PetriNet", "test/Bottom")
-        alter_context("test/my_pn", "test/Bottom")
+        alter_context("test/PetriNet", "formalisms/Bottom")
+        alter_context("test/my_pn", "formalisms/Bottom")
 
         count_nodes = 0
         count_edges = 0

+ 10 - 1
wrappers/modelverse.py

@@ -597,7 +597,9 @@ def process_execute(process_name, prefix, callbacks):
     _input(["process_execute", process_name, prefix])
     _handle_output("Success")
 
-    while _output() != "Success":
+    reuse = False
+    while reuse or _output() != "Success":
+        reuse = False
         output = _last_output()
         if output.startswith("Enacting "):
             # Next activity!
@@ -612,6 +614,8 @@ def process_execute(process_name, prefix, callbacks):
                         mode = MODE_MODELLING
                         if reply is not None:
                             _input(reply)
+                    if _last_output().startswith("Enacting "):
+                        reuse = True
                 elif t == "ManualOperation":
                     _handle_output("Please perform manual operation ")
                     _output("Model loaded, ready for commands!")
@@ -979,3 +983,8 @@ def add_conformance(model_name, metamodel_name, partial_type_mapping=None):
     _goto_mode(MODE_MODELLING)
     _input(["add_conformance", model_name, metamodel_name])
     _handle_output("Success")
+
+def folder_create(folder_name):
+    _goto_mode(MODE_MODELLING)
+    _input(["folder_create", folder_name])
+    _handle_output("Success")