Example #1
0
def graph_menu_loop():
    # set data_explorer to true for the while loop
    data_explorer = True

    while data_explorer is True:

        # centre screen
        print_centred("\n")

        # function to print out menu options
        display_options()

        # error handling/try and except block for menu selection
        while True:
            try:
                selection = input("")

                # method to validate menu selection
                if validate_menu_selection(selection) is False:
                    print_centred("This is not a valid number. "
                                  "Please enter a valid number.")
                else:
                    break
            except ValueError:
                print_centred(
                    "This is not a valid number. Please enter a valid number.")
            except TypeError:
                print_centred(
                    "This is not a valid number. Please enter a valid number.")

        # if selection 1 is chosed, call selection_one function.
        if selection == "1":
            if selection_one(data_explorer) is False:
                data_explorer = False
                break
            else:
                continue

        # if selection 2 is chosed, call selection_two function.
        elif selection == "2":
            if selection_two(data_explorer) is False:
                data_explorer = False
                break
            else:
                continue

        # if selection 3 is chosed, call selection_three function.
        elif selection == "3":
            if selection_three(data_explorer) is False:
                data_explorer = False
                break
            else:
                continue

        # if selection 4 is chosed, call selection_four function.
        elif selection == "4":
            if selection_four(data_explorer) is False:
                data_explorer = False
                break
            else:
                continue
 def test_validate_incorrect_menu_selection_empty(self):
     result = validate_menu_selection("")
     self.assertEqual(result, False, msg="Result did not return False")
 def test_validate_correct_menu_selection_four(self):
     result = validate_menu_selection("4")
     self.assertEqual(result, "4", msg="Result did not return 4")
 def test_validate_correct_menu_selection_three(self):
     result = validate_menu_selection("3")
     self.assertEqual(result, "3", msg="Result did not return 3")
 def test_validate_correct_menu_selection_two(self):
     result = validate_menu_selection("2")
     self.assertEqual(result, "2", msg="Result did not return 2")
 def test_validate_correct_menu_selection_one(self):
     result = validate_menu_selection("1")
     self.assertEqual(result, "1", msg="Result did not return 1")