Browse Source

Even more tests

Yentl Van Tendeloo 9 years ago
parent
commit
dad8e6dce2
2 changed files with 26 additions and 65 deletions
  1. 2 3
      integration/code/pn_interface.alc
  2. 24 62
      integration/test_pn_interface.py

+ 2 - 3
integration/code/pn_interface.alc

@@ -206,7 +206,6 @@ Element function petrinet_loaded(model : Element):
 			if (dict_in(model["model"], model_name)):
 				Element attrs
 				attrs = getAttributeList(model, model_name)
-				output(print_dict(attrs))
 				String attr_name
 				output("Which attribute do you wish to assign?")
 				attr_name = input()
@@ -290,13 +289,13 @@ Element function petrinet_loaded(model : Element):
 				attr_keys_pn = dict_keys(attr_list_pn)
 				while (0 < read_nr_out(attr_keys_pn)):
 					attr_key_pn = set_pop(attr_keys_pn)
-					output(((("   " + attr_key_pn) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])))
+					output(((("  " + attr_key_pn) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])))
 				output("Attributes:")
 				attr_list_pn = getAttributeList(model, cmd)
 				attr_keys_pn = dict_keys(attr_list_pn)
 				while (0 < read_nr_out(attr_keys_pn)):
 					attr_key_pn = set_pop(attr_keys_pn)
-					output((((("   " + cast_v2s(attr_key_pn)) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])) + " = ") + cast_v2s(read_attribute(model, getName(model, read_elem), attr_key_pn)))
+					output((((("  " + cast_v2s(attr_key_pn)) + " : ") + cast_v2s(attr_list_pn[attr_key_pn])) + " = ") + cast_v2s(read_attribute(model, getName(model, read_elem), attr_key_pn)))
 			else:
 				output("Unknown element; aborting")
 		elif (cmd == "verify"):

+ 24 - 62
integration/test_pn_interface.py

@@ -60,9 +60,9 @@ def read_node(name, t, defs, attrs):
             "Name: %s" % name, 
             "Type: %s" % t,
             "Defines attributes:"] + \
-            (set(["  %s : %s" for m, mm in defs]) if defs else []) + \
+            ([set(["  %s : %s" % (m, mm) for m, mm in defs])] if defs else []) + \
             ["Attributes:"] + \
-            (set(['  "%s" : "%s" = %s' for m, mm, v in attrs]) if attrs else [])
+            ([set(['  "%s" : "%s" = %s' % (m, mm, v) for m, mm, v in attrs])] if attrs else [])
 
 def read_edge(name, t, src, dst, defs, attrs):
     return ["Element to read?",
@@ -71,9 +71,9 @@ def read_edge(name, t, src, dst, defs, attrs):
             "Source: %s" % src,
             "Destination: %s" % dst,
             "Defines attributes:"] + \
-            (set(["  %s : %s" for m, mm in defs]) if defs else []) + \
+            ([set(["  %s : %s" % (m, mm) for m, mm in defs])] if defs else []) + \
             ["Attributes:"] + \
-            (set(['  "%s" : "%s" = %s' for m, mm, v in attrs]) if attrs else [])
+            ([set(['  "%s" : "%s" = %s' % (m, mm, v) for m, mm, v in attrs])] if attrs else [])
 
 def enabled(enableds):
     return ["Enabled transitions:"] + \
@@ -86,6 +86,10 @@ def fire(fired):
 
 delete =            ["Model to delete?", "Deleted!"]
 rename =            ["Old name?", "New name?", "Rename complete!"]
+attr_add =          ["Which model do you want to assign an attribute to?",
+                     "Which attribute do you wish to assign?",
+                     "Value of attribute?",
+                     "Added attribute!"]
 
 help_root =         ["Currently no model is loaded, so your operations are limited to:",
                      "  new    -- Create a new model and save it for future use"
@@ -175,64 +179,22 @@ class TestPetrinetInterface(unittest.TestCase):
     def pn_interface_instantiate_place(self, mode):
         self.assertTrue(run_file(all_files,
             ["new", "PetriNets", "abc",
-            "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5],
-            init + new_full + instantiate + instantiate_name +
-            instantiate_tokens + instantiate_ok + prompt_model, mode))
-
-    def test_po_pn_interface_instantiate_place_list(self):
-        self.pn_interface_instantiate_place_list("PO")
-
-    def test_co_pn_interface_instantiate_place_list(self):
-        self.pn_interface_instantiate_place_list("CO")
-
-    def pn_interface_instantiate_place_list(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc",
-            "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
-            "list"],
-            init + new_full + instantiate + instantiate_name +
-            instantiate_tokens + instantiate_ok + prompt_model +
-            list_model + list_p1, mode))
-
-    def test_po_pn_interface_instantiate_place_read(self):
-        self.pn_interface_instantiate_place_read("PO")
-
-    def test_co_pn_interface_instantiate_place_read(self):
-        self.pn_interface_instantiate_place_read("CO")
-
-    def pn_interface_instantiate_place_read(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc",
-            "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
-            "read", "p1"],
-            init + new_full + instantiate + instantiate_name +
-            instantiate_tokens + instantiate_ok + prompt_model + read +
-            read_p1, mode))
-
-    def test_po_pn_interface_instantiate_transition(self):
-        self.pn_interface_instantiate_transition("PO")
-
-    def test_co_pn_interface_instantiate_transition(self):
-        self.pn_interface_instantiate_transition("CO")
-
-    def pn_interface_instantiate_transition(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc",
-            "instantiate", "Transition", "t1"],
-            init + new_full + instantiate + instantiate_name +
-            instantiate_ok + prompt_model, mode))
-
-    def test_po_pn_interface_instantiate_transition_read(self):
-        self.pn_interface_instantiate_transition_read("PO")
-
-    def test_co_pn_interface_instantiate_transition_read(self):
-        self.pn_interface_instantiate_transition_read("CO")
-
-    def pn_interface_instantiate_transition_read(self, mode):
-        self.assertTrue(run_file(all_files,
-            ["new", "PetriNets", "abc", "instantiate", "Transition", "t1", "read", "t1"],
-            init + new_full + instantiate + instantiate_name +
-            instantiate_ok + prompt_model + read + read_t1, mode))
+            "instantiate", "Place", "p1",
+            "attr_add", "p1", "tokens", 5,
+            "list",
+            "read", "p1",
+            "instantiate", "Transition", "t1",
+            "list",
+            "read", "t1"],
+            init + new + loaded + \
+                instantiate_node + prompt + \
+                attr_add + prompt + \
+                list_model([("p1", "Place")]) + prompt + \
+                read_node("p1", "Place", [], [("tokens", "Integer", 5)]) + prompt + \
+                instantiate_node + prompt + \
+                list_model([("p1", "Place"), ("t1", "Transition")]) + prompt + \
+                read_node("t1", "Transition", [], []) + prompt,
+            mode))
 
     def test_po_pn_interface_instantiate_arcs(self):
         self.pn_interface_instantiate_arcs("PO")