Exemplo n.º 1
0
def test_menu_selection_call_on_selected(mocked_print, mocked_input):
    menu = Menu.Builder(MenuDescription('a description')) \
        .with_entry(Entry.create('1', 'first entry', on_selected=lambda: print('first entry selected'))) \
        .with_entry(Entry.create('0', 'exit', is_exit=True)) \
        .build()
    menu.run()
    mocked_print.assert_any_call('first entry selected')
    mocked_input.assert_called()
Exemplo n.º 2
0
 def __init_shopping_list_menu(self) -> Menu:
     return Menu.Builder(MenuDescription('SHOPPING LIST'), auto_select=lambda: self.__print_items()) \
         .with_entry(Entry.create('1', 'Add Smartphone', on_selected=lambda: self.__add_smartphone())) \
         .with_entry(Entry.create('2', 'Add Computer', on_selected=lambda: self.__add_computer())) \
         .with_entry(Entry.create('3', 'Remove Item', on_selected=lambda: self.__remove_item())) \
         .with_entry(Entry.create('4', 'Change quantity', on_selected=lambda: self.__change_quantity())) \
         .with_entry(Entry.create('5', 'Sort by Manufacturer', on_selected=lambda: self.__sort_by_manufacturer())) \
         .with_entry(Entry.create('6', 'Sort by Price', on_selected=lambda: self.__sort_by_price())) \
         .with_entry(Entry.create('0', 'Exit', on_selected=lambda: print('Bye!'), is_exit=True)) \
         .build()
Exemplo n.º 3
0
 def init_first_menu(self) -> Menu:
     return Menu.Builder(MenuDescription('SIGN IN'), auto_select=lambda: print('Welcome!')) \
         .with_entry(Entry.create('1', 'Login', is_logged=lambda: self.__login())) \
         .with_entry(Entry.create('2', 'Register', on_selected=lambda: self.__register())) \
         .with_entry(Entry.create('0', 'Exit', on_selected=lambda: print('Bye!'), is_exit=True)) \
         .build()
Exemplo n.º 4
0
def test_menu_does_not_contain_duplicates():
    menu_builder = Menu.Builder(MenuDescription('a description'))
    menu_builder.with_entry(Entry.create('1', 'first entry'))
    with pytest.raises(ValidationError):
        menu_builder.with_entry(Entry.create('1', 'first entry'))
Exemplo n.º 5
0
def test_menu_builder_cannot_call_two_times_build():
    menu_builder = Menu.Builder(MenuDescription('a description'))
    menu_builder.with_entry(Entry.create('1', 'first entry', is_exit=True))
    menu_builder.build()
    with pytest.raises(ValidationError):
        menu_builder.build()
Exemplo n.º 6
0
def test_menu_builder_cannot_create_menu_without_exit():
    menu_builder = Menu.Builder(MenuDescription('a description'))
    with pytest.raises(ValidationError):
        menu_builder.build()
    menu_builder.with_entry(Entry.create('1', 'exit', is_exit=True))
    menu_builder.build()
Exemplo n.º 7
0
def test_menu_builder_cannot_create_empty_menu():
    menu_builder = Menu.Builder(MenuDescription('a description'))
    with pytest.raises(ValidationError):
        menu_builder.build()