Пример #1
0
def take_student_scores(current_class: Class):
    """
    UI function presenting student names from supplied class one at a
    time and taking a score for each.
    Path objects for each student's avatar are added to a list of avatar
    Paths corresponding to scores.

    Scores can be int or float, eg 78.5 is valid entry, and are
    converted to float (from str) by default.

    Return is a dict with scores as keys, lists of Path objects as
    values. eg student_scores = {33: [Path_obj1, Path_obj2, Path_obj3,
                                 17: [Path_obj1, Path_obj2, Path_obj3]
                                 }

    :param current_class: Class object
    :return: dict
    """
    student_scores: dict = dict()
    for student in current_class.students:

        student_score = take_score_entry(student.name)
        # add avatar to list of avatars for score
        if student_score is not None:
            student_avatar_filename = student.avatar_filename
            avatar_path = get_avatar_path(current_class.name,
                                          student_avatar_filename)

            student_scores[student_score] = student_scores.get(
                student_score, []) + [avatar_path]

    return student_scores
Пример #2
0
def take_score_data(class_name: str):
    """
    UI function presenting student names from supplied class one at a
    time and taking a score for each.
    Path objects for each student's avatar are added to a list of avatar
    Paths corresponding to scores.

    Scores can be int or float, eg 78.5 is valid entry, and are
    converted to float (from str) by default.

    Return is a dict with scores as keys, lists of Path objects as
    values. eg student_scores = {33: [Path_obj1, Path_obj2, Path_obj3,
                                 17: [Path_obj1, Path_obj2, Path_obj3]
                                 }


    :param class_name: str
    :return: dict
    """

    class_data_dict = load_class_data(class_name)

    student_scores = {}

    print(
        f"\nEnter student scores for {class_name}: \n"
        f"Type score for each student, or '_' to exclude student, and press enter."
    )

    for student_name in list(class_data_dict.keys()):

        student_avatar_filename = class_data_dict[student_name][0]
        avatar_path = get_avatar_path(class_name, student_avatar_filename)

        student_score = take_score_entry(student_name)
        # add avatar to list of avatars for score
        if student_score:
            student_scores[student_score] = student_scores.get(
                student_score, []) + [avatar_path]

    # Newline between last score and 'Please enter a chart name/title: '
    print('\n')

    return student_scores
Пример #3
0
 def test_get_avatar_path_calls_avatar_path_from_string(
         self, mock_avatar_path_from_string):
     mock_avatar_path_from_string.return_value = True
     assert get_avatar_path(self.my_class_name, self.my_avatar_path)
Пример #4
0
 def test_get_avatar_path_returning_avatar_path_from_string(self):
     return_val = Path(self.mock_CLASSLIST_DATA_PATH, self.my_class_name,
                       'avatars', self.my_avatar_path)
     assert get_avatar_path(self.my_class_name,
                            self.my_avatar_path) == return_val
Пример #5
0
 def test_get_avatar_path_when_None(self):
     assert get_avatar_path(self.my_class_name,
                            None) == self.mock_DEFAULT_AVATAR_PATH