Esempio n. 1
0
    def testChecksumAfterSaveRestore(self):
        """
        A backend 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 backend that simply has the two sequences added to
        it without interruption.
        """
        seq1 = 'FRRRFRRRFASAASA'
        seq2 = 'MMMMMMMMMFRRRFR'
        dbParams1 = DatabaseParameters(landmarks=[AlphaHelix, BetaStrand],
                                       trigPoints=[Peaks, Troughs])
        be1 = Backend()
        be1.configure(dbParams1, 'name1', 0)
        be1.addSubject(AARead('id1', seq1), '0')
        fp = StringIO()
        be1.save(fp)
        fp.seek(0)
        be1 = Backend.restore(fp)
        be1.addSubject(AARead('id2', seq2), '1')

        dbParams2 = DatabaseParameters(landmarks=[AlphaHelix, BetaStrand],
                                       trigPoints=[Peaks, Troughs])
        be2 = Backend()
        be2.configure(dbParams2, 'name2', 0)
        be2.addSubject(AARead('id1', seq1), '0')
        be2.addSubject(AARead('id2', seq2), '1')

        self.assertEqual(be1.checksum(), be2.checksum())
Esempio n. 2
0
    def testSaveContentIncludesExpectedKeysAndValues(self):
        """
        When a backend saves, its JSON content must include the expected
        keys and values.
        """
        dbParams = DatabaseParameters(landmarks=[], trigPoints=[],
                                      limitPerLandmark=16, maxDistance=17,
                                      minDistance=18, distanceBase=19.0)
        be = Backend()
        be.configure(dbParams, 'backend', 33)
        fp = StringIO()
        be.save(fp)
        fp.seek(0)

        DatabaseParameters.restore(fp)
        SubjectStore.restore(fp)
        state = loads(fp.readline()[:-1])

        # Keys
        self.assertEqual(
            set(['checksum', 'd', 'name', '_totalCoveredResidues']),
            set(state.keys()))

        # Values
        self.assertEqual(be.checksum(), state['checksum'])
        self.assertEqual({}, state['d'])
        self.assertEqual('backend', state['name'])
        self.assertEqual(0, state['_totalCoveredResidues'])
Esempio n. 3
0
 def testInitialChecksum(self):
     """
     The backend checksum must be set to the value passed to its
     __init__ method.
     """
     dbParams = DatabaseParameters(landmarks=[], trigPoints=[])
     be = Backend()
     be.configure(dbParams, 'backend', 10)
     self.assertEqual(10, be.checksum())
Esempio n. 4
0
    def testChecksumAfterSubjectAdded(self):
        """
        The backend checksum must be as expected when a subject has been
        added to the backend.
        """
        dbParams = DatabaseParameters(landmarks=[], trigPoints=[])
        be = Backend()
        be.configure(dbParams, 'backend', 10)
        sequence = 'AFRRRFRRRFASAASA'
        subject = AARead('id', sequence)
        be.addSubject(subject, '0')

        expected = Checksum(10).update([
            'id',
            sequence,
        ])
        self.assertEqual(expected.value, be.checksum())
Esempio n. 5
0
 def testSaveRestoreNonEmpty(self):
     """
     When asked to save and then restore a non-empty backend, the correct
     backend must result.
     """
     dbParams = DatabaseParameters(landmarks=[AlphaHelix, BetaStrand],
                                   trigPoints=[Peaks, Troughs])
     be = Backend()
     be.configure(dbParams)
     be.addSubject(AARead('id', 'FRRRFRRRFASAASA'), '0')
     fp = StringIO()
     be.save(fp)
     fp.seek(0)
     result = Backend.restore(fp)
     self.assertEqual(be.subjectCount(), result.subjectCount())
     self.assertEqual(be.d, result.d)
     self.assertEqual(be.checksum(), result.checksum())
     self.assertIs(None, be.dbParams.compare(result.dbParams))