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 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 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_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_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_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')
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_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_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_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')