Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Static Public Attributes
test_BioSQL.ReadTest Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def test_server
def test_get_db_items
def test_lookup_items

Public Attributes

 server
 db

Static Public Attributes

int loaded_db = 0

Detailed Description

Test reading a database from an already built database.

Definition at line 131 of file test_BioSQL.py.


Member Function Documentation

Connect to and load up the database.

Definition at line 136 of file test_BioSQL.py.

00136 
00137     def setUp(self):
00138         """Connect to and load up the database.
00139         """
00140         gb_file = "GenBank/cor6_6.gb"
00141         gb_handle = open(gb_file, "r")
00142         load_database(gb_handle)
00143         gb_handle.close()
00144             
00145         self.server = BioSeqDatabase.open_database(driver = DBDRIVER,
00146                                               user = DBUSER, 
00147                                               passwd = DBPASSWD,
00148                                               host = DBHOST, db = TESTDB)
00149             
00150         self.db = self.server["biosql-test"]

Here is the call graph for this function:

Definition at line 151 of file test_BioSQL.py.

00151 
00152     def tearDown(self):
00153         self.server.close()
00154         del self.db
00155         del self.server

Check list, keys, length etc

Definition at line 171 of file test_BioSQL.py.

00171 
00172     def test_get_db_items(self):
00173         """Check list, keys, length etc"""
00174         db = self.db
00175         items = db.values()
00176         keys = db.keys()
00177         l = len(items)
00178         self.assertEqual(l, len(db))
00179         self.assertEqual(l, len(list(db.iteritems())))
00180         self.assertEqual(l, len(list(db.iterkeys())))
00181         self.assertEqual(l, len(list(db.itervalues())))
00182         for (k1,r1), (k2,r2) in zip(zip(keys, items), db.iteritems()):
00183             self.assertEqual(k1, k2)
00184             self.assertEqual(r1.id, r2.id)
00185         for k in keys:
00186             del db[k]
00187         self.assertEqual(0, len(db))
00188         try:
00189             del db["non-existant-name"]
00190             assert False, "Should have raised KeyError"
00191         except KeyError:
00192             pass

Test retrieval of items using various ids.

Definition at line 193 of file test_BioSQL.py.

00193 
00194     def test_lookup_items(self):
00195         """Test retrieval of items using various ids.
00196         """
00197         item = self.db.lookup(accession = "X62281")
00198         try:
00199             item = self.db.lookup(accession = "Not real")
00200             raise Assertionerror("No problem on fake id retrieval")
00201         except IndexError:
00202             pass
00203         item = self.db.lookup(display_id = "ATKIN2")
00204         try:
00205             item = self.db.lookup(display_id = "Not real")
00206             raise AssertionError("No problem on fake id retrieval")
00207         except IndexError:
00208             pass
00209         
00210         # primary id retrieval
00211         item = self.db.lookup(primary_id = "16353")
00212         try:
00213             item = self.db.lookup(primary_id = "Not Real")
00214             raise AssertionError("No problem on fake primary id retrieval")
00215         except IndexError:
00216             pass

Check BioSeqDatabase methods

Definition at line 156 of file test_BioSQL.py.

00156 
00157     def test_server(self):
00158         """Check BioSeqDatabase methods"""
00159         server = self.server
00160         self.assertTrue("biosql-test" in server)
00161         self.assertEqual(1, len(server))
00162         self.assertEqual(["biosql-test"], server.keys())
00163         #Check we can delete the namespace...
00164         del server["biosql-test"]
00165         self.assertEqual(0, len(server))
00166         try:
00167             del server["non-existant-name"]
00168             assert False, "Should have raised KeyError"
00169         except KeyError:
00170             pass


Member Data Documentation

Definition at line 149 of file test_BioSQL.py.

Definition at line 134 of file test_BioSQL.py.

Definition at line 144 of file test_BioSQL.py.


The documentation for this class was generated from the following file: