def read_students_from_file(classes_dict):
    global first, student
    students_dict = {}
    fileInput = input(
        "Enter the name of the file you want to read the student info from:")
    path = fileInput + ".csv"
    if os.path.isfile(path):
        file = open(path)
        reader = csv.reader(file)
        for line in reader:
            first = str(line[0])
            last = str(line[1])
            email = str(line[2])
            major = str(line[3])
            standing = str(line[4])
            classes = str(line[5]).split(sep="-")
            student = Student(first, last, email, major, standing)
            full_name = first + " " + last
            students_dict[full_name] = student
            for group2 in classes:
                for title1, group1 in classes_dict.items():
                    if group2 == title1:
                        student.add_class(group1)
                    else:
                        pass
    else:
        print('No such file!')

    return students_dict
Example #2
0
class TestStudent(TestCase):
    def setUp(self):
        self.obj = Student("Johan", "Muco", "*****@*****.**",
                           "Computer Science", "Senior")
        self.class_obj = Group("Cos101", 3)

    def test_setMajor_match(self):
        self.assertEqual(self.obj.get_major(), "Computer Science")
        self.obj.set_major("Journalism")
        self.assertEqual(self.obj.get_major(), "Journalism")

    def test_setMajor_noMatch(self):
        self.assertEqual(self.obj.get_major(), "Computer Science")
        self.obj.set_major("333")
        self.assertEqual(self.obj.get_major(), "No_major")

    def test_setStanding_match(self):
        self.assertEqual(self.obj.get_standing(), "Senior")
        self.obj.set_standing("Freshman")
        self.assertEqual(self.obj.get_standing(), "Freshman")

    def test_setStanding_noMatch(self):
        self.assertEqual(self.obj.get_standing(), "Senior")
        self.obj.set_standing("444")
        self.assertEqual(self.obj.get_standing(), "No_standing")

    def test_add_class_failure(self):
        self.assertEqual(self.obj.add_class(self.obj),
                         "Object needs to be of Group type")

    def test_get_classes_success(self):
        self.obj.add_class(self.class_obj)
        self.assertEqual(self.obj.get_classes(), [self.class_obj])

    def test_get_classes_empty(self):
        self.assertEqual(self.obj.get_classes(), [])