def test_getdatabase_postgres_nohostname_noport_setdefault(self): """Check get_database set default hostname and port for MySQL""" try: db = AccessionID(dbname='taxadb', dbtype='postgres', password="******", username="******") self.assertEqual(int(db.get('port')), 5432) self.assertEqual(db.get('hostname'), 'localhost') except SystemExit as err: unittest.skip("Can't test function: %s" % str(err))
def main(): """ Main program function """ # Get arguments args = get_arguments() # Step 1 print("STEP 1: Extracting Genbank IDS from BLAST output...") accession = extract_genbank_id(args.blast_output_file) chunks = [accession[i:i + 999] for i in range(0, len(accession), 999)] print("Found {0} ids !".format(len(accession))) #print(accession) # Step 3 print("STEP 2: Writing results to file '{0}'...".format( args.taxonomy_file)) accession_db = AccessionID(dbtype='sqlite', dbname=args.taxadb_file) tax_db = TaxID(dbtype='sqlite', dbname=args.taxadb_file) taxids = accession_db.taxid(accession) #taxids = [accession_db.taxid(acc) for acc in accession] #print(taxids) write_results(chunks, accession_db, tax_db, args.taxonomy_file) print("DONE !")
def test_setconfig_nodbname_raises(self): """Check method raises SystemExit when no dbname set""" with self.assertRaises(SystemExit): AccessionID(dbtype='sqlite')
def test_set_config_option_unset_section(self): """Check set throws AttributeError as required section for settings option is not defined yet""" db = AccessionID(config=os.path.join(self.testdir, 'taxadb.cfg')) with self.assertRaises(AttributeError): db.set('newoption', 'newvalue', section="UNSET_SECCTION")
def test_getdatabase_nouser_or_nopasswd(self): """Check get_database throws SystemExit when no user or no password is set""" with self.assertRaises(SystemExit): AccessionID(dbname='taxadb', dbtype='mysql')
def test_get_config_nooption(self): """Check get method returns None when an option is not found in the configuration file""" db = AccessionID(config=os.path.join(self.testdir, 'taxadb.cfg')) self.assertIsNone(db.get('unknown'))
def test_get_config_returnsNone(self): """Check get method returns None when an option has no value in configuration file""" db = AccessionID(config=os.path.join(self.testdir, 'taxadb.cfg')) db.set('foobar', None) self.assertIsNone(db.get('foobar'))
def test_set_args(self): """Check we can set config from dict as args""" db = AccessionID(dbtype='sqlite', dbname=os.path.join(self.testdir, 'test_db.sqlite')) self.assertEqual(db.get('dbtype'), 'sqlite') self.assertEqual(os.path.basename(db.get('dbname')), 'test_db.sqlite')
def test_set_config_with_wrong_section(self): """Check we catch exception by using config file with wrong section""" with self.assertRaises(SystemExit): AccessionID(config=os.path.join(self.testdir, 'taxadb-nosection.cfg'))
def test_getdatabase_sqlite_throws(self): """Check get_database throws SystemExit when wrong or inaccessible db""" with self.assertRaises(SystemExit): db = AccessionID(dbname='/unaccessible', dbtype='sqlite')
def test_setconfig_from_configfile(self): """Check passing a configuration file is ok""" db = AccessionID(config=os.path.join(self.testdir, 'taxadb.cfg')) self.assertEqual(db.get('dbname'), 'taxadb/test/test_db.sqlite') self.assertEqual(db.get('dbtype'), 'sqlite')
def test_setconfig_from_envvar(self): """Check using configuration from environment variable is ok""" self._set_config_from_envvar() db = AccessionID() self.assertEqual(db.get('dbname'), 'taxadb/test/test_db.sqlite') self.assertEqual(db.get('dbtype'), 'sqlite')