123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427 |
- import unittest
- from utils import run_file
- do_instantiate_simple = [
- "new", "PetriNets", "abc",
- "instantiate", "Transition", "t1",
- "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
- "instantiate", "Place", "p2", "attr_add", "p2", "tokens", 0,
- "instantiate", "P2T", "p2t", "p1", "t1", "attr_add", "p2t", "weight", 2,
- "instantiate", "T2P", "t2p", "t1", "p2", "attr_add", "t2p", "weight", 1]
- 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",
- "object_operations.alc",
- "conformance_scd.alc",
- "library.alc",
- "constructors.alc",
- "metamodels.alc",
- "--fast",
- ]
- 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?"]
- prompt = ["Please give your command."]
- loaded = ["Model loaded, ready for commands!",
- "Use 'help' command for a list of possible commands"] + prompt
- load = ["Model to load?"]
- instantiate = ["Type to instantiate?"]
- instantiate_name = ["Name of new element?"]
- instantiate_ok = ["Instantiation successful!"]
- instantiate_source= ["Source name?"]
- instantiate_destination = ["Destination name?"]
- 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",
- " delete -- Delete a previously made model",
- " list -- Show a list of all stored models",
- " help -- Show a list of possible commands"]
- 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"]
- 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_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")
- def test_co_pn_interface_new_reload(self):
- self.pn_interface_new_reload("CO")
- def pn_interface_new_reload(self, mode):
- self.assertTrue(run_file(all_files,
- ["new", "PetriNets", "abc", "exit", "load", "abc"], init + new_full +
- prompt_menu + load_full, mode))
- def test_po_pn_interface_new_list_empty(self):
- self.pn_interface_new_list_empty("PO")
- def test_co_pn_interface_new_list_empty(self):
- self.pn_interface_new_list_empty("CO")
- def pn_interface_new_list_empty(self, mode):
- self.assertTrue(run_file(all_files,
- ["new", "PetriNets", "abc", "list"], init + new_full + list_model +
- prompt_model, mode))
- def test_po_pn_interface_instantiate_place(self):
- self.pn_interface_instantiate_place("PO")
- def test_co_pn_interface_instantiate_place(self):
- self.pn_interface_instantiate_place("CO")
- 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))
- def test_po_pn_interface_instantiate_arcs(self):
- self.pn_interface_instantiate_arcs("PO")
- def test_co_pn_interface_instantiate_arcs(self):
- self.pn_interface_instantiate_arcs("CO")
- def pn_interface_instantiate_arcs(self, mode):
- self.assertTrue(run_file(all_files,
- do_instantiate_simple,
- did_instantiate_simple,
- mode))
- def test_po_pn_interface_instantiate_arcs_read(self):
- self.pn_interface_instantiate_arcs_read("PO")
- def test_co_pn_interface_instantiate_arcs_read(self):
- self.pn_interface_instantiate_arcs_read("CO")
- def pn_interface_instantiate_arcs_read(self, mode):
- self.assertTrue(run_file(all_files,
- do_instantiate_simple + [
- "read", "p1",
- "read", "p2",
- "read", "t1",
- "read", "p2t",
- "read", "t2p"],
- did_instantiate_simple +
- read_p1_full + read_p2_full + read_t1_full + read_p2t_full +
- read_t2p_full, mode))
- def test_po_pn_interface_instantiate_arcs_list(self):
- self.pn_interface_instantiate_arcs_list("PO")
- def test_co_pn_interface_instantiate_arcs_list(self):
- self.pn_interface_instantiate_arcs_list("CO")
- def pn_interface_instantiate_arcs_list(self, mode):
- self.assertTrue(run_file(all_files,
- do_instantiate_simple + ["list"],
- did_instantiate_simple +
- list_model + list_t1 + list_p1 + list_p2 + list_p2t + list_t2p +
- prompt_model, mode))
- def test_po_pn_interface_enabled_empty(self):
- self.pn_interface_enabled_empty("PO")
- def test_co_pn_interface_enabled_empty(self):
- self.pn_interface_enabled_empty("CO")
- def pn_interface_enabled_empty(self, mode):
- self.assertTrue(run_file(all_files,
- ["new", "PetriNets", "abc", "enabled"],
- init + new_full + enabled + prompt_model, mode))
- def test_po_pn_interface_enabled(self):
- self.pn_interface_enabled("PO")
- def test_co_pn_interface_enabled(self):
- self.pn_interface_enabled("CO")
- def pn_interface_enabled(self, mode):
- self.assertTrue(run_file(all_files,
- do_instantiate_simple + ["enabled"],
- did_instantiate_simple + enabled +
- enabled_t1 + prompt_model, mode))
- def test_po_pn_interface_fire(self):
- self.pn_interface_fire("PO")
- def test_co_pn_interface_fire(self):
- self.pn_interface_fire("CO")
- def pn_interface_fire(self, mode):
- self.assertTrue(run_file(all_files,
- do_instantiate_simple + ["fire", "t1"],
- did_instantiate_simple + ["fire", "t1"],
- init + new_full + instantiate_transition + instantiate_place +
- instantiate_place + instantiate_arc + instantiate_arc + fire +
- fire_t1 + fire_finish + prompt_model, mode))
- def test_po_pn_interface_fire_place(self):
- self.pn_interface_fire_place("PO")
- def test_co_pn_interface_fire_place(self):
- self.pn_interface_fire_place("CO")
- def pn_interface_fire_place(self, mode):
- self.assertTrue(run_file(all_files,
- ["new", "PetriNets", "abc",
- "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
- "fire", "p1"],
- init + new_full + instantiate_place + fire + fire_no_enable +
- prompt_model, mode))
- def test_po_pn_interface_fire_unknown(self):
- self.pn_interface_fire_unknown("PO")
- def test_co_pn_interface_fire_unknown(self):
- self.pn_interface_fire_unknown("CO")
- def pn_interface_fire_unknown(self, mode):
- self.assertTrue(run_file(all_files,
- ["new", "PetriNets", "abc", "fire", "t1"],
- init + new_full + fire + fire_unknown + prompt_model, mode))
- def test_po_pn_interface_verify_OK(self):
- self.pn_interface_verify_OK("PO")
- def test_co_pn_interface_verify_OK(self):
- self.pn_interface_verify_OK("CO")
- def pn_interface_verify_OK(self, mode):
- self.assertTrue(run_file(all_files,
- do_instantiate_simple + ["verify"],
- did_instantiate_simple + verify_full, mode))
- def test_po_pn_interface_verify_fail_tokens(self):
- self.pn_interface_verify_fail_tokens("PO")
- def test_co_pn_interface_verify_fail_tokens(self):
- self.pn_interface_verify_fail_tokens("CO")
- def pn_interface_verify_fail_tokens(self, mode):
- self.assertTrue(run_file(all_files,
- do_instantiate_simple + ["modify", "p1", "tokens", -5, "verify"],
- did_instantiate_simple + verify_fail_tokens, mode))
- def test_po_pn_interface_verify_fail_weight(self):
- self.pn_interface_verify_fail_weight("PO")
- def test_co_pn_interface_verify_fail_weight(self):
- self.pn_interface_verify_fail_weight("CO")
- def pn_interface_verify_fail_weight(self, mode):
- self.assertTrue(run_file(all_files,
- do_instantiate_simple + ["modify", "p2t", "weight", -2, "verify"],
- did_instantiate_simple + verify_fail_weight, mode))
- def test_po_pn_interface_verify_fail_structure(self):
- self.pn_interface_verify_fail_structure("PO")
- def test_co_pn_interface_verify_fail_structure(self):
- self.pn_interface_verify_fail_structure("CO")
- def pn_interface_verify_fail_structure(self, mode):
- self.assertTrue(run_file(all_files,
- ["new", "PetriNets", "abc",
- "instantiate", "Transition", "t1",
- "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
- "instantiate", "P2T", "p2t", "t1", "p1", "attr_add", "p2t", "weight", 2, "verify"],
- init + new_full + instantiate_transition +
- instantiate_place + instantiate_arc + verify_fail_structure,
- mode))
- def test_po_pn_interface_types(self):
- self.pn_interface_types("PO")
- def test_co_pn_interface_types(self):
- self.pn_interface_types("CO")
- def pn_interface_types(self, mode):
- self.assertTrue(run_file(all_files,
- ["new", "PetriNets", "abc", "types"], init + new_full + types_full, mode))
- def test_po_pn_interface_modify_place(self):
- self.pn_interface_modify_place("PO")
- def test_co_pn_interface_modify_place(self):
- self.pn_interface_modify_place("CO")
- def pn_interface_modify_place(self, mode):
- self.assertTrue(run_file(all_files,
- ["new", "PetriNets", "abc",
- "instantiate", "Place", "p1", "attr_add", "p1", "tokens", 5,
- "read", "p1",
- "modify", "p1", "tokens", 1, "read", "p1"],
- init + new_full + instantiate + instantiate_name +
- instantiate_tokens + instantiate_ok + prompt_model + read +
- read_p1 + prompt_menu + modify_place_full + read + read_p1_1 +
- prompt_menu, mode))
|