def test_integration(self):
        """Test the integrated application"""
        with patch('builtins.input', side_effect=['1']):
            self.assertEqual(main.main_menu(), main.add_new_item)

        expected_inventory = {
            '64': {
                'item_code': '64',
                'description': 'Nintendo 64',
                'market_price': 24,
                'rental_price': '5.64'
            },
            'WD': {
                'item_code': 'WD',
                'description': 'Combo washer/dryer',
                'market_price': 24,
                'rental_price': '13.75',
                'brand': 'Baytag',
                'voltage': '240V'
            },
            'DINTAB': {
                'item_code': 'DINTAB',
                'description': 'Dining table',
                'market_price': 24,
                'rental_price': '7.99',
                'material': 'Stainless steel',
                'size': 'L'
            }
        }
        with patch('builtins.input',
                   side_effect=['64', 'Nintendo 64', '5.64', 'n', 'n']):
            main.add_new_item()
        with patch('builtins.input',
                   side_effect=[
                       'WD', 'Combo washer/dryer', '13.75', 'n', 'y', 'Baytag',
                       '240V'
                   ]):
            main.add_new_item()
        with patch('builtins.input',
                   side_effect=[
                       'DINTAB', 'Dining table', '7.99', 'y',
                       'Stainless steel', 'L'
                   ]):
            main.add_new_item()
        self.assertEqual(expected_inventory, main.INVENTORY_DATA)

        with patch('builtins.input', side_effect=['2']):
            self.assertEqual(main.main_menu(), main.item_info)

        expected_item_info = """Enter item code: 64
item_code:64
description:Nintendo 64
market_price:24
rental_price:5.64"""

        with patch('builtins.input', side_effect=['64']):
            self.assertEqual(main.item_info(), print(expected_item_info))

        with patch('builtins.input', side_effect=['q']):
            self.assertEqual(main.main_menu(), main.exit_program)
예제 #2
0
 def test_main_menu(self):
     with patch('builtins.input', side_effect=['1']):
         self.assertEqual(main.main_menu(), main.add_new_item)
     with patch('builtins.input', side_effect=['2']):
         self.assertEqual(main.main_menu(), main.item_info)
     with patch('builtins.input', side_effect=['q']):
         self.assertEqual(main.main_menu(), main.exit_program)
예제 #3
0
    def test_main_menu(self):
        """ 
        Tests main.main_menu in a couple different ways.

        First by passing in a menu option as an argument.
        And second by using simulated user input to navigate the menu.

        Both tests verify that the proper function is called based on the menu
        input provided.
        """

        self.assertEqual(main.main_menu('1'), main.add_new_item)
        self.assertEqual(main.main_menu('2'), main.item_info)
        self.assertEqual(main.main_menu('q'), main.exit_program)

        inputs = (user_in for user_in in ['What?', '1'])

        def mock_input(prompt):
            return next(inputs)

        with patch('builtins.input', mock_input):
            main_menu_output = main.main_menu()

        self.assertEqual(main.add_new_item, main_menu_output)

        inputs2 = (user_in2 for user_in2 in ['Yes', 'NO', '2'])

        def mock_input2(prompt):
            return next(inputs2)

        with patch('builtins.input', mock_input2):
            main_menu_output2 = main.main_menu()

        self.assertEqual(main.item_info, main_menu_output2)
