def test_print_class_list_no_grades(self, mock_stdout, mock_input): crud.file_write([]) crud.add_student() crud.print_class_list() self.assertTrue("Test Test T12345678 True 10.0 / 20.0" , mock_stdout.getvalue()) crud.file_write([])
def test_add_student_print_output_when_student_already_exists_in_system( self, mock_stdout): with mock.patch('builtins.open', return_value=io.StringIO(original_file)): mock_student_info = [ "Rob", "Stark", "A47585945", "True", ["95", "78"] ] expected_output = "\nThe student number you entered already exists in the system!\n\n" add_student(mock_student_info) self.assertEqual(mock_stdout.getvalue(), expected_output)
def test_add_student_print_output_when_file_write_was_unsuccessful( self, mock_stdout): with mock.patch('builtins.open', side_effect=[ io.StringIO(original_file), io.StringIO(original_file), io.StringIO(original_file) ]): mock_student_info = [ "Jon", "Snow", "A01024575", "True", ["87", "98"] ] expected_output = "\nStudent could not be written to file.\n\n" add_student(mock_student_info) self.assertEqual(mock_stdout.getvalue(), expected_output)
def test_add_student_successful_print_output(self, mock_stdout): with mock.patch('builtins.open', side_effect=[ io.StringIO(original_file), io.StringIO(original_file), io.StringIO(file_after_add) ]): mock_student_info = [ "Jon", "Snow", "A01024575", "True", ["87", "98"] ] expected_output = "\nStudent successfully added:\n" \ "Name: Jon Snow, Student Number: A01024575, In Good Standing: True, Grades: 87 98\n\n" add_student(mock_student_info) self.assertEqual(mock_stdout.getvalue(), expected_output)
def test_calculate_class_average(self, mock_stdout, mock_input): crud.file_write([]) crud.add_student() crud.add_student() crud.add_student() crud.calculate_class_average() self.assertTrue("15", mock_stdout.getvalue()) crud.file_write([])
def test_add_student_print(self, mock_write, mock_open, mock_input, mock_stdout): add_student() self.assertEqual(mock_stdout.getvalue(), "\nStudent was added successfully!\n\n")
def test_add_student_bool(self, mock_write, mock_open, mock_input): self.assertEqual(add_student(), True)
def test_calculate_class_average_no_grades(self, mock_stdout, mock_input): crud.file_write([]) crud.add_student() crud.calculate_class_average() self.assertTrue("No available grades" in mock_stdout.getvalue()) crud.file_write([])
def test_create_student_duplicate_student_number(self, mock_input): crud.add_student() with self.assertRaises(ValueError): crud.create_student() crud.file_write([])
def test_delete_student(self, mock_input): crud.file_write([]) crud.add_student() crud.delete_student() self.assertEqual(0, len(crud.file_read()))
def test_add_student_successfully(self, mock_input): crud.add_student() self.assertEqual("T12345678", crud.file_read()[0].get_student_number()) crud.file_write([])
def test_add_student_invalid_grade(self, mock_stdout, mock_input): crud.add_student() self.assertTrue("ERROR" in mock_stdout.getvalue())
def test_add_student_duplicate_student_number(self, mock_stdout, mock_input): crud.add_student() crud.add_student() self.assertTrue("ERROR" in mock_stdout.getvalue()) crud.file_write([])
def test_add_grade_invalid_grade(self, mock_stdout, mock_input): crud.file_write([]) crud.add_student() crud.add_grade() self.assertTrue("Invalid grade" in mock_stdout.getvalue())
def test_add_grade_successfully(self, mock_input): crud.file_write([]) crud.add_student() crud.add_grade() self.assertEqual(42.0, crud.file_read()[0].get_final_grades()[0]) crud.file_write([])