def compose_classlist_dialogue(class_name: str) -> NewClass: """ Call UI elements to collect new class data. Provide feedback to user reflecting new class composition. Creates class object. If no students added to class, check if intended, making subsequent call to take_class_data_input UI if unintended blank class returned. :param class_name: str :return: Class object """ while True: new_class = take_class_data_input(class_name) if not new_class.students: # Test for empty class. create_empty_class = blank_class_dialogue() if create_empty_class: break # else: ie if not cancelled: continue # Line (and following) skipped from coverage due to peephole optimiser. break # class_data not empty class_data_feedback(new_class) return new_class
def test_class_data_feedback(self, test_full_class, capsys): printed_strings = [f'\nClass name: {test_full_class.name}\n'] + [ student.name + '\n' for student in test_full_class ] class_data_feedback(test_full_class) captured = capsys.readouterr().out assert captured == ''.join(printed_strings)
def test_class_data_feedback_with_empty_class(self, test_class_name_only, capsys): empty_class_feedback = 'No students entered.' printed_strings = [ f'\nClass name: {test_class_name_only.name}\n{empty_class_feedback}\n' ] class_data_feedback(test_class_name_only) captured = capsys.readouterr().out assert captured == ''.join(printed_strings)
def test_class_data_feedback(self): with patch('dionysus_app.UI_menus.class_functions_UI.print' ) as mocked_print: printed_strings = [f'\nClass name: {self.test_class_name}'] + [ name for name in test_class_data_set['loaded_dict'] ] class_data_feedback(self.test_class_name, self.test_class_data_dict) assert mocked_print.call_args_list == [ mock.call(printed_string) for printed_string in printed_strings ]
def test_class_data_feedback_with_empty_class(self): with patch('dionysus_app.UI_menus.class_functions_UI.print' ) as mocked_print: printed_strings = [f'\nClass name: {self.test_class_name}' ] + [self.empty_class_feedback] assert printed_strings == [ f'\nClass name: {self.test_class_name}', self.empty_class_feedback ] # ie No student names. class_data_feedback(self.test_class_name, self.empty_class_data_dict) assert mocked_print.call_args_list == [ mock.call(printed_string) for printed_string in printed_strings ]
def create_classlist_data(class_name: str): new_class = compose_classlist_dialogue(class_name) class_data_feedback(new_class) write_classlist_to_file(new_class) time.sleep(2) # Pause for user to look over feedback.