예제 #1
0
파일: test_3.py 프로젝트: alexKleider/debk
 def test_menu_create_invalid_entity(self):
     with mock.patch("builtins.input",
                 side_effect=["1", self.invalid_entity, '', "0"]):
         menu.menu(D)
         self.entities = E.Entities(  # Must reassign because
                         # menu.menu sets up its own 'entities'.
                     *E.get_file_info(D), defaults=D)
         self.assertEqual(self.starting_list.sort(),
                         self.entities.lst.sort())
예제 #2
0
파일: menu.py 프로젝트: alexKleider/debk
def menu(defaults):
    """
    Provides the top level user interface.
    Prompts for what to do and then calls the appropriate
    function or method.
    Creating a new entity or choosing an existing one, if successful,
    begins the accounting process with that entity.
    """
    entities = E.Entities(*E.get_file_info(defaults),
                            defaults=defaults)
#   print("'entities' is of type '{}'.".format(type(entities)))
#   print("Initializing 'entities' with the following values:")
#   print("\t", entities.lst)
#   print("\t", entities.default)
    while True:
        listing = entities.show_entities(indent=8)
        if listing:
            listing = (
"""\n    (Currently existing entities are:\n{}          )"""
                    .format(listing))
        else: listing = "\n    (No entities currently exist.)"
#       print("listing is '{}'.".format(listing))
        option = input("""
Main Menu:
    [Working dir: {}]{}
    1. Create a new entity.
    2. Choose an existing entity.
    3. Delete an entity.
    9. Change arguments.
    0. Exit
Choice: """.format(defaults['home'], listing))
        print("You've chosen: '{}'.".format(option))
        if option in ('', '_', '0'):
            break
        try:
            option = int(option)
        except ValueError:
            print(
                "Invalid main menu choice: {} (must be an integer.)"
                        .format(option))
            continue
        if option == 1:
            entity = create_new(entities)
        elif option == 2:
            entity = choose_existing(defaults, entities)
        elif option == 3:
            delete_option(defaults, entities)
            entity = ''
        elif option == 9:
            change_args_option(defaults)
        else:
            print("BAD CHOICE '{}'- try again....".format(option))
            entity = None
        if entity:
            defaults["entity"] = entity
            work_with(defaults)
예제 #3
0
파일: test_3.py 프로젝트: alexKleider/debk
 def setUp(self):
     """
     Effectively tests get_file_info and create_entity.
     """
     self.new_entity = 'newEntity'
     self.invalid_entity = 'invalid_entity'
     self.ent_w_default = "entwdefault"
     self.ent_wo_default = "entwodefault"
     self.starting_list = ['ent1', 'ent2', 'ent3']
     for entity in self.starting_list:
         E.create_entity(entity, defaults=D)
     self.entities = E.Entities(*E.get_file_info(D), defaults=D)
예제 #4
0
파일: test_3.py 프로젝트: alexKleider/debk
 def test_menu_create_newEntity(self):
     with mock.patch("builtins.input",
                     side_effect=["1", self.new_entity, '',
                     '', '']):
         menu.menu(D)
         self.entities = E.Entities(  # Must reassign because
                         # menu.menu sets up its own 'entities'.
                     *E.get_file_info(D), defaults=D)
         expected_list = self.starting_list[:]
         expected_list.append(self.new_entity)
         self.assertTrue((sorted(self.entities.lst)
                                     == sorted(expected_list)) and
                     (self.entities.default == self.new_entity))