예제 #4
0
    def run(self):
        running = True
        while running:
            temp = deepcopy(self.snake.blocks)
            for i in range(1, len(self.snake.blocks)):
                self.snake.blocks[i].x = temp[i - 1].x
                self.snake.blocks[i].y = temp[i - 1].y

            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    exit()
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_UP:
                        self.snake.vel += 10
                    if event.key == pygame.K_DOWN:
                        if self.snake.vel >= 11:
                            self.snake.vel -= 10

            state = self.get_state(self.board_width, self.board_height)
            next_move = 0
            if True in state[1]:
                next_move = state[1].index(True)
            if state[0][next_move]:
                if True in state[1][next_move:]:
                    next_move = state[1][next_move:].index(True)
                    if state[0][next_move]:
                        if False in state[0]:
                            next_move = state[0].index(False)
                        else:
                            main.main_menu()
            self.snake.dx = self.snake.dy = 0
            if next_move == 0:
                self.snake.dx = -self.snake.width
            elif next_move == 1:
                self.snake.dx = self.snake.width
            elif next_move == 2:
                self.snake.dy = -self.snake.height
            else:
                self.snake.dy = self.snake.height

            self.snake.head.x += self.snake.dx
            self.snake.head.y += self.snake.dy

            self.screen.fill((255, 255, 255))
            pygame.draw.rect(self.screen, self.food.color,
                             [self.food.x, self.food.y, self.snake.width, self.snake.height])
            self.snake.draw_snake(self.screen)
            main.display_msg(f'Score: {len(self.snake.blocks) - 1}', (0, 0, 0), (0, 0))
            pygame.display.flip()
            self.clock.tick(self.snake.vel)

            running = not self.snake.is_dead(self.board_width, self.board_height)

            # Check if eating food
            if self.snake.head.x == self.food.x and self.snake.head.y == self.food.y:
                self.food.get_new_pos(self.board_width, self.board_height, self.snake)
                self.snake.add_block()

        main.main_menu()
예제 #5
0
def hamiltonian_cycle(screen, clock, snake, food, width, height):
    running = True
    while running:
        temp = deepcopy(snake.blocks)
        for i in range(1, len(snake.blocks)):
            snake.blocks[i].x = temp[i - 1].x
            snake.blocks[i].y = temp[i - 1].y

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                exit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    snake.vel += 10
                if event.key == pygame.K_DOWN:
                    if snake.vel >= 11:
                        snake.vel -= 10

        if snake.head.x == snake.width and snake.head.y == 0:
            snake.dx = -snake.width
            snake.dy = 0
        elif snake.head.x == 0 and snake.head.y < height - snake.height:
            snake.dx = 0
            snake.dy = snake.height
        elif snake.head.y % 2 == 0 and snake.head.x > snake.width:
            snake.dx = -snake.width
            snake.dy = 0
        elif snake.head.y % 2 == 0 and snake.head.x <= snake.width and snake.head.y > 0:
            snake.dx = 0
            snake.dy = -snake.height
        elif snake.head.y % 2 == 1 and snake.head.x < width - snake.width:
            snake.dx = snake.width
            snake.dy = 0
        elif snake.head.y % 2 == 1 and snake.head.x >= width - snake.width:
            snake.dx = 0
            snake.dy = -snake.width

        else:
            snake.dy = 0
            snake.dx = 0
        snake.head.x += snake.dx
        snake.head.y += snake.dy

        screen.fill((255, 255, 255))
        pygame.draw.rect(screen, food.color,
                         [food.x, food.y, snake.width, snake.height])
        snake.draw_snake(screen)
        main.display_msg(f'Score: {len(snake.blocks) - 1}', (0, 0, 0), (0, 0))
        pygame.display.flip()
        clock.tick(snake.vel)

        running = not snake.is_dead(width, height)

        # Check if eating food
        if snake.head.x == food.x and snake.head.y == food.y:
            food.get_new_pos(width, height, snake)
            snake.add_block()

    main.main_menu()
예제 #6
0
def main_menu_help():
    """
    Displays a general introduction and help message to the user.
    First called at initialization, then called again when asked for by user.
    """

    print("MAIN MENU HELP MESSAGE!")
    pause_clear()
    main.main_menu(
    )  #  This help function is only callable from the main menu.
예제 #7
0
def open_new_dataset():
    """
    Opens data into the global scope DATA variable.
    :return:
    """
    global DATA

    dataset_names = choose_datasets()
    DATA = build_dataset(dataset_names)

    main.main_menu()
예제 #8
0
    def test_main_menu_prompts(self, print_mock, input_mock):

        # Assert that input is accepted
        input_mock.return_value = "1"
        self.assertIs(main.add_new_item, main.main_menu())

        input_mock.return_value = "2"
        self.assertIs(main.item_info, main.main_menu("not valid"))

        input_mock.return_value = "q"
        self.assertIs(main.exit_program, main.main_menu())
