Explorar o código

Fixed at least one test for the pn_interface and made it a bigger one
(so less compilation necessary)

Yentl Van Tendeloo %!s(int64=9) %!d(string=hai) anos
pai
achega
ef72a7e463
Modificáronse 2 ficheiros con 114 adicións e 342 borrados
  1. 1 0
      integration/code/pn_interface.alc
  2. 113 342
      integration/test_pn_interface.py

+ 1 - 0
integration/code/pn_interface.alc

@@ -387,6 +387,7 @@ Element function initial_prompt():
 					output("Model exists; aborting")
 				else:
 					my_model = instantiate_model(root[mm_name])
+					dict_add(root, name, my_model)
 					petrinet_loaded(my_model)
 			else:
 				output("Unknown metamodel; aborting")

+ 113 - 342
integration/test_pn_interface.py

@@ -10,7 +10,15 @@ do_instantiate_simple = [
             "instantiate", "P2T", "p2t", "p1", "t1", "attr_add", "p2t", "weight", 2,
             "instantiate", "T2P", "t2p", "t1", "p2", "attr_add", "t2p", "weight", 1]
 
-did_instantiate_simple = new + loaded + prompt_model + instantiate_t1 + prompt_model + instantiate_p1 + prompt_model + instantiate_p2 + prompt_model + instantiate_p2t + prompt_model + instantiate_t2p + prompt_model
+instantiate_node = ["Type to instantiate?",
+                    "Name of new element?",
+                    "Instantiation successful!"]
+
+instantiate_edge = ["Type to instantiate?",
+                    "Name of new element?",
+                    "Source name?",
+                    "Destination name?",
+                    "Instantiation successful!"]
 
 all_files = [   "pn_interface.alc",
                 "primitives.alc",
@@ -22,95 +30,64 @@ all_files = [   "pn_interface.alc",
                 "--fast",
             ]
 
-greeting =          ["Welcome to the Model Management Interface, running live"
-                     " on the Modelverse!",
+greeting =          ["Welcome to the Model Management Interface, running live on the Modelverse!",
                      "Use 'help' command for a list of possible commands"]
-new =               ["Metamodel to instantiate?", "Name of model?"]
-new_fail =          ["Model exists; aborting"]
+new =               ["Metamodel to instantiate?",
+                     "Name of model?"]
+prompt =            ["Please give your command."]
 loaded =            ["Model loaded, ready for commands!",
-                     "Use 'help' command for a list of possible commands"]
-prompt_menu =       ["Please give your command."]
-prompt_model =      ["Please give your command."]
+                     "Use 'help' command for a list of possible commands"] + prompt
 load =              ["Model to load?"]
-load_fail =         ["Model not found; aborting"]
 instantiate =       ["Type to instantiate?"]
 instantiate_name =  ["Name of new element?"]
-instantiate_tokens= ["tokens : Integer?"]
 instantiate_ok =    ["Instantiation successful!"]
 instantiate_source= ["Source name?"]
 instantiate_destination = ["Destination name?"]
-instantiate_weight= ["weight : Integer?"]
-list_menu =         ["Found models:"]
-list_all =          set(["  PetriNets : SimpleClassDiagrams",
-                         "  SimpleClassDiagrams : SimpleClassDiagrams",
-                         "  LTM_bottom : LTM_bottom"])
-list_empty =        list_menu + [list_all]
-list_abc =          ["  abc : PetriNets"]
-list_def =          ["  def : PetriNets"]
-list_model =        ["List of all elements:"]
-list_p1 =           ["  p1 : Place"]
-list_p2 =           ["  p2 : Place"]
-list_t1 =           ["  t1 : Transition"]
-list_p2t =          ["  p2t : P2T"]
-list_t2p =          ["  t2p : T2P"]
-read =              ["Element to read?"]
-read_p1 =           ["Name: p1",
-                     "Type: Place",
-                     "Defines attributes:",
-                     "Attributes:",
-                     '   "tokens" : "Integer" = None']
-read_p1_1 =         ["Name: p1",
-                     "Type: Place",
-                     "Defines attributes:",
-                     "Attributes:",
-                     '   "tokens" : "Integer" = 1']
-read_p2 =           ["Name: p2",
-                     "Type: Place",
-                     "Defines attributes:",
-                     "Attributes:",
-                     '   "tokens" : "Integer" = None']
-read_t1 =           ["Name: t1",
-                     "Type: Transition",
-                     "Defines attributes:",
-                     "Attributes:"]
-read_p2t =          ["Name: p2t",
-                     "Type: P2T",
-                     "Source: p1",
-                     "Destination: t1",
-                     "Defines attributes:",
-                     "Attributes:",
-                     '   "weight" : "Integer" = None']
-read_t2p =          ["Name: t2p",
-                     "Type: T2P",
-                     "Source: t1",
-                     "Destination: p2",
-                     "Defines attributes:",
-                     "Attributes:",
-                     '   "weight" : "Integer" = None']
-read_fail =         ["Unknown element; aborting"]
-enabled =           ["Enabled transitions:"]
-enabled_t1 =        ["t1"]
-fire =              ["Transition to fire?"]
-fire_t1 =           ["  p1: 3",
-                     "  p2: 1"]
-fire_finish =       ["Transition fired!"]
-fire_unknown =      ["Unknown transition; aborting"]
-fire_no_enable =    ["Cannot fire if not enabled; aborting"]
-delete =            ["Model to delete?"]
-delete_ok =         ["Deleted!"]
-delete_fail =       ["Model not found; aborting"]
-rename_old =        ["Old name?"]
-rename_new =        ["New name?"]
-rename_ok =         ["Rename complete!"]
-rename_fail_not_exists = ["Model not found; aborting"]
-rename_fail_exists= ["Model exists; aborting"]
-rename_model_old =  ["Old name?"]
-rename_model_new =  ["New name?"]
-rename_model_ok =   ["Rename complete!"]
-rename_model_fail_not_exists = ["Unknown element; aborting"]
-rename_model_fail_exists= ["New name already used; aborting"]
-help_msg =          ["Currently no model is loaded, so your operations are "
-                     "limited to:",
+
+def list_menu(defined):
+    defined.append(("PetriNets", "SimpleClassDiagrams"))
+    defined.append(("SimpleClassDiagrams", "SimpleClassDiagrams"))
+    defined.append(("LTM_bottom", "LTM_bottom"))
+    return ["Found models:",
+            set(["  %s : %s" % (m, mm) for m, mm in defined])]
+
+def list_model(defined):
+    return ["List of all elements:",
+            set(["  %s : %s" % (m, mm) for m, mm in defined])]
+
+def read_node(name, t, defs, attrs):
+    return ["Element to read?",
+            "Name: %s" % name, 
+            "Type: %s" % t,
+            "Defines attributes:"] + \
+            (set(["  %s : %s" for m, mm in defs]) if defs else []) + \
+            ["Attributes:"] + \
+            (set(['  "%s" : "%s" = %s' for m, mm, v in attrs]) if attrs else [])
+
+def read_edge(name, t, src, dst, defs, attrs):
+    return ["Element to read?",
+            "Name: %s" % name, 
+            "Type: %s" % t,
+            "Source: %s" % src,
+            "Destination: %s" % dst,
+            "Defines attributes:"] + \
+            (set(["  %s : %s" for m, mm in defs]) if defs else []) + \
+            ["Attributes:"] + \
+            (set(['  "%s" : "%s" = %s' for m, mm, v in attrs]) if attrs else [])
+
+def enabled(enableds):
+    return ["Enabled transitions:"] + \
+            [set(enableds)]
+
+def fire(fired):
+    return ["Transition to fire?"] +  \
+            [set(["  %s: %s" % (p, v) for p, v in fired])] + \
+            ["Transition fired!"]
+
+delete =            ["Model to delete?", "Deleted!"]
+rename =            ["Old name?", "New name?", "Rename complete!"]
+
+help_root =         ["Currently no model is loaded, so your operations are limited to:",
                      "  new    -- Create a new model and save it for future use"
                      "  load   -- Load a previously made model",
                      "  rename -- Rename a previously made model",
@@ -120,159 +97,62 @@ help_msg =          ["Currently no model is loaded, so your operations are "
 verify_ok =         ["OK"]
 verify_fail_weight= ["Negative weight in arc p2t"]
 verify_fail_tokens= ["Negative number of tokens in Place p1"]
-verify_fail_structure = ["Source of model edge not typed by source of type: "
-                         "p2t"]
-list_types =        ["List of types:",
-                     "  Place : Class",
-                     "  Transition : Class",
-                     "  P2T : Association",
-                     "  T2P : Association"]
-modify =            ["Element to modify?"]
-modify_place =      ["   tokens : Integer"]
-modify_arc =        ["   weight : Integer"]
-modify_attribute =  ["Attribute to modify?"]
-modify_value =      ["New value?",
-                     "Modified!"]
-modify_fail_not_exists = ["Element does not exist; aborting"]
-modify_fail_no_attr=["Unknown attribute; aborting"]
-
-instantiate_place = instantiate + instantiate_name + instantiate_tokens +\
-                    instantiate_ok + prompt_model
-instantiate_transition = instantiate + instantiate_name + instantiate_ok +\
-                         prompt_model
-instantiate_arc = instantiate + instantiate_name + instantiate_source +\
-                  instantiate_destination + instantiate_weight +\
-                  instantiate_ok + prompt_model
-read_p1_full = read + read_p1 + prompt_model
-read_p2_full = read + read_p2 + prompt_model
-read_p1_as_p2 = read + [v.replace("p1", "p2") for v in read_p1] + prompt_model
-read_t1_full = read + read_t1 + prompt_model
-read_p2t_full = read + read_p2t + prompt_model
-read_t2p_full = read + read_t2p + prompt_model
-new_full = new + loaded + prompt_model
-delete_full = delete + delete_ok + prompt_menu
-init = greeting + prompt_menu
-rename_full = rename_old + rename_new + rename_ok + prompt_menu
-rename_model_full = rename_model_old + rename_model_new + rename_model_ok +\
-                    prompt_model
-help_full = help_msg + prompt_menu
-load_full = load + loaded + prompt_model
-verify_full = verify_ok + prompt_model
-types_full = list_types + prompt_model
-modify_place_full = modify + modify_place + modify_attribute + modify_value +\
-                    prompt_model
-
+verify_fail_structure = ["Source of model edge not typed by source of type: p2t"]
+
+init = greeting + prompt
+
+did_instantiate_simple = init + \
+                         new + \
+                         loaded +\
+                         instantiate_node +\
+                         prompt + \
+                         instantiate_node +\
+                         prompt + \
+                         instantiate_node +\
+                         prompt + \
+                         instantiate_edge +\
+                         prompt + \
+                         instantiate_edge +\
+                         prompt
+
+def list_types(t):
+    return ["List of types:"] + \
+            [set(["  %s : %s" % (m, mm) for m, mm in t])]
+
+modify =            ["Element to modify?", 
+                     "Attribute to modify?",
+                     "New value?",
+                     "Modified",]
 
 class TestPetrinetInterface(unittest.TestCase):
-    def test_po_pn_interface_new(self):
-        self.pn_interface_new("PO")
-
-    def test_co_pn_interface_new(self):
-        self.pn_interface_new("CO")
-
-    def pn_interface_new(self, mode):
-        self.assertTrue(run_file(all_files, ["help", "new", "PetriNets", "abc"],
-            init + help_full + new_full, mode))
-
-    def test_po_pn_interface_list_empty(self):
-        self.pn_interface_list_empty("PO")
-
-    def test_co_pn_interface_list_empty(self):
-        self.pn_interface_list_empty("CO")
-
-    def pn_interface_list_empty(self, mode):
-        self.assertTrue(run_file(all_files, ["list"],
-            init + list_empty + prompt_model, mode))
-
-    def test_po_pn_interface_list_one(self):
-        self.pn_interface_list_one("PO")
-
-    def test_co_pn_interface_list_one(self):
-        self.pn_interface_list_one("CO")
-
-    def pn_interface_list_one(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc", "exit", "list"], init + new_full + prompt_menu +
-            list_menu + [set(list_abc).union(list_all)] + prompt_menu, mode))
-
-    def test_po_pn_interface_list_two(self):
-        self.pn_interface_list_two("PO")
-
-    def test_co_pn_interface_list_two(self):
-        self.pn_interface_list_two("CO")
-
-    def pn_interface_list_two(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc", "exit", "new", "PetriNets", "def", "exit", "list"],
-            init + new_full + prompt_menu + new_full + prompt_menu +
-            list_menu + [set(list_abc).union(set(list_def)).union(list_all)] + prompt_menu, mode))
-
-    def test_po_pn_interface_rename(self):
-        self.pn_interface_rename("PO")
-
-    def test_co_pn_interface_rename(self):
-        self.pn_interface_rename("CO")
-
-    def pn_interface_rename(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc", "exit", "list", "rename", "abc", "def", "list",
-            "load", "abc", "load", "def", "exit", "list"],
-            init + new_full + prompt_menu + list_menu + [set(list_abc).union(list_all)] +
-            prompt_menu + rename_full + list_menu + [set(list_def).union(list_all)] + prompt_menu +
-            load + load_fail + prompt_menu + load_full + prompt_menu +
-            list_menu + [set(list_def).union(list_all)] + prompt_menu, mode))
-
-    def test_po_pn_interface_rename_fail_not_exists(self):
-        self.pn_interface_rename_fail_not_exists("PO")
-
-    def test_co_pn_interface_rename_fail_not_exists(self):
-        self.pn_interface_rename_fail_not_exists("CO")
-
-    def pn_interface_rename_fail_not_exists(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc", "exit", "list", "rename", "def", "list", "load",
-            "abc", "exit", "load", "def", "list"],
-            init + new_full + prompt_menu + list_menu + [set(list_abc).union(list_all)] +
-            prompt_menu + rename_old + rename_fail_not_exists + prompt_menu +
-            list_menu + [set(list_abc).union(list_all)] + prompt_menu + load_full + prompt_menu +
-            load + load_fail + prompt_menu + list_menu + [set(list_abc).union(list_all)] +
-            prompt_menu, mode))
-
-    def test_po_pn_interface_delete_only(self):
-        self.pn_interface_delete_only("PO")
-
-    def test_co_pn_interface_delete_only(self):
-        self.pn_interface_delete_only("CO")
-
-    def pn_interface_delete_only(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc", "exit", "delete", "abc", "list"],
-            init + new_full + prompt_menu + delete_full + list_empty +
-            prompt_menu, mode))
-
-    def test_po_pn_interface_delete(self):
-        self.pn_interface_delete("PO")
-
-    def test_co_pn_interface_delete(self):
-        self.pn_interface_delete("CO")
-
-    def pn_interface_delete(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc", "exit", "new", "PetriNets", "def", "exit", "delete", "abc",
-            "list"], init + new_full + prompt_menu + new_full + prompt_menu +
-            delete_full + list_menu + [set(list_def).union(list_all)] + prompt_menu, mode))
-
-    def test_po_pn_interface_delete_fail(self):
-        self.pn_interface_delete_fail("PO")
-
-    def test_co_pn_interface_delete_fail(self):
-        self.pn_interface_delete_fail("CO")
-
-    def pn_interface_delete_fail(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc", "exit", "delete", "def", "list"],
-            init + new_full + prompt_menu + delete + delete_fail +
-            prompt_menu + list_menu + [set(list_abc).union(list_all)] + prompt_menu, mode))
+    def test_po_pn_interface_manage(self):
+        self.pn_interface_manage("PO")
+
+    def test_co_pn_interface_manage(self):
+        self.pn_interface_manage("CO")
+
+    def pn_interface_manage(self, mode):
+        self.assertTrue(run_file(all_files,
+            ["list",
+             "new", "PetriNets", "abc", "exit",
+             "list",
+             "new", "PetriNets", "def", "exit",
+             "list",
+             "delete", "def",
+             "list",
+             "rename", "abc", "a",
+             "list",
+             "delete", "a",
+             "list",
+             ],
+            init + \
+                list_menu([]) + prompt + \
+                new + loaded + prompt + list_menu([("abc", "PetriNets")]) + prompt + \
+                new + loaded + prompt + list_menu([("abc", "PetriNets"), ("def", "PetriNets")]) + prompt + \
+                delete + prompt + list_menu([("abc", "PetriNets")]) + prompt + \
+                rename + prompt + list_menu([("a", "PetriNets")]) + prompt + \
+                delete + prompt + list_menu([]) + prompt,
+            mode))
 
     def test_po_pn_interface_new_reload(self):
         self.pn_interface_new_reload("PO")
