def testFindMatchAfterSaveRestore(self): """ A matching subject found before a save/restore must also be found following a database save/restore. """ subject = AARead('subject', 'AFRRRFRRRFASAASAVVVVVVASAVVVASA') query = AARead('query', 'FRRRFRRRFASAASAFRRRFRRRFFRRRFRRRFFRRRFRRRF') dbParams = DatabaseParameters(landmarks=[AlphaHelix, BetaStrand], trigPoints=[Peaks]) db1 = Database(dbParams) db1.addSubject(subject) result = db1.find(query) expected = { '0': [{ 'queryLandmark': Landmark('AlphaHelix', 'A', 0, 9, 2), 'queryTrigPoint': TrigPoint('Peaks', 'P', 10), 'subjectLandmark': Landmark('AlphaHelix', 'A', 1, 9, 2), 'subjectTrigPoint': TrigPoint('Peaks', 'P', 11), }, { 'queryLandmark': Landmark('AlphaHelix', 'A', 0, 9, 2), 'queryTrigPoint': TrigPoint('Peaks', 'P', 13), 'subjectLandmark': Landmark('AlphaHelix', 'A', 1, 9, 2), 'subjectTrigPoint': TrigPoint('Peaks', 'P', 14), }] } self.assertEqual(expected, result.matches) fp = StringIO() db1.save(fp) fp.seek(0) db2 = Database.restore(fp) result = db2.find(query) self.assertEqual(expected, result.matches)
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 testSaveRestoreEmpty(self): """ When asked to save and then restore an empty database, the correct database must result. """ dbParams = DatabaseParameters(landmarks=[AlphaHelix], trigPoints=[Peaks]) db = Database(dbParams) fp = StringIO() db.save(fp) fp.seek(0) result = db.restore(fp) self.assertEqual(0, result.subjectCount()) self.assertEqual(0, result.totalCoveredResidues()) self.assertEqual(0, result.totalResidues()) self.assertIs(None, dbParams.compare(result.dbParams))
def testSaveRestoreWithNonDefaultParameters(self): """ When asked to save and then restore a database with non-default parameters, a database with the correct parameters must result. """ dbParams = DatabaseParameters(landmarks=[], trigPoints=[], limitPerLandmark=16, maxDistance=17, minDistance=18, distanceBase=19.0) db = Database(dbParams) fp = StringIO() db.save(fp) fp.seek(0) result = db.restore(fp) self.assertIs(None, dbParams.compare(result.dbParams))
def testSaveContentHasFourParts(self): """ When a simple database saves, its content must include parts for the database parameters, the database state, the backend parameters and the backend state. """ dbParams = DatabaseParameters(landmarks=[AlphaHelix], trigPoints=[Peaks]) db = Database(dbParams) fp = StringIO() db.save(fp) fp.seek(0) dbParams = DatabaseParameters.restore(fp) loads(fp.readline()[:-1]) backendParams = DatabaseParameters.restore(fp) loads(fp.readline()[:-1]) self.assertIs(None, dbParams.compare(backendParams))
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())
def testSaveContentIncludesExpectedKeysAndValues(self): """ When the database saves, its JSON content must include the expected keys and values. """ dbParams = DatabaseParameters(landmarks=[AlphaHelix], trigPoints=[Peaks]) db = Database(dbParams) fp = StringIO() db.save(fp) fp.seek(0) DatabaseParameters.restore(fp) state = loads(fp.readline()[:-1]) # Keys self.assertEqual(['_connectorClassName'], list(state.keys())) # Values self.assertEqual('SimpleConnector', state['_connectorClassName'])