Example #1
0
    def __init__(self, app_name=None, menus=None, example=False):
        if app_name is None:
            app_name = 'ACME'
        # Create initial options for main menu
        options = []
        # Options with app_name added to it
        new_options = []
        # Add example menu
        if example is True:
            options += examples
        else:
            # The main menu is the same as any other menu.
            # It displays other menus as options. To the user
            # these options are presented as menus to be displayed
            if menus is not None:
                for m in menus:
                    check_mro(m)
                options += menus

        for o in options:
            # Adding the app name to each menu
            o.app_name = app_name
            o.options.append(('Main Menu', getattr(o, 'done')))
            # Quick hack to add users class name as menu option
            # only for main menu
            new_o = (o.menu_name, o)
            new_options.append(new_o)
        check_options_else_raise(new_options)
        new_options.append(('Quit', self.quit))
        self.main = MainMenu(new_options)
        self.main.app_name = app_name
Example #2
0
 def test_fail_greater_10(self):
     with pytest.raises(MenusError):
         data = [('Menu', 'First'), ('Menu', 'First'), ('Menu', 'First'),
                 ('Menu', 'First'), ('Menu', 'First'), ('Menu', 'First'),
                 ('Menu', 'First'), ('Menu', 'First'), ('Menu', 'First'),
                 ('Menu', 'First'),]
         check_options_else_raise(data)
Example #3
0
    def __init__(self, app_name=None, menus=None, example=False):
        # Name used in every menu header
        if app_name is None:
            app_name = 'ACME'

        # Create initial options for main menu
        options = []

        # Adding submenus
        if example is True:
            options += examples
        else:
            if menus is not None:
                for m in menus:
                    check_mro(m)
                options += menus

        # Options with app_name added to it
        new_options = []
        for o in options:
            # Adding the app name to the menu
            o.app_name = app_name
            o.options.append(('Main Menu', getattr(o, 'done')))

            # Quick hack to add users class name as menu option
            # only for main menu
            new_o = (o.menu_name, o)
            new_options.append(new_o)

        new_options.append(('Quit', self.quit))

        # Sanatisation checks on passed options
        check_options_else_raise(new_options)

        # Initilazie main menu with submenus
        self.main = MainMenu(new_options)

        # Adding the app name to the main menu
        self.main.app_name = app_name
Example #4
0
    def __init__(self, app_name=None, menus=None, example=False):
        # Name used in every menu header
        if app_name is None:
            app_name = 'ACME'

        # Create initial options for main menu
        options = []

        # Adding submenus
        if example is True:
            options += examples
        else:
            if menus is not None:
                for m in menus:
                    check_mro(m)
                options += menus

        # Options with app_name added to it
        new_options = []
        for o in options:
            # Adding the app name to the menu
            o.app_name = app_name
            o.options.append(('Main Menu', getattr(o, 'done')))

            # Quick hack to add users class name as menu option
            # only for main menu
            new_o = (o.menu_name, o)
            new_options.append(new_o)

        new_options.append(('Quit', self.quit))

        # Sanatisation checks on passed options
        check_options_else_raise(new_options)

        # Initilazie main menu with submenus
        self.main = MainMenu(new_options)

        # Adding the app name to the main menu
        self.main.app_name = app_name
Example #5
0
 def test_fail_string(self):
     with pytest.raises(MenusError):
         check_options_else_raise([(112, 'First')])
Example #6
0
 def test_fail_no_tuple(self):
     with pytest.raises(MenusError):
         check_options_else_raise(['Menu', 'First'])
Example #7
0
 def test_incorrect_tuple_item_count(self):
     with pytest.raises(MenusError):
         check_options_else_raise([('MainMenu', 'First', 'Extra')])
Example #8
0
 def test_wrong_arg(self):
     with pytest.raises(MenusError):
         check_options_else_raise('Bad to the bone')
Example #9
0
 def test_empty(self):
     with pytest.raises(MenusError):
         check_options_else_raise([])
Example #10
0
 def test_default(self):
     assert check_options_else_raise([('Menu', 'First')]) is True