Ejemplo n.º 1
0
 def setUp(self):
     self.students_list = [
         student.Student("Yongju", "Kwon", "A01059332", True, [91, 93, 87]),
         student.Student("Yongju2", "Kwon2", "A01059333", True,
                         [11, 21, 31]),
         student.Student("Yongju3", "Kwon3", "A01059334", True,
                         [13, 23, 33])
     ]
Ejemplo n.º 2
0
 def test_file_read_two_students_equal_list(self):
     reader = crud.file_read('testfile1.txt')
     new_list = []
     student1 = student.Student('Kyla', 'Purcell', 'A01088856', True, [80, 90, 100])
     student2 = student.Student('Kaylee', 'Hello', 'A01099967', False, [])
     for i in reader:
         new_list.append(i.__repr__())
     self.assertEqual([student1.__repr__(), student2.__repr__()], new_list)
 def test_file_delete_student_in_file_with_multiple_students(self):
     new_list = []
     student1 = student.Student('Kylo', 'Ren', 'A01077789', False, [40, 50])
     student2 = student.Student('Delete', 'Me', 'A01099985', True, [])
     crud.file_write(student1, 'testfile4.txt')
     crud.file_write(student2, 'testfile4.txt')
     crud.file_delete_student('A01099985', 'testfile4.txt')
     for i in crud.file_read('testfile3.txt'):
         new_list.append(i.__repr__())
     self.assertNotIn(student2.__repr__(), new_list)
Ejemplo n.º 4
0
 def test_print_class_list_two_student(self, mock_stdout):
     new_student = student.Student('Kylo', 'Purcell', 'A01088857', True, [80, 90, 70])
     new_student2 = student.Student('Kyla', 'Purcell', 'A01088856', True, [80])
     filename = 'testfile17.txt'
     crud.file_write(new_student, filename)
     crud.file_write(new_student2, filename)
     student_list = crud.file_read(filename)
     crud.print_class_list(filename)
     expected = 'Name: Kylo Purcell Student Number: A01088857 Status: True Grades: 80 90 70\n' \
                'Name: Kyla Purcell Student Number: A01088856 Status: True Grades: 80\n'\
                'There are 2 students currently enrolled in this school\n'
     crud.update_file([], filename)
     self.assertEqual(mock_stdout.getvalue(), expected)
 def test_printed_student_does_not_exist(self, mock_stdout, mock_input):
     new_student = student.Student('Kylo', 'Purcell', 'A01088857', True,
                                   [80, 90, 70])
     crud.file_write(new_student, 'testfile14.txt')
     crud.update_grades('A01088888', 'testfile14.txt')
     expected = 'We could not find that student in our file or grade could not be added\n'
     self.assertEqual(mock_stdout.getvalue(), expected)
 def test_file_delete_student_added_student_deleted(self):
     new_list = []
     student1 = student.Student('Kylo', 'Ren', 'A01077789', False, [40, 50])
     crud.file_write(student1, 'testfile3.txt')
     crud.file_delete_student('A01077789', 'testfile3.txt')
     for i in crud.file_read('testfile3.txt'):
         new_list.append(i.__repr__())
     self.assertNotIn(student1.__repr__(), new_list)
 def test_update_grades_valid_grade(self, mock_input):
     new_student = student.Student('Kylo', 'Purcell', 'A01088857', True,
                                   [80, 90, 70])
     crud.file_write(new_student, 'testfile9.txt')
     crud.update_grades('A01088857', 'testfile9.txt')
     student_list = crud.file_read('testfile9.txt')
     crud.update_file([], 'testfile9.txt')
     self.assertEqual([80, 90, 70, 85], student_list[0].get_grades_list())
 def test_update_grades_invalid_grade_low(self, mock_input):
     new_student = student.Student('Kylee', 'Purcell', 'A01088859', True,
                                   [60, 90, 40])
     crud.file_write(new_student, 'testfile11.txt')
     crud.update_grades('A01088859', 'testfile11.txt')
     student_list = crud.file_read('testfile11.txt')
     crud.update_file([], 'testfile11.txt')
     self.assertEqual([60, 90, 40], student_list[0].get_grades_list())
 def test_printed_student_grade_invalid(self, mock_stdout, mock_input):
     new_student = student.Student('Kylo', 'Purcell', 'A01088857', True,
                                   [80, 90, 70])
     crud.file_write(new_student, 'testfile15.txt')
     crud.update_grades('A01088857', 'testfile15.txt')
     crud.update_file([], 'testfile15.txt')
     expected = 'Grades cannot include numbers below zero or above 100\n'\
                'We could not find that student in our file or grade could not be added\n'
     self.assertEqual(mock_stdout.getvalue(), expected)
