def addGrade(self, cmd, debug = None): ''' Checks if using some parameteres a grade can be added in the repository Parameters: cmd - contains the parts which compose a grade debug - used only for testing ''' parameters = Utility.splitParameters(cmd) if parameters == None: raise ValueError if len(parameters) == 4 and len(parameters[0]) > 0 and len(parameters[1]) == 1 and len(parameters[2]) == 1 and len(parameters[3]) > 0: disc = parameters[0][0] for i in range(1, len(parameters[0])): disc = disc + ' ' + parameters[0][i] name = parameters[3][0] for i in range(1, len(parameters[3])): name = name + ' ' + parameters[0][i] if Controller.isDuplicate(self, disc, "discipline") != -1 and Utility.isConvertableToInt(parameters[1][0]) and Controller.isDuplicate(self, int(parameters[1][0]), "studentID") != -1 and parameters[2][0]: Repository.push(self._repository, Grade(disc, parameters[1][0], name, parameters[2][0])) return elif Controller.isDuplicate(self, disc, "discipline") == -1: raise DuplicateDisciplineError elif Controller.isDuplicate(self, int(parameters[1][0]), "studentID") == -1: raise DuplicateIDError raise ValueError
def setStudentID(self, new_st_id): ''' Checks if the student ID is an integer and sets it, otherwise it does nothing Parameters: new_st_id - new student id ''' if Utility.isInt(new_st_id) == True and new_st_id > 0: self._studentID = new_st_id elif Utility.isConvertableToInt(new_st_id) == True and int(new_st_id) > 0: self._studentID = int(new_st_id) else: return False
def _test_utility_isConvertableToInt(self): ''' Tests if convertability to int works ''' assert Utility.isConvertableToInt("7") == True assert Utility.isConvertableToInt("7.5") == False assert Utility.isConvertableToInt(7) == True assert Utility.isConvertableToInt("D6B8") == False assert Utility.isConvertableToInt("7.5.5") == False assert Utility.isConvertableToInt([]) == False