|
@@ -18,68 +18,80 @@ from Database.sqlwrapper import SqlWrapper
|
18
|
18
|
from Database import sqlutils
|
19
|
19
|
import sqlalchemy as sqla
|
20
|
20
|
|
|
21
|
+
|
21
|
22
|
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Lodel.settings")
|
22
|
23
|
|
|
24
|
+#
|
|
25
|
+# TODO : test create
|
|
26
|
+#
|
|
27
|
+
|
|
28
|
+#=#############=#
|
|
29
|
+# TESTS SETUP #
|
|
30
|
+#=#############=#
|
|
31
|
+
|
|
32
|
+def setUpModule():
|
|
33
|
+ #Overwritting db confs to make tests
|
|
34
|
+ settings.LODEL2SQLWRAPPER = {
|
|
35
|
+ 'default': {
|
|
36
|
+ 'ENGINE': 'sqlite',
|
|
37
|
+ 'NAME': '/tmp/testdb.sqlite'
|
|
38
|
+ }
|
|
39
|
+ }
|
|
40
|
+
|
|
41
|
+ #Disable logging but CRITICAL
|
|
42
|
+ logging.basicConfig(level=logging.CRITICAL)
|
|
43
|
+
|
|
44
|
+ #testDB setup
|
|
45
|
+ # TODO May be slow
|
|
46
|
+ sqls = SQLSetup()
|
|
47
|
+ tables = sqls.get_schema()
|
|
48
|
+ ttest = { 'name':'ttest',
|
|
49
|
+ 'columns': [
|
|
50
|
+ {"name":"uid", "type":"INTEGER", "extra":{"foreignkey":"uids.uid", "nullable":False, "primarykey":True}},
|
|
51
|
+ {"name":"name", "type":"VARCHAR(50)", "extra":{"nullable":False, "unique":True}},
|
|
52
|
+ {"name":"string", "type":"TEXT"},
|
|
53
|
+ {"name":"help", "type":"TEXT"},
|
|
54
|
+ {"name":"rank", "type":"INTEGER"},
|
|
55
|
+ {"name":"rank_fam", "type":"VARCHAR(1)"},
|
|
56
|
+ {"name":"date_update", "type":"DATETIME"},
|
|
57
|
+ {"name":"date_create", "type":"DATETIME"}
|
|
58
|
+ ]
|
|
59
|
+ }
|
|
60
|
+ tables.append(ttest)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+ globals()['dbwrapper'] = SqlWrapper(read_db='default', write_db = 'default', alchemy_logs=False)
|
|
64
|
+ globals()['tables'] = tables
|
|
65
|
+
|
|
66
|
+
|
23
|
67
|
#A dummy EmComponent child class use to make tests
|
24
|
68
|
class EmTestComp(EmComponent):
|
25
|
69
|
table = 'ttest'
|
|
70
|
+ ranked_in = 'rank_fam'
|
26
|
71
|
def __init__(self, ion):
|
27
|
72
|
super(EmTestComp, self).__init__(ion)
|
28
|
73
|
|
|
74
|
+ def populate(self):
|
|
75
|
+ row = super(EmTestComp, self).populate()
|
|
76
|
+ self.rank_fam = row.rank_fam
|
|
77
|
+
|
|
78
|
+ def save(self):
|
|
79
|
+ values = { 'rank_fam': self.rank_fam }
|
|
80
|
+
|
|
81
|
+ return super(EmTestComp, self).save(values)
|
|
82
|
+
|
29
|
83
|
class ComponentTestCase(TestCase):
|
30
|
84
|
|
31
|
|
- # ############# #
|
32
|
|
- # TESTS SETUP #
|
33
|
|
- # ############# #
|
34
|
85
|
@classmethod
|
35
|
86
|
def setUpClass(cls):
|
36
|
|
- #Overwritting db confs to make tests
|
37
|
|
- settings.LODEL2SQLWRAPPER = {
|
38
|
|
- 'default': {
|
39
|
|
- 'ENGINE': 'sqlite',
|
40
|
|
- 'NAME': '/tmp/testdb.sqlite'
|
41
|
|
- }
|
42
|
|
- }
|
43
|
|
-
|
44
|
|
- """
|
45
|
|
- 'default': {
|
46
|
|
- 'ENGINE': 'mysql',
|
47
|
|
- 'NAME': 'lodel2crea',
|
48
|
|
- 'USER': 'lodel',
|
49
|
|
- 'PASSWORD': 'bruno',
|
50
|
|
- },
|
51
|
|
- """
|
52
|
|
- #Disable logging but CRITICAL
|
53
|
|
- logging.basicConfig(level=logging.CRITICAL)
|
54
|
|
-
|
55
|
|
- #testDB setup
|
56
|
|
- # TODO May be slow
|
57
|
|
- sqls = SQLSetup()
|
58
|
|
- tables = sqls.get_schema()
|
59
|
|
- ttest = { 'name':'ttest',
|
60
|
|
- 'columns': [
|
61
|
|
- {"name":"uid", "type":"INTEGER", "extra":{"foreignkey":"uids.uid", "nullable":False, "primarykey":True}},
|
62
|
|
- {"name":"name", "type":"VARCHAR(50)", "extra":{"nullable":False, "unique":True}},
|
63
|
|
- {"name":"string", "type":"TEXT"},
|
64
|
|
- {"name":"help", "type":"TEXT"},
|
65
|
|
- {"name":"rank", "type":"INTEGER"},
|
66
|
|
- {"name":"date_update", "type":"DATETIME"},
|
67
|
|
- {"name":"date_create", "type":"DATETIME"}
|
68
|
|
- ]
|
69
|
|
- }
|
70
|
|
- tables.append(ttest)
|
71
|
|
-
|
|
87
|
+ pass
|
72
|
88
|
|
73
|
|
- #cls.db = SqlWrapper(read_db='default', write_db = 'default', alchemy_logs=True)
|
74
|
|
- cls.db = SqlWrapper(read_db='default', write_db = 'default', alchemy_logs=False)
|
75
|
|
- cls.tables = tables
|
76
|
|
-
|
77
|
89
|
@property
|
78
|
90
|
def db(self):
|
79
|
|
- return self.__class__.db
|
|
91
|
+ return globals()['dbwrapper']
|
80
|
92
|
@property
|
81
|
93
|
def tables(self):
|
82
|
|
- return self.__class__.tables
|
|
94
|
+ return globals()['tables']
|
83
|
95
|
|
84
|
96
|
def setUp(self):
|
85
|
97
|
# Db RAZ
|
|
@@ -113,10 +125,24 @@ class ComponentTestCase(TestCase):
|
113
|
125
|
for i in range(len(self.test_values)):
|
114
|
126
|
self.test_values[i]['date_create'] = datetime.datetime.utcnow()
|
115
|
127
|
self.test_values[i]['date_update'] = datetime.datetime.utcnow()
|
|
128
|
+ self.test_values[i]['rank_fam'] = '1'
|
116
|
129
|
|
117
|
130
|
|
118
|
131
|
req = test_table.insert(values=self.test_values)
|
119
|
132
|
conn.execute(req)
|
|
133
|
+
|
|
134
|
+ """#This commented block allow to dump the test values at each setup
|
|
135
|
+ req = sqla.select([test_table])
|
|
136
|
+ res = conn.execute(req).fetchall()
|
|
137
|
+ print("\nDEBUG (dump inserted)")
|
|
138
|
+ for row in res:
|
|
139
|
+ strrow=""
|
|
140
|
+ for cname in row.keys():
|
|
141
|
+ strrow += "\t"+str(cname)+'\t: '+str(row[cname])+"\n"
|
|
142
|
+ print(strrow)
|
|
143
|
+ print("\n")
|
|
144
|
+ """
|
|
145
|
+
|
120
|
146
|
conn.close()
|
121
|
147
|
|
122
|
148
|
footable = sqla.Table('em_class', sqlutils.meta(self.dber))
|
|
@@ -157,13 +183,19 @@ class ComponentTestCase(TestCase):
|
157
|
183
|
for n in ms1t:
|
158
|
184
|
self.assertEqual(ms1t[n], ms2t[n])
|
159
|
185
|
|
160
|
|
- # ############# #
|
|
186
|
+ def run(self, result=None):
|
|
187
|
+
|
|
188
|
+ super(ComponentTestCase, self).run(result)
|
|
189
|
+
|
|
190
|
+ #=#############=#
|
161
|
191
|
# TESTS BEGIN #
|
162
|
|
- # ############# #
|
|
192
|
+ #=#############=#
|
163
|
193
|
|
164
|
|
- #
|
165
|
|
- # EmComponent.newUid
|
166
|
|
- #
|
|
194
|
+class TestUid(ComponentTestCase):
|
|
195
|
+
|
|
196
|
+ #=======================#
|
|
197
|
+ # EmComponent.newUid #
|
|
198
|
+ #=======================#
|
167
|
199
|
def test_newuid(self):
|
168
|
200
|
""" Test valid calls for newUid method """
|
169
|
201
|
for _ in range(10):
|
|
@@ -180,15 +212,18 @@ class ComponentTestCase(TestCase):
|
180
|
212
|
self.assertEqual(res.uid, nuid)
|
181
|
213
|
self.assertEqual(res.table, EmTestComp.table)
|
182
|
214
|
pass
|
183
|
|
-
|
|
215
|
+
|
184
|
216
|
def test_newuid_abstract(self):
|
185
|
217
|
""" Test not valit call for newUid method """
|
186
|
218
|
with self.assertRaises(NotImplementedError):
|
187
|
219
|
EmComponent.newUid()
|
188
|
220
|
pass
|
189
|
|
- #
|
190
|
|
- # EmComponent.__init__
|
191
|
|
- #
|
|
221
|
+
|
|
222
|
+class TestInit(ComponentTestCase):
|
|
223
|
+
|
|
224
|
+ #===========================#
|
|
225
|
+ # EmComponent.__init__ #
|
|
226
|
+ #===========================#
|
192
|
227
|
def test_component_abstract_init(self):
|
193
|
228
|
""" Test not valid call (from EmComponent) of __init__ """
|
194
|
229
|
with self.assertRaises(EnvironmentError):
|
|
@@ -230,9 +265,10 @@ class ComponentTestCase(TestCase):
|
230
|
265
|
EmTestComp(badarg)
|
231
|
266
|
pass
|
232
|
267
|
|
233
|
|
- #
|
234
|
|
- # EmComponent.save
|
235
|
|
- #
|
|
268
|
+class TestSave(ComponentTestCase):
|
|
269
|
+ #=======================#
|
|
270
|
+ # EmComponent.save #
|
|
271
|
+ #=======================#
|
236
|
272
|
|
237
|
273
|
def _savecheck(self, test_comp, newval):
|
238
|
274
|
""" Utility function for test_component_save_namechange """
|
|
@@ -270,34 +306,40 @@ class ComponentTestCase(TestCase):
|
270
|
306
|
newval = val.copy()
|
271
|
307
|
|
272
|
308
|
time.sleep(2) # We have to sleep 2 secs here, so the update_date will be at least 2 secs more than newval['date_update']
|
273
|
|
-
|
|
309
|
+
|
274
|
310
|
#name change
|
275
|
|
- newval['name'] = test_comp.name = 'newname'
|
276
|
|
- test_comp.save({})
|
277
|
|
- self._savecheck(test_comp, newval)
|
|
311
|
+ with self.subTest("Save after name change"):
|
|
312
|
+ newval['name'] = test_comp.name = 'newname'
|
|
313
|
+ test_comp.save()
|
|
314
|
+ self._savecheck(test_comp, newval)
|
278
|
315
|
|
279
|
316
|
#help change
|
280
|
|
- newval['help'] = '{"fr": "help fr", "en":"help en", "es":"help es"}'
|
281
|
|
- test_comp.help = MlString.load(newval['help'])
|
282
|
|
- test_comp.save()
|
283
|
|
- self._savecheck(test_comp, newval)
|
|
317
|
+ with self.subTest("Save after help change"):
|
|
318
|
+ newval['help'] = '{"fr": "help fr", "en":"help en", "es":"help es"}'
|
|
319
|
+ test_comp.help = MlString.load(newval['help'])
|
|
320
|
+ test_comp.save()
|
|
321
|
+ self._savecheck(test_comp, newval)
|
284
|
322
|
|
285
|
323
|
#string change
|
286
|
|
- newval['string'] = '{"fr": "string fr", "en":"string en", "es":"string es"}'
|
287
|
|
- test_comp.string = MlString.load(newval['string'])
|
288
|
|
- test_comp.save()
|
289
|
|
- self._savecheck(test_comp, newval)
|
|
324
|
+ with self.subTest("Save after string change"):
|
|
325
|
+ newval['string'] = '{"fr": "string fr", "en":"string en", "es":"string es"}'
|
|
326
|
+ test_comp.string = MlString.load(newval['string'])
|
|
327
|
+ test_comp.save()
|
|
328
|
+ self._savecheck(test_comp, newval)
|
290
|
329
|
|
291
|
330
|
#no change
|
292
|
|
- test_comp.save()
|
293
|
|
- self._savecheck(test_comp, newval)
|
|
331
|
+ with self.subTest("Save without any change"):
|
|
332
|
+ test_comp.save()
|
|
333
|
+ self._savecheck(test_comp, newval)
|
294
|
334
|
|
295
|
335
|
#change all
|
296
|
|
- newval['name'] = test_comp.name = 'newnewname'
|
297
|
|
- newval['help'] = '{"fr": "help fra", "en":"help eng", "es":"help esp"}'
|
298
|
|
- newval['string'] = '{"fr": "string FR", "en":"string EN", "es":"string ES", "foolang":"foofoobar"}'
|
299
|
|
- test_comp.save()
|
300
|
|
- self._savecheck(test_comp, newval)
|
|
336
|
+ with self.subTest("Save after name, help and string change"):
|
|
337
|
+ newval['name'] = test_comp.name = 'newnewname'
|
|
338
|
+ newval['help'] = '{"fr": "help fra", "en":"help eng", "es":"help esp"}'
|
|
339
|
+ newval['string'] = '{"fr": "string FR", "en":"string EN", "es":"string ES", "foolang":"foofoobar"}'
|
|
340
|
+ test_comp.save()
|
|
341
|
+ self._savecheck(test_comp, newval)
|
|
342
|
+
|
301
|
343
|
pass
|
302
|
344
|
|
303
|
345
|
@unittest.skip("Soon we will not use anymore the values argument of the savec method")
|
|
@@ -333,38 +375,49 @@ class ComponentTestCase(TestCase):
|
333
|
375
|
changes = { 'date_create': datetime.datetime(1982,4,2,13,37), 'date_update': datetime.datetime(1982,4,2,22,43), 'rank': 42 }
|
334
|
376
|
|
335
|
377
|
for prop in changes:
|
336
|
|
- test_comp = EmTestComp(val['name'])
|
337
|
|
- self.check_equals(val, test_comp)
|
338
|
|
-
|
339
|
|
- setattr(test_comp, prop, changes[prop])
|
340
|
|
- test_comp.save({})
|
341
|
|
-
|
342
|
|
- test_comp2 = EmTestComp(val['name'])
|
343
|
|
-
|
344
|
|
- if prop in ['date_create', 'date_update']:
|
345
|
|
- assertion = self.assertEqualDatetime
|
346
|
|
- else: #rank
|
347
|
|
- assertion = self.assertEqual
|
348
|
|
-
|
349
|
|
- assertion(getattr(test_comp,prop), val[prop], "When using setattr the "+prop+" of a component is set : ")
|
350
|
|
- assertion(getattr(test_comp2, prop), val[prop], "When using setattr and save the "+prop+" of a loaded component is set : ")
|
351
|
|
-
|
352
|
|
- # The code block commented bellow uses the values argument of the save method.
|
353
|
|
- # soon this argument will not being used anymore
|
354
|
|
- """
|
355
|
|
- test_comp = EmTestComp(val['name'])
|
356
|
|
- self.check_equals(val, test_comp)
|
357
|
|
- test_comp.save({ prop: changes['prop'] })
|
358
|
|
-
|
359
|
|
- test_comp2 = EmTestComp(val['name'])
|
360
|
|
- self.assertEqualDatetime(test_comp.date_create, val[prop], "The "+prop+" of the component instance has been changed")
|
361
|
|
- self.assertEqualDatetime(test_comp2.date_create, val[prop], "When loaded the "+prop+" has been changed")
|
362
|
|
- """
|
|
378
|
+ with self.subTest("Illega change of "+prop):
|
|
379
|
+ test_comp = EmTestComp(val['name'])
|
|
380
|
+ self.check_equals(val, test_comp)
|
|
381
|
+
|
|
382
|
+ setattr(test_comp, prop, changes[prop])
|
|
383
|
+ test_comp.save()
|
|
384
|
+
|
|
385
|
+ test_comp2 = EmTestComp(val['name'])
|
|
386
|
+
|
|
387
|
+ if prop in ['date_create', 'date_update']:
|
|
388
|
+ assertion = self.assertEqualDatetime
|
|
389
|
+ else: #rank
|
|
390
|
+ assertion = self.assertEqual
|
|
391
|
+
|
|
392
|
+ assertion(getattr(test_comp,prop), val[prop], "When using setattr the "+prop+" of a component is set : ")
|
|
393
|
+ assertion(getattr(test_comp2, prop), val[prop], "When using setattr and save the "+prop+" of a loaded component is set : ")
|
|
394
|
+
|
|
395
|
+ # The code block commented bellow uses the values argument of the save method.
|
|
396
|
+ # soon this argument will not being used anymore
|
|
397
|
+ """
|
|
398
|
+ test_comp = EmTestComp(val['name'])
|
|
399
|
+ self.check_equals(val, test_comp)
|
|
400
|
+ test_comp.save({ prop: changes['prop'] })
|
|
401
|
+
|
|
402
|
+ test_comp2 = EmTestComp(val['name'])
|
|
403
|
+ self.assertEqualDatetime(test_comp.date_create, val[prop], "The "+prop+" of the component instance has been changed")
|
|
404
|
+ self.assertEqualDatetime(test_comp2.date_create, val[prop], "When loaded the "+prop+" has been changed")
|
|
405
|
+ """
|
363
|
406
|
pass
|
364
|
407
|
|
365
|
|
- #
|
366
|
|
- # EmComponent.modify_rank
|
367
|
|
- #
|
|
408
|
+class TestModifyRank(ComponentTestCase):
|
|
409
|
+ #===========================#
|
|
410
|
+ # EmComponent.modify_rank #
|
|
411
|
+ #===========================#
|
|
412
|
+
|
|
413
|
+ def dump_ranks(self):
|
|
414
|
+ names = [ v['name'] for v in self.test_values ]
|
|
415
|
+ ranks=""
|
|
416
|
+ for i in range(len(names)):
|
|
417
|
+ tc = EmTestComp(names[i])
|
|
418
|
+ ranks += " "+str(tc.rank)
|
|
419
|
+ return ranks
|
|
420
|
+
|
368
|
421
|
def test_modify_rank_absolute(self):
|
369
|
422
|
""" Testing modify_rank with absolute rank """
|
370
|
423
|
|
|
@@ -372,25 +425,31 @@ class ComponentTestCase(TestCase):
|
372
|
425
|
nmax = len(names)-1
|
373
|
426
|
|
374
|
427
|
#moving first to 3
|
|
428
|
+ #-----------------
|
375
|
429
|
test_comp = EmTestComp(names[0])
|
376
|
430
|
|
377
|
431
|
test_comp.modify_rank(3, '=')
|
378
|
|
- self.assertEqual(test_comp.rank, 3)
|
|
432
|
+ self.assertEqual(test_comp.rank, 3, "Called modify_rank(3, '=') but rank is '"+str(test_comp.rank)+"'. Ranks dump : "+self.dump_ranks())
|
|
433
|
+ tc2 = EmTestComp(names[0])
|
|
434
|
+ self.assertEqual(tc2.rank, 3, "Called modify_rank(3, '=') but rank is '"+str(tc2.rank)+"'. Ranks dump : "+self.dump_ranks())
|
379
|
435
|
|
380
|
436
|
for i in range(1,4):
|
381
|
437
|
test_comp = EmTestComp(names[i])
|
382
|
|
- self.assertEqual(test_comp.rank, i-1, "Excepted rank was '"+str(i-1)+"' but found '"+str(test_comp.rank)+"'")
|
|
438
|
+ self.assertEqual(test_comp.rank, i-1, "Excepted rank was '"+str(i-1)+"' but found '"+str(test_comp.rank)+"'. Ranks dump : "+self.dump_ranks())
|
383
|
439
|
|
384
|
440
|
for i in [4,nmax]:
|
385
|
441
|
test_comp = EmTestComp(names[i])
|
386
|
|
- self.assertEqual(test_comp.rank, i, "Rank wasn't excepted to change, but : previous value was '"+str(i)+"' current value is '"+str(test_comp.rank)+"'")
|
|
442
|
+ self.assertEqual(test_comp.rank, i, "Rank wasn't excepted to change, but : previous value was '"+str(i)+"' current value is '"+str(test_comp.rank)+"'. Ranks dump : "+self.dump_ranks())
|
387
|
443
|
|
388
|
444
|
#undoing last rank change
|
389
|
445
|
test_comp = EmTestComp(names[0])
|
390
|
446
|
test_comp.modify_rank(0,'=')
|
391
|
447
|
self.assertEqual(test_comp.rank, 0)
|
|
448
|
+ tc2 = EmTestComp(names[0])
|
|
449
|
+ self.assertEqual(tc2.rank, 0)
|
392
|
450
|
|
393
|
451
|
#moving last to 2
|
|
452
|
+ #----------------
|
394
|
453
|
test_comp = EmTestComp(names[nmax])
|
395
|
454
|
|
396
|
455
|
test_comp.modify_rank(2, '=')
|
|
@@ -398,9 +457,9 @@ class ComponentTestCase(TestCase):
|
398
|
457
|
for i in [0,1]:
|
399
|
458
|
test_comp = EmTestComp(names[i])
|
400
|
459
|
self.assertEqual(test_comp.rank, i)
|
401
|
|
- for i in range(3,nmax+1):
|
|
460
|
+ for i in range(3,nmax-1):
|
402
|
461
|
test_comp = EmTestComp(names[i])
|
403
|
|
- self.assertEqual(testc_omp.rank, i+1)
|
|
462
|
+ self.assertEqual(test_comp.rank, i+1, "Excepted rank was '"+str(i+1)+"' but found '"+str(test_comp.rank)+"'. Ranks dump : "+self.dump_ranks())
|
404
|
463
|
|
405
|
464
|
#undoing last rank change
|
406
|
465
|
test_comp = EmTestComp(names[nmax])
|
|
@@ -410,9 +469,10 @@ class ComponentTestCase(TestCase):
|
410
|
469
|
#Checking that we are in original state again
|
411
|
470
|
for i,name in enumerate(names):
|
412
|
471
|
test_comp = EmTestComp(name)
|
413
|
|
- self.assertEqual(test_comp.rank, i, "Excepted rank was '"+str(i-1)+"' but found '"+str(test_comp.rank)+"'")
|
|
472
|
+ self.assertEqual(test_comp.rank, i, "Excepted rank was '"+str(i-1)+"' but found '"+str(test_comp.rank)+"'. Ranks dump : "+self.dump_ranks())
|
414
|
473
|
|
415
|
474
|
#Inverting the list
|
|
475
|
+ #------------------
|
416
|
476
|
for i,name in enumerate(names):
|
417
|
477
|
test_comp = EmTestComp(name)
|
418
|
478
|
test_comp.modify_rank(0,'=')
|
|
@@ -424,14 +484,15 @@ class ComponentTestCase(TestCase):
|
424
|
484
|
test_comp = EmTestComp(names[j])
|
425
|
485
|
self.assertEqual(test_comp.rank, j)
|
426
|
486
|
|
427
|
|
- #Not inverting the list
|
|
487
|
+ #Not inverting the list (makes swap but at the end we are in reverse state again)
|
|
488
|
+ #--------------------------------------------------------------------------------
|
428
|
489
|
for i in range(nmax,-1,-1):
|
429
|
|
- test_comp = EmTestComp(name)
|
|
490
|
+ test_comp = EmTestComp(names[i])
|
430
|
491
|
test_comp.modify_rank(nmax,'=')
|
431
|
492
|
self.assertEqual(test_comp.rank, nmax)
|
432
|
493
|
for j in range(i,nmax+1):
|
433
|
494
|
test_comp = EmTestComp(names[j])
|
434
|
|
- self.assertEqual(test_comp.rank, nmax-(j-i))
|
|
495
|
+ self.assertEqual(test_comp.rank, nmax-(j-i), "Excepted rank was '"+str(nmax-(j-i))+"' but got '"+str(test_comp.rank)+"'). Ranks dump : "+self.dump_ranks())
|
435
|
496
|
for j in range(0,i):
|
436
|
497
|
test_comp = EmTestComp(names[j])
|
437
|
498
|
self.assertEqual(test_comp.rank, i-j-1)
|
|
@@ -444,9 +505,10 @@ class ComponentTestCase(TestCase):
|
444
|
505
|
nmax = len(names)-1
|
445
|
506
|
|
446
|
507
|
test_comp = EmTestComp(names[0])
|
|
508
|
+ #Running modify_rank(i,'+') and the modify_rank(i,'-') for i in range(1,nmax)
|
447
|
509
|
for i in range(1,nmax):
|
448
|
510
|
test_comp.modify_rank(i,'+')
|
449
|
|
- self.assertEqual(test_comp.rank, i, "The instance on wich we applied the modify_rank doesn't have expected rank : expected '"+str(i)+"' but got '"+str(test_comp.rank)+"'")
|
|
511
|
+ self.assertEqual(test_comp.rank, i, "The instance (name="+names[0]+") on wich we applied the modify_rank doesn't have expected rank : expected '"+str(i)+"' but got '"+str(test_comp.rank)+"'")
|
450
|
512
|
test_comp2 = EmTestComp(names[0])
|
451
|
513
|
self.assertEqual(test_comp.rank, i, "The instance fetched in Db does'n't have expected rank : expected '"+str(i)+"' but got '"+str(test_comp.rank)+"'")
|
452
|
514
|
|
|
@@ -460,14 +522,14 @@ class ComponentTestCase(TestCase):
|
460
|
522
|
test_comp.modify_rank(i,'-')
|
461
|
523
|
self.assertEqual(test_comp.rank, 0, "The instance on wich we applied the modify_rank -"+str(i)+" doesn't have excepted rank : excepted '0' but got '"+str(test_comp.rank)+"'")
|
462
|
524
|
test_comp2 = EmTestComp(names[0])
|
463
|
|
- self.assertEqual(test_comp.rank, i, "The instance fetched in Db does'n't have expected rank : expected '0' but got '"+str(test_comp.rank)+"'")
|
|
525
|
+ self.assertEqual(test_comp.rank, 0, "The instance fetched in Db does'n't have expected rank : expected '0' but got '"+str(test_comp.rank)+"'"+self.dump_ranks())
|
464
|
526
|
|
465
|
527
|
for j in range(1,nmax+1):
|
466
|
528
|
test_comp2 = EmTestComp(names[j])
|
467
|
529
|
self.assertEqual(test_comp2.rank, j)
|
468
|
530
|
|
469
|
531
|
test_comp = EmTestComp(names[3])
|
470
|
|
- test_comp.modify_rank('2','+')
|
|
532
|
+ test_comp.modify_rank(2,'+')
|
471
|
533
|
self.assertEqual(test_comp.rank, 5)
|
472
|
534
|
tc2 = EmTestComp(names[3])
|
473
|
535
|
self.assertEqual(tc2.rank,5)
|
|
@@ -478,7 +540,7 @@ class ComponentTestCase(TestCase):
|
478
|
540
|
tc2 = EmTestComp(names[i])
|
479
|
541
|
self.assertEqual(tc2.rank, i)
|
480
|
542
|
|
481
|
|
- test_comp.modify_rank('2', '-')
|
|
543
|
+ test_comp.modify_rank(2, '-')
|
482
|
544
|
self.assertEqual(test_comp.rank, 3)
|
483
|
545
|
for i in range(0,6):
|
484
|
546
|
tc2 = EmTestComp(names[i])
|
|
@@ -514,8 +576,8 @@ class ComponentTestCase(TestCase):
|
514
|
576
|
((1, 'Hello world !'), ValueError),
|
515
|
577
|
|
516
|
578
|
#Out of bounds
|
517
|
|
- ((42*10**9), '+', ValueError),
|
518
|
|
- ((-42*10**9), '+', ValueError),
|
|
579
|
+ ((42*10**9, '+'), ValueError),
|
|
580
|
+ ((-42*10**9, '+'), ValueError),
|
519
|
581
|
((len(names), '+'), ValueError),
|
520
|
582
|
((len(names), '-'), ValueError),
|
521
|
583
|
((len(names), '='), ValueError),
|
|
@@ -524,8 +586,8 @@ class ComponentTestCase(TestCase):
|
524
|
586
|
]
|
525
|
587
|
|
526
|
588
|
for (args, err) in badargs:
|
527
|
|
- with self.assertRaises(TypeError, "Bad arguments supplied : "+str(args)+" but no error raised"):
|
528
|
|
- test_comp.modify_rank(*args)
|
|
589
|
+ with self.assertRaises(err, msg="Bad arguments supplied : "+str(args)+" for a component at rank 3 but no error raised"):
|
|
590
|
+ tc.modify_rank(*args)
|
529
|
591
|
self.assertEqual(tc.rank, 3, "The function raises an error but modify the rank")
|
530
|
592
|
pass
|
531
|
593
|
|