Back to index

python-biopython  1.60
setup_BioSQL.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # This code is part of the Biopython distribution and governed by its
00003 # license.  Please see the LICENSE file that should have been included
00004 # as part of this package.
00005 
00006 """Preparation for BioSQL tests, setting passwords etc
00007 """
00008 import os
00009 from Bio import MissingExternalDependencyError
00010 from BioSQL import BioSeqDatabase
00011 
00012 ##################################
00013 # Start of user-editable section #
00014 ##################################
00015 
00016 # You are expected to edit the following lines to match your system.
00017 # The BioSQL unit tests will call this code, and will only run if it works.
00018 
00019 # Constants for the database driver
00020 DBHOST = 'localhost'
00021 DBUSER = 'root'
00022 DBPASSWD = ''
00023 TESTDB = 'biosql_test'
00024 
00025 # -- MySQL
00026 #DBDRIVER = 'MySQLdb'
00027 #DBTYPE = 'mysql'
00028 # -- PostgreSQL
00029 #DBDRIVER = 'psycopg2'
00030 #DBTYPE = 'pg'
00031 # -- SQLite
00032 DBDRIVER = 'sqlite3'
00033 DBTYPE = 'sqlite'
00034 TESTDB = os.path.join(os.getcwd(), "BioSQL", "temp_sqlite.db")
00035 # In memory SQLite does not work with current test structure since the tests
00036 # expect databases to be retained between individual tests. 
00037 #TESTDB = ':memory:'
00038 
00039 ################################
00040 # End of user-editable section #
00041 ################################
00042 
00043 # Works for mysql and postgresql, not oracle
00044 try:
00045     DBSCHEMA = "biosqldb-" + DBTYPE + ".sql"
00046 except NameError:
00047     #This happens if the lines above are commented out
00048     message = "Enter your settings in Tests/setup_BioSQL.py " \
00049               "(not important if you do not plan to use BioSQL)."
00050     raise MissingExternalDependencyError(message)
00051 
00052 # Uses the SQL file in the Tests/BioSQL directory -- try to keep this current
00053 # with what is going on with BioSQL
00054 SQL_FILE = os.path.join(os.getcwd(), "BioSQL", DBSCHEMA)
00055 assert os.path.isfile(SQL_FILE), "Missing %s" % SQL_FILE
00056 
00057 #Check the database driver is installed:
00058 try:
00059     __import__(DBDRIVER)
00060 except ImportError:
00061     message = "Install %s or correct Tests/setup_BioSQL.py "\
00062               "(not important if you do not plan to use BioSQL)." % DBDRIVER
00063     raise MissingExternalDependencyError(message)
00064 
00065 #Could check the username, password and host work here,
00066 #but this only seems to work for the first unit test
00067 #that tries to import this file.