def test_file_reader(self) -> None:
     """
     This function has test cases for file_reader()
     """
     expect = [['123', 'Jin He', 'Computer Science'],
               ['234', 'Nanda Koka', 'Software Engineering'],
               ['345', 'Benji Cai', 'Software Engineering']]
     self.assertEqual(list(file_reader('./student_majors.txt',
                                       3, '|', True)), expect)
     self.assertNotEqual(list(file_reader(
         './student_majors.txt', 3, '|')), expect)
     with self.assertRaises(ValueError):
         list(file_reader('student_majors.txt', 4, '|', True))
     with self.assertRaises(FileNotFoundError):
         list(file_reader('xyz.txt', 3, '|', True))
Exemplo n.º 2
0
    def _read_instructor(self) -> None:
        """
        Read instructor file from path construct object
        """
        try:
            path: str = os.path.join(self._path,"instructors.txt")
            for cwid, name, dept in file_reader(path=path, fields=3, sep='|', header=True):
                self._instructors[cwid] = Instructor(cwid, dept, name)

        except FileNotFoundError:
           print(f"Can not open file at {self._path}")
        except ValueError:
            print(" Some fields are missing in 3")
Exemplo n.º 3
0
 def _read_students(self) -> None:
     """
     Read students file from path construct object
     """
     try:
         path: str = os.path.join(self._path,"students.txt")
         for cwid, name, major in file_reader(path=path, fields=3, sep=';', header=True):
             required: List[str] = self._majors[major].get_required()
             electives: List[str] = self._majors[major].get_elective()
             self._students[cwid] = Student(cwid,name, major, required, electives)
     except FileNotFoundError:
        print(f"Can not open file at {self._path}")
     except ValueError:
         print(" Some fields are missing in 2 ")
Exemplo n.º 4
0
 def _read_majors(self) -> None:
     """
     Read majors file from path construct object
     """
     try:
         path: str = os.path.join(self._path,"majors.txt")
         for major, required, course in file_reader(path=path, fields=3, sep='\t', header=True):
             if major not in self._majors:
                 self._majors[major] = Major(major)
             self._majors[major].add_course(required=required, course=course)
     except FileNotFoundError:
        print(f"Can not open file at {self._path}")
     except ValueError:
         print(" Some fields are missing in 1")
Exemplo n.º 5
0
    def _read_grades(self) -> None:
        """Read grade file from path construct object"""
        try:
            path: str = os.path.join(self._path,"grades.txt")
            for stu_cwid, course, grade, inst_cwid in file_reader(path=path, fields=4, sep='|', header=True):
                if stu_cwid in self._students:
                    s: Student = self._students[stu_cwid]
                    s.course_add(course=course, grade=grade)
                else:
                    raise ValueError("No Student with such id")

                if inst_cwid in self._instructors:
                    p: Instructor = self._instructors[inst_cwid]
                    p.inst_add_course(course)
                else:
                    raise ValueError("No Professor with that ID")

        except FileNotFoundError:
           print(f"Can not open file at {self._path}")
        except ValueError:
            print(" Some fields are missing in 4")