18
|
1 from commons.core.sql.DbMySql import DbMySql
|
|
2 from commons.core.sql.TablePathAdaptator import TablePathAdaptator
|
|
3 from commons.core.coord.PathUtils import PathUtils
|
|
4 from commons.core.utils.FileUtils import FileUtils
|
|
5 import os
|
|
6 import unittest
|
|
7
|
|
8 class Test_F_RetrieveInitHeaders(unittest.TestCase):
|
|
9
|
|
10 def setUp(self):
|
|
11 self._iDb = DbMySql()
|
|
12
|
|
13 def tearDown(self):
|
|
14 self._iDb.close()
|
|
15
|
|
16 def test_run_as_script_rename_subject_and_clean_table(self):
|
|
17 shortHLinkFileName = "dummy.shortHlink"
|
|
18 self._writeShortHLinkFile(shortHLinkFileName)
|
|
19 pathTableName = "dummyInput_path"
|
|
20 self._createPathTable(pathTableName)
|
|
21 expFileName = "exp.path"
|
|
22 self._writeExpFile(expFileName)
|
|
23 obsTableName = "dummyOutput_path"
|
|
24
|
|
25 cmd = "RetrieveInitHeaders.py -i %s -l %s -o %s -s -c -v 1" % (pathTableName, shortHLinkFileName, obsTableName)
|
|
26 os.system(cmd)
|
|
27
|
|
28 self.assertTrue(self._iDb.doesTableExist(obsTableName))
|
|
29 self.assertFalse(self._iDb.doesTableExist(pathTableName))
|
|
30 obsFileName = "obs.path"
|
|
31 iTPA = TablePathAdaptator(self._iDb, obsTableName)
|
|
32 lPaths = iTPA.getListOfAllPaths()
|
|
33 PathUtils.writeListInFile(lPaths, obsFileName)
|
|
34 self.assertTrue(FileUtils.are2FilesIdentical(expFileName, obsFileName))
|
|
35
|
|
36 os.remove(shortHLinkFileName)
|
|
37 os.remove(expFileName)
|
|
38 os.remove(obsFileName)
|
|
39 self._iDb.dropTable(obsTableName)
|
|
40
|
|
41 def _writeShortHLinkFile(self, fileName):
|
|
42 f = open(fileName, "w")
|
|
43 f.write("refTE_1\tPaphi_v2-B-R11932-Map16_classI-LTR-comp\t1\t5388\n")
|
|
44 f.write("refTE_2\tPaphi_v2-B-R2469-Map20_classI-LTR-comp\t1\t6385\n")
|
|
45 f.write("refTE_3\tPaphi_v2-B-R8543-Map9_classI-LTR-comp\t1\t7148\n")
|
|
46 f.write("refTE_4\tPaphi_v2-B-R33384-Map4_classI-LTR-incomp\t1\t262\n")
|
|
47 f.write("refTE_5\tPaphi_v2-B-P73.1298-Map3_classI-LTR-incomp\t1\t389\n")
|
|
48 f.write("refTE_6\tPaphi_v2-B-R36143-Map3_classI-LTR-incomp\t1\t393\n")
|
|
49 f.write("refTE_7\tPaphi_v2-B-R35261-Map5_classI-LTR-incomp\t1\t408\n")
|
|
50 f.write("refTE_8\tPaphi_v2-B-R12434-Map4_classI-LTR-incomp\t1\t420\n")
|
|
51 f.write("refTE_9\tPaphi_v2-B-R20580-Map4_classI-LTR-incomp\t1\t426\n")
|
|
52 f.write("refTE_10\tPaphi_v2-B-R5129-Map3_classI-LTR-incomp\t1\t441\n")
|
|
53 f.close()
|
|
54
|
|
55 def _createPathTable(self, tableName):
|
|
56 fileName = "dummy.path"
|
|
57 f = open(fileName, "w")
|
|
58 f.write("7615\tchunk0030\t188432\t188611\trefTE_1\t5386\t5208\t0\t174\t97.23\n")
|
|
59 f.write("86375\tchunk0372\t155816\t157157\trefTE_1\t2213\t3575\t0\t843\t62.89\n")
|
|
60 f.write("88018\tchunk0381\t52141\t53500\trefTE_1\t2191\t3575\t0\t860\t63.3\n")
|
|
61 f.write("110377\tchunk0473\t117281\t117518\trefTE_1\t3966\t3716\t0\t230\t97.05\n")
|
|
62 f.write("39621\tchunk0169\t123563\t124003\trefTE_10\t1\t441\t0\t439\t99.55\n")
|
|
63 f.write("544710\tchunk2778\t62387\t62625\trefTE_10\t100\t327\t0\t165\t69.09\n")
|
|
64 f.write("601761\tchunk4780\t441\t559\trefTE_10\t5\t123\t0\t119\t100\n")
|
|
65 f.write("17589\tchunk0071\t58591\t59763\trefTE_2\t5139\t6384\t0\t1150\t98.12\n")
|
|
66 f.write("21050\tchunk0087\t186576\t186812\trefTE_2\t3636\t3891\t0\t232\t98.31\n")
|
|
67 f.close()
|
|
68 self._iDb.createTable(tableName, "path", fileName, True)
|
|
69 os.remove(fileName)
|
|
70
|
|
71 def _writeExpFile(self, fileName):
|
|
72 f = open(fileName, "w")
|
|
73 f.write("7615\tchunk0030\t188432\t188611\tPaphi_v2-B-R11932-Map16_classI-LTR-comp\t5386\t5208\t0\t174\t97.230000\n")
|
|
74 f.write("86375\tchunk0372\t155816\t157157\tPaphi_v2-B-R11932-Map16_classI-LTR-comp\t2213\t3575\t0\t843\t62.890000\n")
|
|
75 f.write("88018\tchunk0381\t52141\t53500\tPaphi_v2-B-R11932-Map16_classI-LTR-comp\t2191\t3575\t0\t860\t63.300000\n")
|
|
76 f.write("110377\tchunk0473\t117281\t117518\tPaphi_v2-B-R11932-Map16_classI-LTR-comp\t3966\t3716\t0\t230\t97.050000\n")
|
|
77 f.write("39621\tchunk0169\t123563\t124003\tPaphi_v2-B-R5129-Map3_classI-LTR-incomp\t1\t441\t0\t439\t99.550000\n")
|
|
78 f.write("544710\tchunk2778\t62387\t62625\tPaphi_v2-B-R5129-Map3_classI-LTR-incomp\t100\t327\t0\t165\t69.090000\n")
|
|
79 f.write("601761\tchunk4780\t441\t559\tPaphi_v2-B-R5129-Map3_classI-LTR-incomp\t5\t123\t0\t119\t100.000000\n")
|
|
80 f.write("17589\tchunk0071\t58591\t59763\tPaphi_v2-B-R2469-Map20_classI-LTR-comp\t5139\t6384\t0\t1150\t98.120000\n")
|
|
81 f.write("21050\tchunk0087\t186576\t186812\tPaphi_v2-B-R2469-Map20_classI-LTR-comp\t3636\t3891\t0\t232\t98.310000\n")
|
|
82 f.close()
|
|
83
|
|
84 if __name__ == "__main__":
|
|
85 unittest.main() |