Browse Source

Added modify_rank test, done some refactoring and updated runtest utils script

runtest script has now comments inside showing usefull options to run tests
Yann Weber 10 years ago
parent
commit
9e27610b40
2 changed files with 233 additions and 124 deletions
  1. 185
    123
      EditorialModel/test/test_component.py
  2. 48
    1
      runtest

+ 185
- 123
EditorialModel/test/test_component.py View File

18
 from Database import sqlutils
18
 from Database import sqlutils
19
 import sqlalchemy as sqla
19
 import sqlalchemy as sqla
20
 
20
 
21
+
21
 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Lodel.settings")
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
 #A dummy EmComponent child class use to make tests
67
 #A dummy EmComponent child class use to make tests
24
 class EmTestComp(EmComponent):
68
 class EmTestComp(EmComponent):
25
     table = 'ttest'
69
     table = 'ttest'
70
+    ranked_in = 'rank_fam'
26
     def __init__(self, ion):
71
     def __init__(self, ion):
27
         super(EmTestComp, self).__init__(ion)
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
 class ComponentTestCase(TestCase):
83
 class ComponentTestCase(TestCase):
30
 
84
 
31
-    # ############# # 
32
-    #  TESTS SETUP  #
33
-    # ############# #
34
     @classmethod
85
     @classmethod
35
     def setUpClass(cls):
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
     @property
89
     @property
78
     def db(self):
90
     def db(self):
79
-        return self.__class__.db
91
+        return globals()['dbwrapper']
80
     @property
92
     @property
81
     def tables(self):
93
     def tables(self):
82
-        return self.__class__.tables
94
+        return globals()['tables']
83
 
95
 
84
     def setUp(self):
96
     def setUp(self):
85
         # Db RAZ
97
         # Db RAZ
113
         for i in range(len(self.test_values)):
125
         for i in range(len(self.test_values)):
114
             self.test_values[i]['date_create'] = datetime.datetime.utcnow()
126
             self.test_values[i]['date_create'] = datetime.datetime.utcnow()
115
             self.test_values[i]['date_update'] = datetime.datetime.utcnow()
127
             self.test_values[i]['date_update'] = datetime.datetime.utcnow()
128
+            self.test_values[i]['rank_fam'] = '1'
116
             
129
             
117
 
130
 
118
         req = test_table.insert(values=self.test_values)
131
         req = test_table.insert(values=self.test_values)
119
         conn.execute(req)
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
         conn.close()
146
         conn.close()
121
 
147
 
122
         footable = sqla.Table('em_class', sqlutils.meta(self.dber))
148
         footable = sqla.Table('em_class', sqlutils.meta(self.dber))
157
         for n in ms1t:
183
         for n in ms1t:
158
             self.assertEqual(ms1t[n], ms2t[n])
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
     #  TESTS BEGIN  #
191
     #  TESTS BEGIN  #
162
-    # ############# #
192
+    #=#############=#
163
 
193
 
164
-    #
165
-    #   EmComponent.newUid
166
-    #
194
+class TestUid(ComponentTestCase):
195
+
196
+    #=======================#
197
+    #   EmComponent.newUid  #
198
+    #=======================#
167
     def test_newuid(self):
199
     def test_newuid(self):
168
         """ Test valid calls for newUid method """
200
         """ Test valid calls for newUid method """
169
         for _ in range(10):
201
         for _ in range(10):
180
             self.assertEqual(res.uid, nuid)
212
             self.assertEqual(res.uid, nuid)
181
             self.assertEqual(res.table, EmTestComp.table)
213
             self.assertEqual(res.table, EmTestComp.table)
182
         pass
214
         pass
183
-
215
+    
184
     def test_newuid_abstract(self):
216
     def test_newuid_abstract(self):
185
         """ Test not valit call for newUid method """
217
         """ Test not valit call for newUid method """
186
         with self.assertRaises(NotImplementedError):
218
         with self.assertRaises(NotImplementedError):
187
             EmComponent.newUid()
219
             EmComponent.newUid()
188
         pass
220
         pass
189
-    #
190
-    #   EmComponent.__init__
191
-    #
221
+
222
+class TestInit(ComponentTestCase):
223
+
224
+    #===========================#
225
+    #   EmComponent.__init__    #
226
+    #===========================#
192
     def test_component_abstract_init(self):
227
     def test_component_abstract_init(self):
193
         """ Test not valid call (from EmComponent) of __init__ """
228
         """ Test not valid call (from EmComponent) of __init__ """
194
         with self.assertRaises(EnvironmentError):
229
         with self.assertRaises(EnvironmentError):
230
                 EmTestComp(badarg)
265
                 EmTestComp(badarg)
231
         pass
266
         pass
232
 
267
 