@@ -285,38 +165,6 @@ class TestPetrinetInterface(unittest.TestCase):
             ["new", "PetriNets", "abc", "exit", "load", "abc"], init + new_full +
             prompt_menu + load_full, mode))
 
-    def test_po_pn_interface_new_fail(self):
-        self.pn_interface_new_fail("PO")
-
-    def test_co_pn_interface_new_fail(self):
-        self.pn_interface_new_fail("CO")
-
-    def pn_interface_new_fail(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc", "exit", "new", "PetriNets", "abc"], init + new_full +
-            prompt_menu + new + new_fail + prompt_menu, mode))
-
-    def test_po_pn_interface_load_fail(self):
-        self.pn_interface_load_fail("PO")
-
-    def test_co_pn_interface_load_fail(self):
-        self.pn_interface_load_fail("CO")
-
-    def pn_interface_load_fail(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc", "exit", "load", "def"], init + new_full +
-            prompt_menu + load + load_fail + prompt_menu, mode))
-
-    def test_po_pn_interface_load_empty(self):
-        self.pn_interface_load_empty("PO")
-
-    def test_co_pn_interface_load_empty(self):
-        self.pn_interface_load_empty("CO")
-
-    def pn_interface_load_empty(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["load", "def"], init + load + load_fail + prompt_menu, mode))
-
     def test_po_pn_interface_new_list_empty(self):
         self.pn_interface_new_list_empty("PO")
 
