Example #1
0
    def test_take_student_selection(self, inputs, expected_return):
        """Valid input after invalid input yields expected value."""
        with patch('builtins.input') as mock_input:
            mock_input.side_effect = inputs

            assert take_student_selection(
                test_class_data_set['enumerated_dict']) == expected_return
Example #2
0
def select_student(class_name: str):
    """
    Display list of students in class and allow user to select one, returning the name of the
    selected student.

    :param class_name: str
    :return: str
    """
    student_options = create_student_list_dict(class_name)
    display_class_selection_menu(student_options)

    selected_student = take_student_selection(student_options)

    return selected_student
Example #3
0
def select_student(current_class: Class):
    """
    Display list of students in class and allow user to select one, returning
    the selected Student object.

    :param current_class: Class object
    :return: Student_object
    """
    student_options = {
        numeral: student.name
        for numeral, student in enumerate(current_class.students, start=1)
    }
    display_student_selection_menu(student_options)

    selected_student_name = take_student_selection(student_options)

    return next(student for student in current_class.students
                if student.name == selected_student_name)
Example #4
0
    def test_take_student_selection(self, mock_print):
        with patch('dionysus_app.UI_menus.class_functions_UI.input'
                   ) as mock_input:
            for test_case in self.input_sets:
                with self.subTest(i=test_case):
                    input_strings = test_case[0]
                    expected_return = test_case[1]

                    mock_input.side_effect = input_strings

                    assert take_student_selection(
                        self.test_class_student_options) == expected_return

                    # Check print calls:
                    assert mock_print.call_args_list == [
                        mock.call(self.invalid_input_response)
                        for input_string in input_strings[0:-1]
                    ]

                    # Reset the mock function after each test sequence:
                    mock_input.reset_mock(return_value=True, side_effect=True)
                    mock_print.reset_mock(return_value=True, side_effect=True)