Ejemplo n.º 10
0
 def test_file_append(self):
     crud.file_append(
         student.Student("Yongju2", "Kwon2", "A01059335", True,
                         [13, 23, 33]))
     with open("students.txt", 'r') as file_object:
         student_info = file_object.read()
     self.assertEqual(
         "Yongju Kwon A01059332 True 91 93 87\n"
         "Yongju2 Kwon2 A01059335 True 13 23 33\n", student_info)
Ejemplo n.º 11
0
def file_read() -> list:
    """Read text line by line, create objects with the info and return the list has the objects.

    Create a list and store objects made of the string read from text file
    RETURN: a list have student objects
    """
    students_list = list()
    with open("students.txt", 'r') as file_object:
        for line in file_object:
            student_info = line.split()
            std = student.Student(student_info[0], student_info[1], student_info[2], eval(student_info[3]),
                                  student_info[4:])
            students_list.append(std)
    return students_list
Ejemplo n.º 12
0
def add_student() -> None:
    """Create a student object and append it on text file.

    Create an object based on user's input and append the info of the object as a string if the student does not exist
    in text file
    POSTCONDITION: Create a student object
    POSTCONDITION: Write a string which is information of student object on text file
    POSTCONDITION: Print helpful message if the student number already exists in the text file
    """
    new_student = student.Student(student.ask_first_name(),
                                  student.ask_last_name(),
                                  student.ask_student_num(),
                                  student.ask_student_stat(),
                                  student.ask_grades())
    if does_file_exist():
        file_append(new_student) if not is_student_in_file(new_student.get_student_number()) \
            else print("The student number is already registered.\n")
    else:
        file_append(new_student)
Ejemplo n.º 13
0
def file_read(filename: str) -> list:
    """
     Read a student text file.

     PARAM: filename, a string
     PRE-CONDITION: filename must be a string ending in .txt
     POST-CONDITION: Converts students in the text file to student objects and adds them to a list
     RETURN: list of students as a list of student objects.
     """
    object_list = []
    with open(filename) as file_object:
        lines = file_object.readlines()
        student_list = [line.split() for line in lines]
        for i in student_list:
            if not i:
                continue
            else:
                object_list.append(
                    student.Student(i[0], i[1], i[2], make_boolean(i[3]),
                                    list(map(int, i[4:]))))
        return object_list
Ejemplo n.º 14
0
def add_student():
    """
     Create a student object.

     POST-CONDITION: If user input is valid returns a student object, otherwise returns None
     RETURN: a student as a Student object or None.
     """
    student1 = None
    try:
        first_name1 = input("What is the student's first name ")
        last_name1 = input("What is the student's last name ")
        student_number1 = input("What is the student's # ")
        status1 = make_boolean(
            input('Is this student in good standing, (True or False) '))
        grades = add_grades()
        student1 = student.Student(first_name1, last_name1, student_number1,
                                   status1, grades)
        student1.format_first_name()
        student1.format_last_name()
    except ValueError:
        print(
            'A student must have correct a student number, a first/last name and a status to be added '
        )
    return student1
Ejemplo n.º 15
0
 def test_calculate_gpa_with_empty_list(self):
     self.students_list.append(
         student.Student("Yongju3", "Kwon3", "A01059334", True, []))
     self.assertEqual([90.33, 21, 23],
                      student.Student.calculate_gpa(self.students_list))
