コード例 #1
0
ファイル: test_database.py プロジェクト: acorg/light-matter
    def testPopulationFromCommandLineSequencesAndFastaFile(self):
        """
        Using both command line sequences and --databaseFasta must result in
        all the command line subjects and those in the file being added to the
        returned database.
        """
        parser = argparse.ArgumentParser()
        specifier = DatabaseSpecifier()
        specifier.addArgsToParser(parser)
        args = parser.parse_args([
            '--databaseFasta', 'file.fasta', '--databaseSequence', 'id1 FFF',
            '--databaseSequence', 'id2 RRR'
        ])
        data = '\n'.join(['>id3', 'FFFF', '>id4', 'RRRR'])
        mockOpener = mockOpen(read_data=data)
        with patch.object(builtins, 'open', mockOpener):
            db = specifier.getDatabaseFromArgs(args)

        allSubjects = [subject.read for subject in db.getSubjects()]
        self.assertEqual(
            {
                AARead('id1', 'FFF'),
                AARead('id2', 'RRR'),
                AARead('id3', 'FFFF'),
                AARead('id4', 'RRRR'),
            }, set(allSubjects))
コード例 #2
0
ファイル: test_database.py プロジェクト: acorg/light-matter
 def testPopulationNotAllowed(self):
     """
     Using --databaseFasta must result in a ValueError if database
     population has not been enabled.
     """
     parser = argparse.ArgumentParser()
     specifier = DatabaseSpecifier(allowPopulation=False)
     specifier.addArgsToParser(parser)
コード例 #3
0
ファイル: test_database.py プロジェクト: acorg/light-matter
 def testNoArgs(self):
     """
     If no arguments are given, getDatabaseFromArgs must return a database.
     """
     parser = argparse.ArgumentParser()
     specifier = DatabaseSpecifier()
     specifier.addArgsToParser(parser)
     args = parser.parse_args([])
     db = specifier.getDatabaseFromArgs(args)
     self.assertIsInstance(db, Database)
コード例 #4
0
ファイル: test_database.py プロジェクト: acorg/light-matter
 def testPassedParamsAreUsed(self):
     """
     If specific parameters are given, they must be used.
     """
     parser = argparse.ArgumentParser()
     specifier = DatabaseSpecifier()
     specifier.addArgsToParser(parser)
     args = parser.parse_args([])
     dbParams = DatabaseParameters()
     db = specifier.getDatabaseFromArgs(args, dbParams)
     self.assertIs(db.dbParams, dbParams)
コード例 #5
0
ファイル: test_database.py プロジェクト: acorg/light-matter
 def testNoArgsDefaultParameters(self):
     """
     The database returned from getDatabaseFromKeywords when it is
     passed no keywords must have the default database parameters.
     """
     parser = argparse.ArgumentParser()
     specifier = DatabaseSpecifier()
     specifier.addArgsToParser(parser)
     args = parser.parse_args([])
     db = specifier.getDatabaseFromArgs(args)
     self.assertIs(None, db.dbParams.compare(DatabaseParameters()))
コード例 #6
0
ファイル: test_database.py プロジェクト: acorg/light-matter
 def testPopulationFromCommandLineSequences(self):
     """
     Passing --databaseSequence arguments must result in the subjects in the
     sequences being added to the returned database.
     """
     parser = argparse.ArgumentParser()
     specifier = DatabaseSpecifier()
     specifier.addArgsToParser(parser)
     args = parser.parse_args(
         ['--databaseSequence', 'id1 FFF', '--databaseSequence', 'id2 RRR'])
     db = specifier.getDatabaseFromArgs(args)
     allSubjects = [subject.read for subject in db.getSubjects()]
     self.assertEqual(
         {AARead('id1', 'FFF'), AARead('id2', 'RRR')}, set(allSubjects))
コード例 #7
0
ファイル: test_database.py プロジェクト: acorg/light-matter
 def testCreationNotAllowed(self):
     """
     Not passing any arguments when creation (or a WAMP connection)
     is not allowed must result in a RuntimeError.
     """
     parser = argparse.ArgumentParser()
     specifier = DatabaseSpecifier(allowCreation=False, allowWamp=False)
     specifier.addArgsToParser(parser)
     args = parser.parse_args([])
     error = ('^Not enough information given to specify a database, '
              'database creation is not enabled, and '
              'no remote WAMP database could be found\.$')
     six.assertRaisesRegex(self, RuntimeError, error,
                           specifier.getDatabaseFromArgs, args)
コード例 #8
0
ファイル: test_database.py プロジェクト: acorg/light-matter
    def testPopulationFromFastaFile(self):
        """
        Passing a --databaseFasta argument must result in the subjects in the
        file being added to the returned database.
        """
        parser = argparse.ArgumentParser()
        specifier = DatabaseSpecifier()
        specifier.addArgsToParser(parser)
        args = parser.parse_args(['--databaseFasta', 'file.fasta'])
        data = '\n'.join(['>id1', 'FFF', '>id2', 'RRR'])
        mockOpener = mockOpen(read_data=data)
        with patch.object(builtins, 'open', mockOpener):
            db = specifier.getDatabaseFromArgs(args)

        allSubjects = [subject.read for subject in db.getSubjects()]
        self.assertEqual(
            {AARead('id1', 'FFF'), AARead('id2', 'RRR')}, set(allSubjects))
コード例 #9
0
#!/usr/bin/env python

import argparse

from autobahn.asyncio.wamp import ApplicationRunner

from light.autobahn.database import DatabaseComponent
from light.database import DatabaseSpecifier

if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description='Start a WAMP-based distributed light-matter database.')

    databaseSpecifier = DatabaseSpecifier(allowInMemory=False)
    databaseSpecifier.addArgsToParser(parser)
    args = parser.parse_args()
    # We're always using WAMP for distributed databases.
    args.wampServer = True

    database = databaseSpecifier.getDatabaseFromArgs(args)
    runner = ApplicationRunner(args.wampUrl,
                               args.realm,
                               extra=dict(database=database))
    runner.run(DatabaseComponent)