def addRecord(self, newID, newGender, newAge, newSales, newBMI, newIncome, autoID, overwrite): typeCheckStringERR(newID) preppedID = None invalidID = False origRec = None insertPos = None overwriteSignal = 0 # will become 1 if overwriting will be used try: preppedID = self._prepID(newID) origRec, insertPos = self._prot_findRecord(preppedID) except InvalidIDException: invalidID = True if origRec is not None and overwrite: overwriteSignal = 1 elif (origRec is not None or invalidID) and autoID: preppedID, insertPos = self._autoID() # doNotUse, insertPos = self._prot_findRecord(preppedID) elif origRec is not None: raise DuplicateIDException() elif invalidID: raise InvalidIDException() newRec = Record(preppedID, newGender) self._allMyRecords[insertPos:insertPos + overwriteSignal] = [newRec] newRec.setAge(newAge) newRec.setSales(newSales) newRec.setBMI(newBMI) newRec.setIncome(newIncome)
def test_NoChangeBMI(self): """ Expect BMI to remain after attempting to set it to 'other' (not recognised in enumeration) """ expBMI = "Overweight" rec = Record(None, "M") """Default values proven in other test""" rec.setBMI(expBMI) rec.setBMI("other") self.assertEqual(expBMI, rec.getBMI())