예제 #9
0
def by_offense():
    """
    Menu to calculate certain information oriented by offense type.
    """

    calc_functions = {1: data_min, 2: data_max, 3: data_average}

    calc_choice = calc_options_menu()

    if calc_choice == 4:
        main.main_menu()
    else:
        calc_functions[calc_choice](config.DATA, 'MajorOffenseType')
예제 #10
0
def by_neighborhood():
    """
    Menu to calculate certain information oriented by neighborhood.
    """

    calc_functions = {1: data_min, 2: data_max, 3: data_average}

    calc_choice = calc_options_menu()

    if calc_choice == 4:
        main.main_menu()
    else:
        calc_functions[calc_choice](config.DATA, 'Neighborhood')
예제 #11
0
def by_date():
    """
    Menu to calculate certain information oriented by date.
    """

    calc_functions = {1: data_min, 2: data_max, 3: data_average}

    calc_choice = calc_options_menu()

    if calc_choice == 4:
        main.main_menu()
    else:
        calc_functions[calc_choice](config.DATA, 'ReportDate')
예제 #12
0
 def test_add_and_get_new_item_appliance(self, user_input, item):
     """
     Add appliance and get it back
     """
     text_trap = StringIO()
     with patch('main.input', side_effect=user_input):
         with redirect_stdout(text_trap):
             for i in range(2):
                 main_menu()(self.inventory)
     result = text_trap.getvalue()
     self.assertIn("New inventory item added", result)
     self.assertIn(item, result)
     self.assertNotIn("Item not found in inventory", result)
예제 #13
0
 def test_not_added_not_found(self):
     text_trap = StringIO()
     item_test = 'red chair'
     user_input = [
         "1", "abc", "funky chair", "500", "Y", "leather", "S", "", '2',
         item_test
     ]
     with patch('main.input', side_effect=user_input):
         with redirect_stdout(text_trap):
             for i in range(2):
                 main_menu()(self.inventory)
     result = text_trap.getvalue()
     self.assertIn("New inventory item added", result)
     self.assertNotIn(item_test, result)
     self.assertIn("Item not found in inventory", result)
예제 #14
0
def pantry_menu():
    print("Welcome to the pantry")

    try:
        with open("pantry.json", "r") as myPantry:
            pantry = Pantry.Pantry(json.load(myPantry))
        print("-- Found an existing file!\n")
    except:
        pantry = Pantry.Pantry()
        print("-- No existing file found. Here's a fresh pantry!\n")

    while True:
        print("[0] Print current pantry")
        print("[1] Add item to pantry")
        print("[2] Save pantry")
        print("[3] Update pantry item")
        print("[4] Search pantry for item")
        print("[q] Exit")

        pantrynav = input("\nChoose an option from above: ")
        print("===========================================")

        if pantrynav == '0':
            pantry.toString()
        elif pantrynav == '1':
            iname = input("Name: ")
            ipdate = input("Purchase date: ")
            iedate = input("Expiration date: ")
            iquantity = input("Quantity: ")
            print(pantry.add_item(iname, ipdate, iedate, iquantity))
        elif pantrynav == '2':
            print(pantry.save())
        elif pantrynav == '3':
            new_attr = []
            print("Enter the name of item to update and information to update")
            new_attr.append(input("Name: "))
            new_attr.append(input("Attribute: "))
            new_attr.append(input("Value: "))
            print(pantry.update(new_attr))
        elif pantrynav == '4':
            print(pantry.search(input("Name: ")))
        elif pantrynav == 'q':
            pantry.save()
            main.main_menu()
        else:
            print("Invalid choice")

        print("===========================================")
예제 #15
0
def by_time():
    """
    Menu to calculate certain information oriented by time of day.
    """

    # for dataset_key in data.keys():
    #     data = sorted(data[dataset_key], key=sort_by_offense_helper)

    calc_functions = {1: data_min, 2: data_max, 3: data_average}

    calc_choice = calc_options_menu()

    if calc_choice == 4:
        main.main_menu()
    else:
        calc_functions[calc_choice](config.DATA, 'ReportTime')