233
-    #
234
-    #   EmComponent.save
235
-    #
268
+class TestSave(ComponentTestCase):
269
+    #=======================#
270
+    #   EmComponent.save    #
271
+    #=======================#
236
 
272
 
237
     def _savecheck(self, test_comp, newval):
273
     def _savecheck(self, test_comp, newval):
238
         """ Utility function for test_component_save_namechange """
274
         """ Utility function for test_component_save_namechange """
270
         newval = val.copy()
306
         newval = val.copy()
271
 
307
 
272
         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']
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
         #name change
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
         #help change
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
         #string change
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
         #no change
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
         #change all
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
         pass
343
         pass
302
 
344
 
303
     @unittest.skip("Soon we will not use anymore the values argument of the savec method")
345
     @unittest.skip("Soon we will not use anymore the values argument of the savec method")
333
         changes = { 'date_create': datetime.datetime(1982,4,2,13,37), 'date_update': datetime.datetime(1982,4,2,22,43), 'rank': 42 }
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
         for prop in changes:
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
         pass
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
     def test_modify_rank_absolute(self):
421
     def test_modify_rank_absolute(self):
369
         """ Testing modify_rank with absolute rank """
422
         """ Testing modify_rank with absolute rank """
370
         
423
         
372
         nmax = len(names)-1
425
         nmax = len(names)-1
373
         
426
         
374
         #moving first to 3
427
         #moving first to 3
428
+        #-----------------
375
         test_comp = EmTestComp(names[0])
429
         test_comp = EmTestComp(names[0])
376
 
430
 
377
         test_comp.modify_rank(3, '=')
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
         for i in range(1,4):
436
         for i in range(1,4):
381
             test_comp = EmTestComp(names[i])
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
         for i in [4,nmax]:
440
         for i in [4,nmax]:
385
             test_comp = EmTestComp(names[i])
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
         #undoing last rank change
444
         #undoing last rank change
389
         test_comp = EmTestComp(names[0])
445
         test_comp = EmTestComp(names[0])
390
         test_comp.modify_rank(0,'=')
446
         test_comp.modify_rank(0,'=')
391
         self.assertEqual(test_comp.rank, 0)
447
         self.assertEqual(test_comp.rank, 0)
448
+        tc2 = EmTestComp(names[0])
449
+        self.assertEqual(tc2.rank, 0)
392
 
450
 
393
         #moving last to 2
451
         #moving last to 2
452
+        #----------------
394
         test_comp = EmTestComp(names[nmax])
453
         test_comp = EmTestComp(names[nmax])
395
 
454
 
396
         test_comp.modify_rank(2, '=')
455
         test_comp.modify_rank(2, '=')
398
         for i in [0,1]:
457
         for i in [0,1]:
399
             test_comp = EmTestComp(names[i])
458
             test_comp = EmTestComp(names[i])
400
             self.assertEqual(test_comp.rank, i)
459
             self.assertEqual(test_comp.rank, i)
401
-        for i in range(3,nmax+1):
460
+        for i in range(3,nmax-1):
402
             test_comp = EmTestComp(names[i])
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
         #undoing last rank change
464
         #undoing last rank change
406
         test_comp = EmTestComp(names[nmax])
465
         test_comp = EmTestComp(names[nmax])
410
         #Checking that we are in original state again
469
         #Checking that we are in original state again
411
         for i,name in enumerate(names):
470
         for i,name in enumerate(names):
412
             test_comp = EmTestComp(name)
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
         #Inverting the list
474
         #Inverting the list
475
+        #------------------
416
         for i,name in enumerate(names):
476
         for i,name in enumerate(names):
417
             test_comp = EmTestComp(name)
477
             test_comp = EmTestComp(name)
418
             test_comp.modify_rank(0,'=')
478
             test_comp.modify_rank(0,'=')
424
                 test_comp = EmTestComp(names[j])
484
                 test_comp = EmTestComp(names[j])
425
                 self.assertEqual(test_comp.rank, j)
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
         for i in range(nmax,-1,-1):
489
         for i in range(nmax,-1,-1):
429
-            test_comp = EmTestComp(name)
490
+            test_comp = EmTestComp(names[i])
430
             test_comp.modify_rank(nmax,'=')
491
             test_comp.modify_rank(nmax,'=')
431
             self.assertEqual(test_comp.rank, nmax)
492
             self.assertEqual(test_comp.rank, nmax)
432
             for j in range(i,nmax+1):
493
             for j in range(i,nmax+1):
433
                 test_comp = EmTestComp(names[j])
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
             for j in range(0,i):
496
             for j in range(0,i):
436
                 test_comp = EmTestComp(names[j])
497
                 test_comp = EmTestComp(names[j])
437
                 self.assertEqual(test_comp.rank, i-j-1)
498
                 self.assertEqual(test_comp.rank, i-j-1)
444
         nmax = len(names)-1
