Exemplo n.º 1
0
def test_ErrorDBNotExists(tmpdir):
    '''Test the class ErrorDBNotExists (error when a database doesn't exist)'''
    # This file is not created, just a tmp path
    tmpfile = os.path.join(tmpdir.strpath, "tmpfile")
    # Test instantiation
    test_error = NCBImetaErrors.ErrorDBNotExists(tmpfile)
    # Test str representation (error message)
    error_output = str(test_error)
    error_expect = ("\n\nDatabase does not exist." + "\n" + tmpfile)
    assert error_output == error_expect
Exemplo n.º 2
0
args = vars(parser.parse_args())

db_name = args['dbName']
output_dir = args['outputDir']

#-----------------------------------------------------------------------#
#                           Argument Checking                           #
#-----------------------------------------------------------------------#

# Check if database exists
if os.path.exists(db_name):
    conn = sqlite3.connect(db_name)
    print('\nOpening database: ' + db_name, flush=True)
else:
    raise NCBImetaErrors.ErrorDBNotExists(db_name)

# Check if output dir exists
if not os.path.exists(output_dir):
    os.makedirs(CONFIG_OUTPUT_DIR)

# no errors were raised, safe to connect to db
cur = conn.cursor()

#-----------------------------------------------------------------------#
#                         Process Database                              #
#-----------------------------------------------------------------------#

# Get a list of tables
cur.execute("SELECT name FROM sqlite_master WHERE type='table';")
table_list = cur.fetchall()