Exemple #1
0
 def testPopulationByInMemorySubjects(self):
     """
     Passing a subjects keyword must result in the subjects being added
     to the returned database.
     """
     subjects = Reads()
     subject1 = AARead('id1', 'FFF')
     subject2 = AARead('id2', 'RRR')
     subjects.add(subject1)
     subjects.add(subject2)
     db = DatabaseSpecifier().getDatabaseFromKeywords(subjects=subjects)
     allSubjects = [subject.read for subject in db.getSubjects()]
     self.assertEqual({subject1, subject2}, set(allSubjects))
Exemple #2
0
    def testPopulationFromFastaFile(self):
        """
        Passing a databaseFasta keyword must result in the subjects in the
        file being added to the returned database.
        """
        data = '\n'.join(['>id1', 'FFF', '>id2', 'RRR'])
        mockOpener = mockOpen(read_data=data)
        with patch.object(builtins, 'open', mockOpener):
            db = DatabaseSpecifier().getDatabaseFromKeywords(
                databaseFasta='file.fasta')

        allSubjects = [subject.read for subject in db.getSubjects()]
        self.assertEqual(
            {AARead('id1', 'FFF'), AARead('id2', 'RRR')}, set(allSubjects))
Exemple #3
0
 def testInMemoryDatabaseIsPopulated(self):
     """
     Passing a database keyword with an in-memory database results in that
     database being populated.
     """
     original = Database()
     subjects = Reads()
     subject1 = AARead('id1', 'FFF')
     subject2 = AARead('id2', 'RRR')
     subjects.add(subject1)
     subjects.add(subject2)
     db = DatabaseSpecifier().getDatabaseFromKeywords(database=original,
                                                      subjects=subjects)
     allSubjects = [subject.read for subject in db.getSubjects()]
     self.assertEqual({subject1, subject2}, set(allSubjects))
Exemple #4
0
    def testPopulationFromInMemoryAndFastaFile(self):
        """
        Passing both subjects and databaseFasta keywords must result in
        all the subjects in memory and in the file being added to the returned
        database.
        """
        subjects = Reads()
        subject1 = AARead('id1', 'FFF')
        subject2 = AARead('id2', 'RRR')
        subjects.add(subject1)
        subjects.add(subject2)

        data = '\n'.join(['>id3', 'FFFF', '>id4', 'RRRR'])
        mockOpener = mockOpen(read_data=data)
        with patch.object(builtins, 'open', mockOpener):
            db = DatabaseSpecifier().getDatabaseFromKeywords(
                subjects=subjects, databaseFasta='file.fasta')

        allSubjects = [subject.read for subject in db.getSubjects()]
        self.assertEqual(
            {subject1, subject2,
             AARead('id3', 'FFFF'),
             AARead('id4', 'RRRR')}, set(allSubjects))