Example #1
0
 def test_file_reader(self) -> None:
     """ Test the file reader"""
     expected = [('123', 'Jin He', 'Computer Science'),
                 ('234', 'Nanda Koka', 'Software Engineering'),
                 ('345', 'Benji Cai', 'Software Engineering')]
     self.assertEqual(list(file_reader('HW08_Test.txt', 3, '|', True)),
                      expected)
     self.assertNotEqual(list(file_reader('HW08_Test.txt', 3, '|')),
                         expected)
     with self.assertRaises(ValueError):
         list(file_reader('HW08_Test.txt', 4, '|', True))
     with self.assertRaises(FileNotFoundError):
         list(file_reader('HW08_Test1.txt', 3, '|', True))
 def _get_students(self, path: str) -> None:
     """ Student detail are read using file reading gen and added to dictionary """
     for cwid, name, major in file_reader(path, 3, sep=';', header=True):
         if major not in self._majors:
             print(f"Student {cwid} '{name}' has unknown major '{major}'")
         else:
             self._students[cwid] = Student(cwid, name, self._majors[major])
Example #3
0
    def _get_grades(self, path) -> None:
        """Grades are read using file reading gen and assigned to student and instructor """
        for std_cwid, course, grade, instructor_cwid in file_reader(path, 4, sep='\t', header=False):
            if std_cwid in self._students:
                self._students[std_cwid].add_course(course, grade)
            else:
                print(f'Grades for student is {std_cwid}')

            if instructor_cwid in self._instructors:
                self._instructors[instructor_cwid].add_student(course)
            else:
                print(f'Grades for instructor is {instructor_cwid}')
 def _get_instructors(self, path: str) -> None:
     """ Instructor detail are read using file reading gen and added to dictionary """
     for cwid, name, dept in file_reader(path, 3, sep='|', header=True):
         self._instructors[cwid] = Instructor(cwid, name, dept)
 def _get_majors(self, path: str):
     """Major details are read using file reading gen and added to dictionary"""
     for major, flag, course in file_reader(path, 3, sep='\t', header=True):
         if major not in self._majors:
             self._majors[major] = Major(major)
         self._majors[major].add_course(course, flag)
Example #6
0
 def _get_students(self, path) -> None:
     """ Student detail are read using file reading gen and added to dictionary """
     for cwid, name, major in file_reader(path, 3, sep='\t', header=False):
         self._students[cwid] = Student(cwid, name, major)