def testChecksumAfterSaveRestore(self): """ A database that has a sequence added to it, which is then saved and restored, and then has a second sequence is added to it must have the same checksum as a database that simply has the two sequences added to it without the intervening save/restore. """ seq1 = 'FRRRFRRRFASAASA' seq2 = 'MMMMMMMMMFRRRFR' dbParams1 = DatabaseParameters(landmarks=[AlphaHelix, BetaStrand], trigPoints=[Peaks, Troughs]) db1 = Database(dbParams1) db1.addSubject(AARead('id1', seq1)) fp = StringIO() db1.save(fp) fp.seek(0) db1 = Database.restore(fp) db1.addSubject(AARead('id2', seq2)) dbParams2 = DatabaseParameters(landmarks=[AlphaHelix, BetaStrand], trigPoints=[Peaks, Troughs]) db2 = Database(dbParams2) db2.addSubject(AARead('id1', seq1)) db2.addSubject(AARead('id2', seq2)) self.assertEqual(db1.checksum(), db2.checksum())
def testChecksumEmptyDatabase(self): """ The database checksum must be the same as the checksum for its parameters plus the default backend name when no subjects have been added to the database. """ dbParams = DatabaseParameters() expected = Checksum(dbParams.checksum).update([ Backend.DEFAULT_NAME, ]) db = Database(dbParams) self.assertEqual(expected.value, db.checksum())
def testChecksumAfterSubjectAdded(self): """ The database checksum must be as expected when a subject has been added to the database. """ dbParams = DatabaseParameters(landmarks=[AlphaHelix], trigPoints=[]) db = Database(dbParams) sequence = 'AFRRRFRRRFASAASA' subject = AARead('id', sequence) db.addSubject(subject) expected = Checksum(dbParams.checksum).update([ Backend.DEFAULT_NAME, 'id', sequence, ]) self.assertEqual(expected.value, db.checksum())
def testSaveRestoreNonEmpty(self): """ When asked to save and then restore a non-empty database, the correct database must result. """ dbParams = DatabaseParameters(landmarks=[AlphaHelix, BetaStrand], trigPoints=[Peaks, Troughs]) db = Database(dbParams) db.addSubject(AARead('id', 'FRRRFRRRFASAASA')) fp = StringIO() db.save(fp) fp.seek(0) result = db.restore(fp) self.assertIs(None, dbParams.compare(result.dbParams)) self.assertEqual(db.subjectCount(), result.subjectCount()) self.assertEqual(db.totalCoveredResidues(), result.totalCoveredResidues()) self.assertEqual(db.totalResidues(), result.totalResidues()) self.assertEqual(db.checksum(), result.checksum())