@@ -576,80 +424,3 @@ class TestPetrinetInterface(unittest.TestCase):
             instantiate_tokens + instantiate_ok + prompt_model + read +
             read_p1 + prompt_menu + modify_place_full + read + read_p1_1 +
             prompt_menu, mode))
-
-    def test_po_pn_interface_modify_unknown(self):
-        self.pn_interface_modify_unknown("PO")
-
-    def test_co_pn_interface_modify_unknown(self):
-        self.pn_interface_modify_unknown("CO")
-
-    def pn_interface_modify_unknown(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc", "modify", "p1"],
-            init + new_full + modify + modify_fail_not_exists + prompt_model,
-            mode))
-
-    def test_po_pn_interface_modify_place_attr(self):
-        self.pn_interface_modify_place_attr("PO")
-
-    def test_co_pn_interface_modify_place_attr(self):
-        self.pn_interface_modify_place_attr("CO")
-
-    def pn_interface_modify_place_attr(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc", "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
-                "read", "p1", "modify", "p1", "tok", "read", "p1"],
-            init + new_full + instantiate + instantiate_name +
-            instantiate_tokens + instantiate_ok + prompt_model + read +
-            read_p1 + prompt_menu + modify + modify_place + modify_attribute +
-            modify_fail_no_attr + prompt_model + read + read_p1 +
-            prompt_model, mode))
-
-    def test_po_pn_interface_rename_place(self):
-        self.pn_interface_rename_place("PO")
-
-    def test_co_pn_interface_rename_place(self):
-        self.pn_interface_rename_place("CO")
-
-    def pn_interface_rename_place(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc", "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
-                "rename", "p1", "p2", "read", "p1", "read", "p2"],
-            init + new_full + instantiate + instantiate_name +
-            instantiate_tokens + instantiate_ok + prompt_model +
-            rename_model_full + read + read_fail + prompt_model +
-            read_p1_as_p2, mode))
-
-    def test_po_pn_interface_rename_exists(self):
-        self.pn_interface_rename_exists("PO")
-
-    def test_co_pn_interface_rename_exists(self):
-        self.pn_interface_rename_exists("CO")
-
-    def pn_interface_rename_exists(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc", "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5, "instantiate",
-             "Place", "p2", "attr_add", "p2", "tokens", 0, "rename", "p1", "p2", "read", "p1", "read",
-             "p2"],
-            init + new_full + instantiate + instantiate_name +
-            instantiate_tokens + instantiate_ok + prompt_model +
-            instantiate + instantiate_name + instantiate_tokens +
-            instantiate_ok + prompt_model + rename_model_old +
-            rename_model_new + rename_model_fail_exists + prompt_model +
-            read + read_p1 + prompt_model + read + read_p2 + prompt_model,
-            mode))
-
-    def test_po_pn_interface_rename_not_exists(self):
-        self.pn_interface_rename_not_exists("PO")
-
-    def test_co_pn_interface_rename_not_exists(self):
-        self.pn_interface_rename_not_exists("CO")
-
-    def pn_interface_rename_not_exists(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc", "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5, "rename", "p2",
-             "read", "p1", "read", "p2"],
-            init + new_full + instantiate + instantiate_name +
-            instantiate_tokens + instantiate_ok + prompt_model +
-            rename_model_old + rename_model_fail_not_exists + prompt_model +
-            read_p1_full + read + read_fail + prompt_model, mode))