6
|
1 # Copyright INRA (Institut National de la Recherche Agronomique)
|
|
2 # http://www.inra.fr
|
|
3 # http://urgi.versailles.inra.fr
|
|
4 #
|
|
5 # This software is governed by the CeCILL license under French law and
|
|
6 # abiding by the rules of distribution of free software. You can use,
|
|
7 # modify and/ or redistribute the software under the terms of the CeCILL
|
|
8 # license as circulated by CEA, CNRS and INRIA at the following URL
|
|
9 # "http://www.cecill.info".
|
|
10 #
|
|
11 # As a counterpart to the access to the source code and rights to copy,
|
|
12 # modify and redistribute granted by the license, users are provided only
|
|
13 # with a limited warranty and the software's author, the holder of the
|
|
14 # economic rights, and the successive licensors have only limited
|
|
15 # liability.
|
|
16 #
|
|
17 # In this respect, the user's attention is drawn to the risks associated
|
|
18 # with loading, using, modifying and/or developing or reproducing the
|
|
19 # software by the user in light of its specific status of free software,
|
|
20 # that may mean that it is complicated to manipulate, and that also
|
|
21 # therefore means that it is reserved for developers and experienced
|
|
22 # professionals having in-depth computer knowledge. Users are therefore
|
|
23 # encouraged to load and test the software's suitability as regards their
|
|
24 # requirements in conditions enabling the security of their systems and/or
|
|
25 # data to be ensured and, more generally, to use and operate it in the
|
|
26 # same conditions as regards security.
|
|
27 #
|
|
28 # The fact that you are presently reading this means that you have had
|
|
29 # knowledge of the CeCILL license and that you accept its terms.
|
|
30
|
|
31
|
|
32 import unittest
|
|
33 import time
|
|
34 import os
|
|
35 from commons.core.sql.DbMySql import DbMySql
|
|
36 from commons.core.coord.Match import Match
|
|
37 from commons.core.sql.TableMatchAdaptator import TableMatchAdaptator
|
|
38
|
|
39
|
|
40 class Test_TableMatchAdaptator( unittest.TestCase ):
|
|
41
|
|
42 def setUp( self ):
|
|
43 self._uniqId = "%s_%s" % (time.strftime("%Y%m%d%H%M%S") , os.getpid())
|
|
44 self._configFileName = "dummyConfigFile_%s" % self._uniqId
|
|
45 self._iDb = DbMySql()
|
|
46 self._table = "dummyMatchTable_%s" % self._uniqId
|
|
47 self._tMatchA = TableMatchAdaptator( self._iDb, self._table )
|
|
48
|
|
49 def tearDown( self ):
|
|
50 self._uniqId = None
|
|
51 self._iDb.dropTable( self._table )
|
|
52 self._iDb.close()
|
|
53 self._table = None
|
|
54 self._tMatchA = None
|
|
55
|
|
56 ##################################################################################
|
|
57 ################## Tests for methods in ITableMatchAdaptator #####################
|
|
58 ##################################################################################
|
|
59 def test_insert(self):
|
|
60 match = Match()
|
|
61
|
|
62 tuple = ("QName1", 1, 5, 5, 0.1, 0.2, "SName1", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1)
|
|
63
|
|
64 match.setFromTuple(tuple)
|
|
65
|
|
66 self._iDb.createTable( self._table, "match", "" )
|
|
67 self._tMatchA.insert( match, False )
|
|
68
|
|
69 expTMatchTuple = (('QName1', 1L, 5L, 5L, 0.1, 0.2, 'SName1', 5L, 25L, 20L, 0.15, 1e-20, 15L, 87.2, 1L),)
|
|
70
|
|
71 sqlCmd = "SELECT * FROM %s" % ( self._table )
|
|
72 self._iDb.execute( sqlCmd )
|
|
73 obsTmatchTuple = self._iDb.cursor.fetchall()
|
|
74
|
|
75 self.assertEquals( expTMatchTuple, obsTmatchTuple )
|
|
76
|
|
77
|
|
78 def test_insert_empty_match(self):
|
|
79 match = Match()
|
|
80
|
|
81 tuple = ("", -1, -1, 5, 0.1, 0.2, "SName1", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1)
|
|
82
|
|
83 match.setFromTuple(tuple)
|
|
84
|
|
85 self._iDb.createTable( self._table, "match", "" )
|
|
86 self._tMatchA.insert( match, False )
|
|
87
|
|
88 expTMatchTuple = ()
|
|
89
|
|
90 sqlCmd = "SELECT * FROM %s" % ( self._table )
|
|
91 self._iDb.execute( sqlCmd )
|
|
92 obsTmatchTuple = self._iDb.cursor.fetchall()
|
|
93
|
|
94 self.assertEquals( expTMatchTuple, obsTmatchTuple )
|
|
95
|
|
96
|
|
97 def test_insertList(self):
|
|
98 match1 = Match()
|
|
99 match2 = Match()
|
|
100
|
|
101 tuple1 = ("QName1", 1, 5, 5, 0.1, 0.2, "SName1", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1)
|
|
102 tuple2 = ("QName2", 2, 5, 5, 0.1, 0.2, "SName2", 6, 25, 20, 0.15, 1e-20, 15, 87.2, 2)
|
|
103
|
|
104 match1.setFromTuple(tuple1)
|
|
105 match2.setFromTuple(tuple2)
|
|
106
|
|
107 self._iDb.createTable( self._table, "match", "" )
|
|
108 self._tMatchA.insertList( [ match1, match2 ], False )
|
|
109
|
|
110 expTMatchTuple = (('QName1', 1L, 5L, 5L, 0.1, 0.2, 'SName1', 5L, 25L, 20L, 0.15, 1e-20, 15L, 87.2, 1L),\
|
|
111 ('QName2', 2L, 5L, 5L, 0.1, 0.2, 'SName2', 6L, 25L, 20L, 0.15, 1e-20, 15L, 87.2, 2L))
|
|
112
|
|
113 sqlCmd = "SELECT * FROM %s" % ( self._table )
|
|
114 self._iDb.execute( sqlCmd )
|
|
115 obsTmatchTuple = self._iDb.cursor.fetchall()
|
|
116
|
|
117 self.assertEquals( expTMatchTuple, obsTmatchTuple )
|
|
118
|
|
119
|
|
120 def test_getMatchListFromQuery(self):
|
|
121 self._iDb.createTable( self._table, "match", "" )
|
|
122 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1)
|
|
123 tuple2 = ("QName", 1, 6, 6, 0.2, 0.1, "SName", 6, 26, 10, 0.18, 1e-30, 18, 85.2, 2)
|
|
124 tuple3 = ("QName", 1, 7, 8, 0.1, 0.2, "SName", 5, 20, 15, 0.20, 1e-25, 20, 89.0, 3)
|
|
125 tuple4 = ("QName", 1, 8, 8, 0.1, 0.1, "SName", 5, 15, 10, 0.17, 1e-23, 14, 89.5, 4)
|
|
126 match1 = Match()
|
|
127 match1.setFromTuple( tuple1 )
|
|
128 match2 = Match()
|
|
129 match2.setFromTuple( tuple2 )
|
|
130 match3 = Match()
|
|
131 match3.setFromTuple( tuple3 )
|
|
132 match4 = Match()
|
|
133 match4.setFromTuple( tuple4 )
|
|
134 expListMatch = [ match1, match2, match3, match4 ]
|
|
135 self._tMatchA.insertList(expListMatch)
|
|
136
|
|
137 obsListMatch = self._tMatchA.getMatchListFromQuery("QName")
|
|
138
|
|
139 self.assertEquals(expListMatch, obsListMatch)
|
|
140
|
|
141
|
|
142 def test_getMatchListFromQuery_unexisted_seq_name(self):
|
|
143 self._iDb.createTable( self._table, "match", "" )
|
|
144 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1)
|
|
145 tuple2 = ("QName", 1, 6, 6, 0.2, 0.1, "SName", 6, 26, 10, 0.18, 1e-30, 18, 85.2, 2)
|
|
146 tuple3 = ("QName", 1, 7, 8, 0.1, 0.2, "SName", 5, 20, 15, 0.20, 1e-25, 20, 89.0, 3)
|
|
147 tuple4 = ("QName", 1, 8, 8, 0.1, 0.1, "SName", 5, 15, 10, 0.17, 1e-23, 14, 89.5, 4)
|
|
148 match1 = Match()
|
|
149 match1.setFromTuple( tuple1 )
|
|
150 match2 = Match()
|
|
151 match2.setFromTuple( tuple2 )
|
|
152 match3 = Match()
|
|
153 match3.setFromTuple( tuple3 )
|
|
154 match4 = Match()
|
|
155 match4.setFromTuple( tuple4 )
|
|
156 lMatch = [ match1, match2, match3, match4 ]
|
|
157 self._tMatchA.insertList(lMatch)
|
|
158
|
|
159 expListMatch = []
|
|
160 obsListMatch = self._tMatchA.getMatchListFromQuery("Dummy")
|
|
161
|
|
162 self.assertEquals(expListMatch, obsListMatch)
|
|
163
|
|
164
|
|
165 def test_getMatchListFromId(self):
|
|
166 self._iDb.createTable( self._table, "match", "" )
|
|
167 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1)
|
|
168 tuple2 = ("QName", 1, 6, 6, 0.2, 0.1, "SName", 6, 26, 10, 0.18, 1e-30, 18, 85.2, 2)
|
|
169 tuple3 = ("QName", 1, 7, 8, 0.1, 0.2, "SName", 5, 20, 15, 0.20, 1e-25, 20, 89.0, 3)
|
|
170 tuple4 = ("QName", 1, 8, 8, 0.1, 0.1, "SName", 5, 15, 10, 0.17, 1e-23, 14, 89.5, 4)
|
|
171 match1 = Match()
|
|
172 match1.setFromTuple( tuple1 )
|
|
173 match2 = Match()
|
|
174 match2.setFromTuple( tuple2 )
|
|
175 match3 = Match()
|
|
176 match3.setFromTuple( tuple3 )
|
|
177 match4 = Match()
|
|
178 match4.setFromTuple( tuple4 )
|
|
179 lMatch = [ match1, match2, match3, match4 ]
|
|
180 expListMatch = [ match1 ]
|
|
181 self._tMatchA.insertList(lMatch)
|
|
182
|
|
183 obsListMatch = self._tMatchA.getMatchListFromId(1)
|
|
184
|
|
185 self.assertEquals(expListMatch, obsListMatch)
|
|
186
|
|
187
|
|
188 def test_getMatchListFromIdList_empty_id_list( self ):
|
|
189 self._iDb.createTable( self._table, "match", "" )
|
|
190 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1)
|
|
191 tuple2 = ("QName", 1, 6, 6, 0.2, 0.1, "SName", 6, 26, 10, 0.18, 1e-30, 18, 85.2, 2)
|
|
192 tuple3 = ("QName", 1, 7, 8, 0.1, 0.2, "SName", 5, 20, 15, 0.20, 1e-25, 20, 89.0, 3)
|
|
193 tuple4 = ("QName", 1, 8, 8, 0.1, 0.1, "SName", 5, 15, 10, 0.17, 1e-23, 14, 89.5, 4)
|
|
194 match1 = Match()
|
|
195 match1.setFromTuple( tuple1 )
|
|
196 match2 = Match()
|
|
197 match2.setFromTuple( tuple2 )
|
|
198 match3 = Match()
|
|
199 match3.setFromTuple( tuple3 )
|
|
200 match4 = Match()
|
|
201 match4.setFromTuple( tuple4 )
|
|
202 lMatch = [ match1, match2, match3, match4 ]
|
|
203 self._tMatchA.insertList(lMatch)
|
|
204
|
|
205 expList = []
|
|
206 obsList = self._tMatchA.getMatchListFromIdList([])
|
|
207 self.assertEquals(expList, obsList)
|
|
208
|
|
209
|
|
210 def test_getMatchListFromIdList( self ):
|
|
211 self._iDb.createTable( self._table, "match", "" )
|
|
212 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1)
|
|
213 tuple2 = ("QName", 1, 6, 6, 0.2, 0.1, "SName", 6, 26, 10, 0.18, 1e-30, 18, 85.2, 2)
|
|
214 tuple3 = ("QName", 1, 7, 8, 0.1, 0.2, "SName", 5, 20, 15, 0.20, 1e-25, 20, 89.0, 3)
|
|
215 tuple4 = ("QName", 1, 8, 8, 0.1, 0.1, "SName", 5, 15, 10, 0.17, 1e-23, 14, 89.5, 4)
|
|
216 match1 = Match()
|
|
217 match1.setFromTuple( tuple1 )
|
|
218 match2 = Match()
|
|
219 match2.setFromTuple( tuple2 )
|
|
220 match3 = Match()
|
|
221 match3.setFromTuple( tuple3 )
|
|
222 match4 = Match()
|
|
223 match4.setFromTuple( tuple4 )
|
|
224 lMatch = [ match1, match2, match3, match4 ]
|
|
225 self._tMatchA.insertList(lMatch)
|
|
226
|
|
227 lObs = self._tMatchA.getMatchListFromIdList((1, 2, 3))
|
|
228
|
|
229 lExp = [match1, match2, match3]
|
|
230 self.assertEquals(lExp, lObs)
|
|
231
|
|
232 def test_getListOfAllMatches( self ):
|
|
233 self._iDb.createTable( self._table, "match", "" )
|
|
234 tuple1 = ("QName", 1, 5, 5, 0.1, 0.2, "SName", 5, 25, 20, 0.15, 1e-20, 15, 87.2, 1)
|
|
235 tuple2 = ("QName", 1, 6, 6, 0.2, 0.1, "SName", 6, 26, 10, 0.18, 1e-30, 18, 85.2, 2)
|
|
236 tuple3 = ("QName", 1, 7, 8, 0.1, 0.2, "SName", 5, 20, 15, 0.20, 1e-25, 20, 89.0, 3)
|
|
237 tuple4 = ("QName", 1, 8, 8, 0.1, 0.1, "SName", 5, 15, 10, 0.17, 1e-23, 14, 89.5, 4)
|
|
238 match1 = Match()
|
|
239 match1.setFromTuple( tuple1 )
|
|
240 match2 = Match()
|
|
241 match2.setFromTuple( tuple2 )
|
|
242 match3 = Match()
|
|
243 match3.setFromTuple( tuple3 )
|
|
244 match4 = Match()
|
|
245 match4.setFromTuple( tuple4 )
|
|
246 lMatch = [ match1, match2, match3, match4 ]
|
|
247 expList = [ match1, match2, match3, match4 ]
|
|
248 self._tMatchA.insertList(lMatch)
|
|
249
|
|
250 obsList = self._tMatchA.getListOfAllMatches()
|
|
251 self.assertEqual( expList, obsList )
|
|
252
|
|
253
|
|
254 def test_getListOfAllMatches_empty_table( self ):
|
|
255 self._iDb.createTable( self._table, "match", "" )
|
|
256 expList = []
|
|
257 obsList = self._tMatchA.getListOfAllMatches()
|
|
258 self.assertEqual( expList, obsList )
|
|
259
|
|
260
|
|
261 test_suite = unittest.TestSuite()
|
|
262 test_suite.addTest( unittest.makeSuite( Test_TableMatchAdaptator ) )
|
|
263 if __name__ == "__main__":
|
|
264 unittest.TextTestRunner(verbosity=2).run( test_suite )
|