505
         nmax = len(names)-1
445
         
506
         
446
         test_comp = EmTestComp(names[0])
507
         test_comp = EmTestComp(names[0])
508
+        #Running modify_rank(i,'+') and the modify_rank(i,'-') for i in range(1,nmax)
447
         for i in range(1,nmax):
509
         for i in range(1,nmax):
448
             test_comp.modify_rank(i,'+')
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
             test_comp2 = EmTestComp(names[0])
512
             test_comp2 = EmTestComp(names[0])
451
             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)+"'")
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
             test_comp.modify_rank(i,'-')
522
             test_comp.modify_rank(i,'-')
461
             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)+"'")
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
             test_comp2 = EmTestComp(names[0])
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
             for j in range(1,nmax+1):
527
             for j in range(1,nmax+1):
466
                 test_comp2 = EmTestComp(names[j])
528
                 test_comp2 = EmTestComp(names[j])
467
                 self.assertEqual(test_comp2.rank, j)
529
                 self.assertEqual(test_comp2.rank, j)
468
 
530
 
469
         test_comp = EmTestComp(names[3])
531
         test_comp = EmTestComp(names[3])
470
-        test_comp.modify_rank('2','+')
532
+        test_comp.modify_rank(2,'+')
471
         self.assertEqual(test_comp.rank, 5)
533
         self.assertEqual(test_comp.rank, 5)
472
         tc2 = EmTestComp(names[3])
534
         tc2 = EmTestComp(names[3])
473
         self.assertEqual(tc2.rank,5)
535
         self.assertEqual(tc2.rank,5)
478
             tc2 = EmTestComp(names[i])
540
             tc2 = EmTestComp(names[i])
479
             self.assertEqual(tc2.rank, i)
541
             self.assertEqual(tc2.rank, i)
480
 
542
 
481
-        test_comp.modify_rank('2', '-')
543
+        test_comp.modify_rank(2, '-')
482
         self.assertEqual(test_comp.rank, 3)
544
         self.assertEqual(test_comp.rank, 3)
483
         for i in range(0,6):
545
         for i in range(0,6):
484
             tc2 = EmTestComp(names[i])
546
             tc2 = EmTestComp(names[i])
514
             ((1, 'Hello world !'), ValueError),
576
             ((1, 'Hello world !'), ValueError),
515
             
577
             
516
             #Out of bounds
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
             ((len(names), '+'), ValueError),
581
             ((len(names), '+'), ValueError),
520
             ((len(names), '-'), ValueError),
582
             ((len(names), '-'), ValueError),
521
             ((len(names), '='), ValueError),
583
             ((len(names), '='), ValueError),
524
         ]
586
         ]
525
 
587
 
526
         for (args, err) in badargs:
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
             self.assertEqual(tc.rank, 3, "The function raises an error but modify the rank")
591
             self.assertEqual(tc.rank, 3, "The function raises an error but modify the rank")
530
         pass
592
         pass
531
 
593
 

+ 48
- 1
runtest View File

1
 #!/bin/bash
1
 #!/bin/bash
2
+#
3
+# Usage : ./runtest [OPTIONS] [test_module[.test_class][ test_module2[.test_class2]...]
4
+#########
5
+#
6
+# Options list :
7
+################
8
+#
9
+# -b, --buffer
10
+#
11
+#    The standard output and standard error streams are buffered during the test run. Output during a passing test is discarded. Output is echoed normally on test fail or error and is added to the failure messages.
12
+#
13
+# -c, --catch
14
+#
15
+#    Control-C during the test run waits for the current test to end and then reports all the results so far. A second control-C raises the normal KeyboardInterrupt exception.
16
+#
17
+#
18
+# -f, --failfast
19
+#
20
+#    Stop the test run on the first error or failure.
21
+#
22
+# -h, --help
23
+#
24
+#    Get some help
25
+#
26
+# -v, --verbose
27
+#
28
+#   higher verbosity
29
+#
30
+# Examples :
31
+############
32
+#
33
+# Running all discoverables tests :
34
+# ./runtest
35
+#
36
+# Running only Em test about component object (only tests about the __init__ and modify_rank methods) with higher verbosity and failfast :
37
+# ./runtest -fv EditorialModel.test.test_component.TestInit EditorialModel.test.test_component.TestModifyRank
38
+#
39
+#
40
+# Running only Em tests
41
+# ./runtest discover EditorialModel
42
+#
43
+# More details :
44
+################
45
+#
46
+# https://docs.python.org/3.4/library/unittest.html
47
+#
48
+
2
 
49
 
3
 export DJANGO_SETTINGS_MODULE="Lodel.settings"
50
 export DJANGO_SETTINGS_MODULE="Lodel.settings"
4
 
51
 
5
-python -m unittest
52
+python -m unittest $@

Loading…
Cancel
Save