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))
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)
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)
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)
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()))
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))
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)
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))
#!/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)