예제 #1
0
 def _read_instructors(self, path: str) -> None:
     """read each line from file instructors.txt and create instance of class instructor"""
     try:
         for cwid, name, department in file_reader(
                 os.path.join(self._path, 'instructors.txt'), 3, "|", True):
             self._instructors[cwid] = Instructor(cwid, name, department)
     except (FileNotFoundError, ValueError) as e:
         print(e)
    def _read_major(self, path: str) -> None:
        """read each line from file majors.txt and create instance of class Major"""
        try:
            for major, flag, course in file_reader(
                    os.path.join(self._path, 'majors.txt'), 3, "\t", True):
                if major not in self._majors.keys():
                    self._majors[major] = Major(major)
                self._majors[major].add_course(major, flag, course)

        except (FileNotFoundError, ValueError) as e:
            print(e)
예제 #3
0
    def _read_students(self, path: str) -> None:
        """read each line from path/students.txt and create instance of class student"""
        try:
            for cwid, name, major in file_reader(
                    os.path.join(self._path, 'students.txt'), 3, ";", True):
                if major in self._majors[major]._major:
                    required = self._majors[major].req_course()
                    elective = self._majors[major].elec_course()
                    self._students[cwid] = Student(cwid, name, major, required,
                                                   elective)

        except (FileNotFoundError, ValueError) as e:
            print(e)
    def _read_students(self, path: str) -> None:
        """read each line from path/students.txt and create instance of class student"""
        try:
            for cwid, name, major in file_reader(
                    os.path.join(self._path, 'students.txt'), 3, "\t", True):
                if major in self._majors.keys():
                    required = self._majors[major].req_course()
                    elective = self._majors[major].elec_course()
                    self._students[cwid] = Student(cwid, name, major, required,
                                                   elective)

                else:
                    print(
                        f"Student with Name: {name} and CWID: {cwid} has Unknown Major:{major}"
                    )

        except (FileNotFoundError, ValueError) as e:
            print(e)
 def _read_grades(self, path: str) -> None:
     """ read student_cwid, course, grade, instructor_cwid """
     # tell the student about the course and the grade
     # look up student associated with student_cwid, reach inside and update the dictionary
     try:
         for student_cwid, course, grades, instructor_cwid in file_reader(
                 os.path.join(self._path, 'grades.txt'), 4, "\t", True):
             if student_cwid in self._students.keys():
                 stu: Student = self._students[student_cwid]
                 stu.store_course_grade(course, grades)
             else:
                 print(
                     f"The Student with CWID : {student_cwid} is unknown.")
             if instructor_cwid in self._instructors.keys():
                 inst: Instructor = self._instructors[instructor_cwid]
                 inst.store_course_student(course)
             else:
                 print(
                     f"The Instructor with CWID : {instructor_cwid} is unknown."
                 )
     except (FileNotFoundError, ValueError) as e:
         if FileNotFoundError:
             print(e)
 def test_file_reader(self):
     """The function tests the file_reader() function."""
     calculated: List[tuple] = [('123', 'Jin He', 'Computer Science'),('234', 'Nanda Koka', 'Software Engineering'),('345', 'Benji Cai', 'Software Engineering')]
     self.assertNotEqual(list(file_reader("func2_test.txt", 3, '|', False)), calculated)
     self.assertEqual(list(file_reader("func2_test.txt", 3, '|', True)), calculated)
     self.assertEqual(list(file_reader("func2_test.txt1", 3, '|', False)), ['File Not Found'])