Mercurial > repos > yufei-luo > s_mart
comparison commons/pyRepetUnit/profilesDB/tests/TestInsertProfilesMapFileInDB.py @ 18:94ab73e8a190
Uploaded
author | m-zytnicki |
---|---|
date | Mon, 29 Apr 2013 03:20:15 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
17:b0e8584489e6 | 18:94ab73e8a190 |
---|---|
1 import unittest | |
2 import time | |
3 import os | |
4 from commons.core.sql.TableMapAdaptator import TableMapAdaptator | |
5 from commons.core.coord.Map import Map | |
6 #from commons.pyRepetUnit.profilesDB.tests.InsertProfilesMapFileInDBTestRessources import InsertProfilesMapFileInDBTestRessources | |
7 from commons.pyRepetUnit.profilesDB.InsertProfilesMapFileInDB import InsertProfilesMapFileInDB | |
8 from commons.core.sql.DbMySql import DbMySql | |
9 | |
10 | |
11 class TestInsertProfilesMapFileInDB(unittest.TestCase): | |
12 | |
13 def setUp(self): | |
14 self._inputFileName = "./datas/profiles.map" | |
15 self._createProfilesMapFile() | |
16 # self._host = InsertProfilesMapFileInDBTestRessources.REPET_DB_HOST | |
17 # self._user = InsertProfilesMapFileInDBTestRessources.REPET_DB_USER | |
18 # self._passwd = InsertProfilesMapFileInDBTestRessources.REPET_DB_PW | |
19 # self._dbname = InsertProfilesMapFileInDBTestRessources.REPET_DB_NAME | |
20 # self._db = DbMySql( self._user, self._host, self._passwd, self._dbname ) | |
21 self._db = DbMySql( os.environ["REPET_USER"], | |
22 os.environ["REPET_HOST"], | |
23 os.environ["REPET_PW"], | |
24 os.environ["REPET_DB"] ) | |
25 self._uniqId = "%s_%s" % ( time.strftime("%Y%m%d%H%M%S") , os.getpid() ) | |
26 self._table = "dummyMapTable_%s" % ( self._uniqId ) | |
27 | |
28 def tearDown(self): | |
29 os.remove(self._inputFileName) | |
30 self._deleteDBtables() | |
31 self._db.close() | |
32 | |
33 def testInsertProfilesMapFileInDB(self): | |
34 resultFromFileMapUtils = self._readMapResultsFromFileAndFillList() | |
35 InsertProfilesMapFileInDBinstance = InsertProfilesMapFileInDB(self._inputFileName, self._table, self._db) | |
36 InsertProfilesMapFileInDBinstance.createAndLoadTable() | |
37 resultFromTableMapUtils = self._readMapResultsFromTableAndFillList() | |
38 self.assertEquals(resultFromFileMapUtils, resultFromTableMapUtils) | |
39 | |
40 def _createProfilesMapFile(self): | |
41 f = open(self._inputFileName, "w") | |
42 f.write("rrm\t\t1\t77\n") | |
43 f.write("fn3\tFibronectin type III domain\t1\t84\n") | |
44 f.write("pkinase\tProtein kinase domain\t1\t294\n") | |
45 f.close() | |
46 | |
47 def _readMapResultsFromTableAndFillList(self): | |
48 tableMapAdaptatorInstance = TableMapAdaptator (self._db, self._table) | |
49 return tableMapAdaptatorInstance.getListOfAllMaps() | |
50 | |
51 def _readMapResultsFromFileAndFillList(self): | |
52 mapInstance = Map() | |
53 lMap = [] | |
54 f = open( self._inputFileName , "r") | |
55 while mapInstance.read( f ): | |
56 lMap.append (mapInstance) | |
57 mapInstance = Map() | |
58 f.close() | |
59 return lMap | |
60 | |
61 def _deleteDBtables(self): | |
62 self._db.dropTable(self._table) | |
63 | |
64 if __name__ == "__main__": | |
65 unittest.main() |