Ejemplo n.º 16
0
 def setUp(self):
     self.student1 = student.Student("Yongju", "Kwon", "A01059332", True,
                                     [91, 93, 87])
     crud.file_write(str(self.student1) + "\n")
 def test_file_delete_student_does_exist(self):
     student1 = student.Student('Kyla', 'Ren', 'A01077789', False, [40, 50])
     crud.file_write(student1, 'testfile6.txt')
     self.assertTrue(crud.file_delete_student('A01077789', 'testfile6.txt'))
 def test_printed_output_true(self, mock_stdout):
     expected = 'We successfully deleted the student\n'
     student1 = student.Student('Kyla', 'Ren', 'A01077789', False, [40, 50])
     crud.file_write(student1, 'testfile7.txt')
     crud.file_delete_student('A01077789', 'testfile7.txt')
     self.assertEqual(mock_stdout.getvalue(), expected)
 def test_printed_output_false(self, mock_stdout):
     expected = 'We could not remove that student because they do not exist in the database\n'
     student1 = student.Student('Kyla', 'Ren', 'A01077789', False, [40, 50])
     crud.file_write(student1, 'testfile8.txt')
     crud.file_delete_student('A01011111', 'testfile8.txt')
     self.assertEqual(mock_stdout.getvalue(), expected)
 def test_update_grades_is_false(self, mock_input):
     new_student = student.Student('Kylo', 'Purcell', 'A01088857', True,
                                   [80, 90, 70])
     crud.file_write(new_student, 'testfile13.txt')
     self.assertFalse(crud.update_grades('A01088888', 'testfile13.txt'))
Ejemplo n.º 21
0
 def setUp(self):
     self.test_student = student.Student('Kyla', 'Purcell', 'A01088856',
                                         True, [80, 90, 75])
     self.test_student2 = student.Student('dahlia', 'billings', 'A01099976',
                                          False, [])
 def test_update_file_normal_case(self):
     student1 = student.Student('Kylo', 'Ren', 'A01077789', False, [40, 50])
     crud.update_file([student1], 'testfile2.txt')
     read = crud.file_read('testfile2.txt')
     self.assertEqual([student1][0].__repr__(), read[0].__repr__())
 def setUp(self):
     self.my_std = student.Student("smith", "sam", "A01059332", True,
                                   [100, 99, 79])
     crud.file_write(self.my_std)
Ejemplo n.º 24
0
 def setUp(self):
     self.my_std = student.Student("smith", "sam", "A01059332", True)
Ejemplo n.º 25
0
 def test_file_write_returns_true(self):
     new_student = student.Student('Kylo', 'Purcell', 'A01088857', True, [80, 90, 70])
     filename = 'testfile1.txt'
     self.assertTrue(crud.file_write(new_student, filename))
Ejemplo n.º 26
0
 def test_file_read_length(self):
     self.student1 = student.Student("Yongju", "Kwon", "A01059332", True,
                                     [91, 93, 87])
     crud.file_write(str(self.student1) + "\n")
     self.assertEqual(1, len(crud.file_read()))
Ejemplo n.º 27
0
 def test_file_read_return_type(self):
     self.student1 = student.Student("Yongju", "Kwon", "A01059332", True,
                                     [91, 93, 87])
     crud.file_write(str(self.student1) + "\n")
     self.assertTrue(type(crud.file_read()) == list)
 def test_update_file_returns_none(self):
     student1 = student.Student('Kylo', 'Ren', 'A01077789', False, [40, 50])
     self.assertIsNone(crud.update_file([student1], 'testfile2.txt'))
Ejemplo n.º 29
0
 def test_file_write_normal_case(self):
     new_student = student.Student('Kylo', 'Purcell', 'A01088857', True, [80, 90, 70])
     filename = 'testfile1.txt'
     crud.file_write(new_student, filename)
     student_list = crud.file_read('testfile1.txt')
     self.assertEqual(new_student.__repr__(), student_list[len(student_list)-1].__repr__())
 def setUp(self):
     self.my_std = student.Student("yongju", "kwon", "A01059333", True,
                                   [0, 10])
     crud.file_write(self.my_std)