예제 #16
0
 def test_main_menu(self):
     user_input = ["1"]
     text_trap = io.StringIO()
     sys.stdout = text_trap
     with patch('builtins.input', side_effect=user_input):
         function = main_menu()
     self.assertEqual(function.__name__, "add_new_item")
     sys.stdout = sys.__stdout__
예제 #17
0
 def test_add_and_get_new_item_furniture(self):
     """
     Add furniture and get it back
     """
     text_trap = StringIO()
     item_added = "funky chair"
     user_input = [
         "1", "abc", item_added, "500", "Y", "leather", "S", "", '2', 'abc'
     ]
     with patch('main.input', side_effect=user_input):
         with redirect_stdout(text_trap):
             for _ in range(2):
                 main_menu()(self.inventory)
     result = text_trap.getvalue()
     self.assertIn("New inventory item added", result)
     self.assertIn(item_added, result)
     self.assertNotIn("Item not found in inventory", result)
예제 #18
0
def dead_message(hero):
    while True:
        main.clear_screen()

        print(f"\n{hero.name} har dött.")
        save_collected_treasure(hero)

        print("\n[1] - Main menu\n" "[2] - Avsluta spelet")
        choice = input("\nSkriv in ditt val: ")

        if choice == "1":
            main.main_menu()
        elif choice == "2":
            exit()
        else:
            print("\n-- Felaktig input, ange en siffra från menyn. --")
            input('-- Tyck på enter för att fortsätta --')
예제 #19
0
def Auto_sale_main():
    print("----------------------------------")
    print("welcome to Auto sale ")
    Auto_transacation()
    print("transaction finished")
    while True:
        user_input = input("Do you want to make another transaction? ").lower()
        print("1. make a new transaction")
        print("0. Back to the Main Menu")
        if user_input == 1 or user_input == 0:
            if user_input2 == 1:
                New_Vehicle_Registraion()
            else:
                print("exit to main menu")
                main.main_menu()
        else:
            print("invalid input, try again")
예제 #20
0
def NVR_main():
    print("----------------------------------")
    print("Registration for New vehicle")
    New_Vehicle_Registraion()
    print("registration finished")
    while True:
        user_input2 = input(
            "Do you want to register another car?(1/0) ").lower()
        print("1. register a new car")
        print("0. Back to the Main Menu")
        if user_input2 == 1 or user_input2 == 0:
            if user_input2 == 1:
                New_Vehicle_Registraion()
            else:
                print("exit to main menu")
                main.main_menu()
        else:
            print("invalid input, try again")
예제 #21
0
 def test_main_menu(self):
     """Testing of menu options"""
     prompt_1 = "1"
     prompt_2 = "2"
     prompt_3 = "q"
     prompt_4 = "error"
     with patch('builtins.input', side_effect=prompt_1):
         expected_option = 'add_new_item'
         actual_option = main.main_menu()
         self.assertEqual(actual_option.__name__, expected_option)
     with patch('builtins.input', side_effect=prompt_2):
         expected_option = 'item_info'
         actual_option = main.main_menu()
         self.assertEqual(actual_option.__name__, expected_option)
     with patch('builtins.input', side_effect=prompt_3):
         expected_option = 'exit_program'
         actual_option = main.main_menu()
         self.assertEqual(actual_option.__name__, expected_option)
def menu_exercise_1():
    while True:
        option = buttonbox(
            "A. Insert a sequence manually\n\nB. Generate a sequence with the letters: A, C, T, G\n\n"
            "C. Show the total number of elements in sequence\n\n"
            "D. Show the number of occurrences of a letter/sub-sequence and a list with the indexes\n\n"
            "E. Show the frequence of a certain set of letters/sub-sequences (total and relative(%) number of each letter\n\n"
            "F. Complementary sequence ('A' and 'T' change, and also 'G' and 'C'",
            "Menu Exercise 1",
            choices=["A", "B", "C", "D", "E", "F", "Go back", "Exit"])
        if option == "A": exercise_1a()
        if option == "B": exercise_1b()
        if option == "C": exercise_1c()
        if option == "D": exercise_1d_1e_1f(indexes_sequence_1d)
        if option == "E": exercise_1d_1e_1f(freq_seq)
        if option == "F": exercise_1d_1e_1f(complementary)
        if option == "Go back": main.main_menu()
        if option == "Exit": sys.exit()
예제 #23
0
 def test_main_menu(self):
     f_inventory={}
     user_input = ["1"]
     text_trap = io.StringIO()
     sys.stdout = text_trap
     with patch('builtins.input', side_effect=user_input):
         function = main_menu()
     if function.__name__=="add_new_item":
         f_inventory=self.add_new_item_furniture(f_inventory)
     user_input = ["2"]
     with patch('builtins.input', side_effect=user_input):
         function = main_menu()
     if function.__name__=="item_info":
         f_inventory=item_info(f_inventory)
     user_input = ["q"]
     with patch('builtins.input', side_effect=user_input):
         function = main_menu()
     if function.__name__=="exit_program":
         self.assertRaises(SystemExit, exit_program, f_inventory)
    def test_integration_one(self):
        """
        Tests use of inventory_management module using simulated user input.
        """

        main.FULL_INVENTORY = {}

        inputs_list = [
            '1', 147, 'Chair', 1250, 'y', 'wood', 'l', '2', 147, 'q'
        ]
        user_inputs = (user_input for user_input in inputs_list)

        def mock_inputs(prompt):
            return next(user_inputs)

        with patch('builtins.input', mock_inputs):
            main.main_menu()()

        self.assertEqual('Chair', main.FULL_INVENTORY[147]['description'])
 def test_menu_info(self):
     '''
     Testing number 2
     '''
     while True:
         try:
             with patch('builtins.input', side_effect='2'):
                 self.assertEqual(main_menu(), main.item_info())
         except StopIteration as error_code:
             return error_code
 def test_menu_add(self):
     '''
     Here we test injecting a value of 1 in the menu
     '''
     while True:
         try:
             with patch('builtins.input', side_effect='1'):
                 self.assertEqual(main_menu(), main.add_new_item())
         except StopIteration as error_code:
             return error_code
    def test_integration_two(self):
        """
        A second thorough use test of inventory_management.
        """

        main.FULL_INVENTORY = {}

        inputs_list = [
            '1', 765, 'Toaster', 300, 'n', 'y', 'Smeg', 110, '2', 765, 'q'
        ]
        user_inputs = (user_input for user_input in inputs_list)

        def mock_inputs(prompt):
            return next(user_inputs)

        with patch('builtins.input', mock_inputs):
            main.main_menu()()

        self.assertEqual('Smeg', main.FULL_INVENTORY[765]['brand'])
예제 #28
0
def leave():
    """Quits program"""

    print("Are you sure you want to quit?")
    leave_yn = input("Y/N: ")

    if 'y' in leave_yn.lower():
        print("Thanks for stopping by!")
        print("Come back soon!")
        pause_clear()
        exit()

    elif 'n' in leave_yn.lower():
        pause_clear()
        main.main_menu()

    else:
        print("I'm not sure what you mean!")
        pause_clear()
        leave()
예제 #29
0
def check_room(coordinates, room_list, hero, game_board, start_coordinates,
               grid_size):

    for room in room_list:
        if room.coordinates == coordinates:
            if room.symbol == "[ ]":
                undiscovered_room(room, hero, room_list, game_board, grid_size)
            elif room.symbol == "[O]":
                main.print_board(game_board, hero)
                exit_to_menu = main.exit_map(
                    game_board, (start_coordinates[0], start_coordinates[1]),
                    hero)
                if exit_to_menu:
                    main.clear_screen()
                    save_collected_treasure(hero)

                    main.main_menu()
            elif room.symbol == "[.]":
                main.print_board(game_board, hero)
                print('\nInga monster i rummet.')
                print('Inga skatter hittades i rummet.')
    def test_menu_quit(self):
        '''
        Testing q
        '''
        # while True:
            # try:
                # with patch('builtins.input', side_effect='q'):
                    # self.assertEqual(main_menu(), main.exit_program())
            # except StopIteration as error_code:
                # return error_code

        with mock.patch('builtins.input', return_value='q'):
            self.assertEqual(main_menu(), main.exit_program)