Mercurial > repos > yufei-luo > s_mart
view commons/tools/tests/Test_getCumulLengthFromTEannot.py @ 18:94ab73e8a190
Uploaded
author | m-zytnicki |
---|---|
date | Mon, 29 Apr 2013 03:20:15 -0400 |
parents | |
children |
line wrap: on
line source
import unittest import os import time from commons.core.sql.DbMySql import DbMySql from commons.tools.getCumulLengthFromTEannot import getCumulLengthFromTEannot from commons.core.utils.FileUtils import FileUtils class Test_getCumulLengthFromTEannot( unittest.TestCase ): def setUp( self ): self.fileUtils = FileUtils() self._getCumulLengthFromTEannot = None self._uniqId = "%s_%s" % ( time.strftime("%Y_%m_%d_%H_%M_%S") , os.getpid() ) self._configFileName = "dummyConfig_%s" % self._uniqId configFile = open( self._configFileName, "w" ) configFile.write("[repet_env]\n") configFile.write( "repet_host: %s\n" % ( os.environ["REPET_HOST"] ) ) configFile.write( "repet_user: %s\n" % ( os.environ["REPET_USER"] ) ) configFile.write( "repet_pw: %s\n" % ( os.environ["REPET_PW"] ) ) configFile.write( "repet_db: %s\n" % ( os.environ["REPET_DB"] ) ) configFile.write( "repet_port: %s\n" % ( os.environ["REPET_PORT"] ) ) configFile.close() def tearDown( self ): os.remove( self._configFileName ) def test_getAllSubjectsAsMapOfQueries( self ): inFileName = "dummyInFile_%s" % self._uniqId expFileName = "dummyExp_%s" % self._uniqId for f in [inFileName,expFileName]: if os.path.exists(f): os.remove(f) inFile = open( inFileName, "w" ) inFile.write( "1\tchr1\t1501\t2500\tTE1\t1\t500\t0.0\t880\t95.7\n" ) inFile.write( "2\tchr1\t3401\t4000\tTE3\t101\t700\t0.0\t950\t97.2\n" ) inFile.close() inTable = "dummyPathTable_%s" % self._uniqId db = DbMySql(cfgFileName=self._configFileName) db.createTable(inTable, "path", inFileName) expFile = open( expFileName, "w" ) expFile.write( "TE1\tchr1\t1501\t2500\n" ) expFile.write( "TE3\tchr1\t3401\t4000\n" ) expFile.close() self._getCumulLengthFromTEannot = getCumulLengthFromTEannot() self._getCumulLengthFromTEannot._tableName = inTable self._getCumulLengthFromTEannot._configFileName = self._configFileName self._getCumulLengthFromTEannot.setAdaptatorToTable() obsFileName = self._getCumulLengthFromTEannot.getAllSubjectsAsMapOfQueries() self.assertTrue( self.fileUtils.are2FilesIdentical( obsFileName, expFileName ) ) for f in [inFileName,inTable+".map",expFileName]: if os.path.exists(f): os.remove(f) db.dropTable(inTable) db.close() def test_getCumulLength( self ): mergeFileName = "dummyInFile_%s" % self._uniqId mergeFile = open( mergeFileName, "w" ) mergeFile.write( "TE1\tchr1\t1501\t2500\n" ) mergeFile.write( "TE3\tchr1\t4000\t3401\n" ) mergeFile.close() exp = 1000+600 self._getCumulLengthFromTEannot = getCumulLengthFromTEannot() obs = self._getCumulLengthFromTEannot.getCumulLength( mergeFileName ) self.assertEqual( obs, exp ) os.remove( mergeFileName ) if __name__ == "__main__": unittest.main()