import unittest

from utils import run_file

all_files = [   "pn_interface.alc",
                "primitives.alc",
                "object_operations.alc",
                "conformance_scd.alc",
                "library.alc",
                "constructors.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?"]
new_fail =          ["Model exists; aborting"]
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."]
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 = 5"]
read_p1_1 =         ["Name: p1",
                     "Type: Place",
                     "Defines attributes:",
                     "Attributes:",
                     "   tokens : Integer = 1"]
read_p2 =           ["Name: p2",
                     "Type: Place",
                     "Defines attributes:",
                     "Attributes:",
                     "   tokens : Integer = 0"]
read_t1 =           ["Name: t1",
                     "Type: Transition",
                     "Defines attributes:",
                     "Attributes:"]
read_p2t =          ["Name: p2t",
                     "Type: P2T",
                     "Source: p1",
                     "Destination: t1",
                     "Defines attributes:",
                     "Attributes:",
                     "   weight : Integer = 2"]
read_t2p =          ["Name: t2p",
                     "Type: T2P",
                     "Source: t1",
                     "Destination: p2",
                     "Defines attributes:",
                     "Attributes:",
                     "   weight : Integer = 1"]
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:",
                     "  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"]
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


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, ["new", "PetriNets", "abc"],
            init + new_full, mode))

    def test_po_pn_interface_help(self):
        self.pn_interface_help("PO")

    def test_co_pn_interface_help(self):
        self.pn_interface_help("CO")

    def pn_interface_help(self, mode):
        self.assertTrue(run_file(all_files, ["help"],
            init + help_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_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_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")

    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", 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", 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", 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,
            ["new", "PetriNets", "abc", "instantiate", "Transition", "t1", "instantiate",
             "Place", "p1", 5, "instantiate", "Place", "p2", 0, "instantiate",
             "P2T", "p2t", "p1", "t1", 2, "instantiate", "T2P", "t2p", "t1",
             "p2", 1],
            init + new_full + instantiate_transition + instantiate_place +
            instantiate_place + instantiate_arc + instantiate_arc, 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,
            ["new", "PetriNets", "abc", "instantiate", "Transition", "t1", "instantiate",
             "Place", "p1", 5, "instantiate", "Place", "p2", 0, "instantiate",
             "P2T", "p2t", "p1", "t1", 2, "instantiate", "T2P", "t2p", "t1",
             "p2", 1, "read", "p1", "read", "p2", "read", "t1", "read", "p2t",
             "read", "t2p"],
            init + new_full + instantiate_transition + instantiate_place +
            instantiate_place + instantiate_arc + instantiate_arc +
            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,
            ["new", "PetriNets", "abc", "instantiate", "Transition", "t1", "instantiate",
             "Place", "p1", 5, "instantiate", "Place", "p2", 0, "instantiate",
             "P2T", "p2t", "p1", "t1", 2, "instantiate", "T2P", "t2p", "t1",
             "p2", 1, "list"],
            init + new_full + instantiate_transition + instantiate_place +
            instantiate_place + instantiate_arc + instantiate_arc +
            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,
            ["new", "PetriNets", "abc", "instantiate", "Transition", "t1", "instantiate",
             "Place", "p1", 5, "instantiate", "Place", "p2", 0, "instantiate",
             "P2T", "p2t", "p1", "t1", 2, "instantiate", "T2P", "t2p", "t1",
             "p2", 1, "enabled"],
            init + new_full + instantiate_transition + instantiate_place +
            instantiate_place + instantiate_arc + instantiate_arc + 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,
            ["new", "PetriNets", "abc", "instantiate", "Transition", "t1", "instantiate",
             "Place", "p1", 5, "instantiate", "Place", "p2", 0, "instantiate",
             "P2T", "p2t", "p1", "t1", 2, "instantiate", "T2P", "t2p", "t1",
             "p2", 1, "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", "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,
            ["new", "PetriNets", "abc", "instantiate", "Transition", "t1", "instantiate",
             "Place", "p1", 5, "instantiate", "Place", "p2", 0, "instantiate",
             "P2T", "p2t", "p1", "t1", 2, "instantiate", "T2P", "t2p", "t1",
             "p2", 1, "verify"],
            init + new_full + instantiate_transition + instantiate_place +
            instantiate_place + instantiate_arc + instantiate_arc +
            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,
            ["new", "PetriNets", "abc", "instantiate", "Transition", "t1", "instantiate",
             "Place", "p1", -5, "instantiate", "Place", "p2", 0,
             "instantiate", "P2T", "p2t", "p1", "t1", 2, "instantiate", "T2P",
             "t2p", "t1", "p2", 1, "verify"],
            init + new_full + instantiate_transition + instantiate_place +
            instantiate_place + instantiate_arc + instantiate_arc +
            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,
            ["new", "PetriNets", "abc", "instantiate", "Transition", "t1", "instantiate",
             "Place", "p1", 5, "instantiate", "Place", "p2", 0, "instantiate",
             "P2T", "p2t", "p1", "t1", -2, "instantiate", "T2P", "t2p", "t1",
             "p2", 1, "verify"], init + new_full + instantiate_transition +
            instantiate_place + instantiate_place + instantiate_arc +
            instantiate_arc + 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", 5, "instantiate", "Place", "p2", 0, "instantiate",
             "P2T", "p2t", "t1", "p1", 2, "verify"],
            init + new_full + instantiate_transition + instantiate_place +
            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", 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))

    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", 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", 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", 5, "instantiate",
             "Place", "p2", 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", 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))

