Browse Source

test, fieldgroups: no use of subtest

ArnAud 9 years ago
parent
commit
96bfee8baa
1 changed files with 65 additions and 70 deletions
  1. 65
    70
      EditorialModel/test/test_fieldgroups.py

+ 65
- 70
EditorialModel/test/test_fieldgroups.py View File

57
     EmClass.create("entry2", EmClassType.entry)
57
     EmClass.create("entry2", EmClassType.entry)
58
     EmClass.create("person1", EmClassType.person)
58
     EmClass.create("person1", EmClassType.person)
59
     EmClass.create("person2", EmClassType.person)
59
     EmClass.create("person2", EmClassType.person)
60
-    
60
+
61
     saveDbState(TEST_FIELDGROUP_DBNAME)
61
     saveDbState(TEST_FIELDGROUP_DBNAME)
62
 
62
 
63
     #shutil.copyfile(TEST_FIELDGROUP_DBNAME, globals()['fieldgroup_test_dbfilename']+'_bck')
63
     #shutil.copyfile(TEST_FIELDGROUP_DBNAME, globals()['fieldgroup_test_dbfilename']+'_bck')
81
     def setUp(self):
81
     def setUp(self):
82
         super(TestInit, self).setUp()
82
         super(TestInit, self).setUp()
83
         conn = sqlutils.getEngine().connect()
83
         conn = sqlutils.getEngine().connect()
84
-        
84
+
85
         ent1 = EmClass('entity1')
85
         ent1 = EmClass('entity1')
86
         idx1 = EmClass('entry1')
86
         idx1 = EmClass('entry1')
87
 
87
 
101
 
101
 
102
     def test_init(self):
102
     def test_init(self):
103
         """ Test that EmFieldgroup are correctly instanciated compare to self.tfg """
103
         """ Test that EmFieldgroup are correctly instanciated compare to self.tfg """
104
-        with self.subTest("Call __init__ with name"):
105
-            for tfg in self.tfg:
106
-                fg = EmFieldGroup(tfg['name'])
107
-                for attr in tfg:
108
-                    if attr in ['string', 'help']:
109
-                        v = MlString.load(tfg[attr])
110
-                    else:
111
-                        v = tfg[attr]
112
-                    self.assertEqual(getattr(fg, attr), v, "The propertie '"+attr+"' fetched from Db don't match excepted value")
113
-
114
-        with self.subTest("Call __init__ with id"):
115
-            for tfg in self.tfg:
116
-                fg = EmFieldGroup(tfg['uid'])
117
-                for attr in tfg:
118
-                    if attr in ['string', 'help']:
119
-                        v = MlString.load(tfg[attr])
120
-                    else:
121
-                        v = tfg[attr]
122
-                    self.assertEqual(getattr(fg, attr), v, "The propertie '"+attr+"' fetched from Db don't match excepted value")
104
+        for tfg in self.tfg:
105
+            fg = EmFieldGroup(tfg['name'])
106
+            for attr in tfg:
107
+                if attr in ['string', 'help']:
108
+                    v = MlString.load(tfg[attr])
109
+                else:
110
+                    v = tfg[attr]
111
+                self.assertEqual(getattr(fg, attr), v, "The propertie '"+attr+"' fetched from Db don't match excepted value")
112
+
113
+        for tfg in self.tfg:
114
+            fg = EmFieldGroup(tfg['uid'])
115
+            for attr in tfg:
116
+                if attr in ['string', 'help']:
117
+                    v = MlString.load(tfg[attr])
118
+                else:
119
+                    v = tfg[attr]
120
+                self.assertEqual(getattr(fg, attr), v, "The propertie '"+attr+"' fetched from Db don't match excepted value")
123
 
121
 
124
         pass
122
         pass
125
 
123
 
142
 # EmFieldgroup.create #
140
 # EmFieldgroup.create #
143
 #=====================#
141
 #=====================#
144
 class TestCreate(FieldGroupTestCase):
142
 class TestCreate(FieldGroupTestCase):
145
-    
143
+
146
     def test_create(self):
144
     def test_create(self):
147
         """ Does create actually create a fieldgroup ? """
145
         """ Does create actually create a fieldgroup ? """
148
 
146
 
154
                 }
152
                 }
155
 
153
 
156
         for i,param_name in enumerate(params):
154
         for i,param_name in enumerate(params):
157
-            with self.subTest("Create from an "+param_name):
158
-                arg = params[param_name]
159
-                if isinstance(arg, EmClass):
160
-                    cl = arg
161
-                else:
162
-                    cl = EmClass(arg)
163
-
164
-                fgname = 'new_fg'+str(i)
165
-                fg = EmFieldGroup.create(fgname, arg)
166
-                self.assertEqual(fg.name, fgname, "EmFieldGroup.create() dont instanciate name correctly")
167
-                self.assertEqual(fg.class_id, cl.uid, "EmFieldGroup.create() dont instanciate class_id correctly")
168
-    
169
-                nfg = EmFieldGroup(fgname)
170
-
171
-                #Checking object property
172
-                for fname in fg._fields:
173
-                    self.assertEqual(getattr(nfg,fname), getattr(fg,fname), "Msg inconsistency when a created fieldgroup is fecthed from Db (in "+fname+" property)")
155
+            arg = params[param_name]
156
+            if isinstance(arg, EmClass):
157
+                cl = arg
158
+            else:
159
+                cl = EmClass(arg)
160
+
161
+            fgname = 'new_fg'+str(i)
162
+            fg = EmFieldGroup.create(fgname, arg)
163
+            self.assertEqual(fg.name, fgname, "EmFieldGroup.create() dont instanciate name correctly")
164
+            self.assertEqual(fg.class_id, cl.uid, "EmFieldGroup.create() dont instanciate class_id correctly")
165
+
166
+            nfg = EmFieldGroup(fgname)
167
+
168
+            #Checking object property
169
+            for fname in fg._fields:
170
+                self.assertEqual(getattr(nfg,fname), getattr(fg,fname), "Msg inconsistency when a created fieldgroup is fecthed from Db (in "+fname+" property)")
174
         pass
171
         pass
175
 
172
 
176
     def test_create_badargs(self):
173
     def test_create_badargs(self):
177
         """ Does create fails when badargs given ? """
174
         """ Does create fails when badargs given ? """
178
 
175
 
179
-        with self.subTest("With badarg as second argument"):
180
-            badargs = { 'EmClass type (not an instance)': EmClass,
181
-                        'Non Existing name': 'fooClassThatDontExist',
182
-                        'Non Existing Id': 4042, #Hope that it didnt exist ;)
183
-                        'Another component instance': EmType.create('fooType', EmClass('entity1')),
184
-                        'A function': print
185
-                    }
186
-            for i,badarg_name in enumerate(badargs):
187
-                with self.assertRaises(TypeError, msg="Should raise because trying to give "+badarg_name+" as em_class"):
188
-                    fg = EmFieldGroup.create('new_fg'+i, badargs[badarg_name])
189
-
190
-        with self.subTest("With badarg as first argument"):
191
-            #Creating a fieldgroup to test duplicate name
192
-            exfg = EmFieldGroup.create('existingfg', EmClass('entity1'))
193
-
194
-            badargs = { 'a duplicate name': ('existingfg', ValueError),
195
-                        'an integer': (42, TypeError),
196
-                        'a function': (print, TypeError),
197
-                        'an EmClass': (EmClass('entry1'), TypeError),
198
-                    }
199
-            for badarg_name in badargs:
200
-                (badarg,expt) = badargs[badarg_name]
201
-                with self.assertRaises(expt, msg="Should raise because trying to give "+badarg_name+" as first argument"):
202
-                    fg = EmFieldGroup.create(badarg, EmClass('entity1'))
176
+        badargs = { 'EmClass type (not an instance)': EmClass,
177
+                    'Non Existing name': 'fooClassThatDontExist',
178
+                    'Non Existing Id': 4042, #Hope that it didnt exist ;)
179
+                    'Another component instance': EmType.create('fooType', EmClass('entity1')),
180
+                    'A function': print
181
+                }
182
+        for i,badarg_name in enumerate(badargs):
183
+            with self.assertRaises(TypeError, msg="Should raise because trying to give "+badarg_name+" as em_class"):
184
+                fg = EmFieldGroup.create('new_fg'+i, badargs[badarg_name])
185
+
186
+        #Creating a fieldgroup to test duplicate name
187
+        exfg = EmFieldGroup.create('existingfg', EmClass('entity1'))
188
+
189
+        badargs = { 'a duplicate name': ('existingfg', ValueError),
190
+                    'an integer': (42, TypeError),
191
+                    'a function': (print, TypeError),
192
+                    'an EmClass': (EmClass('entry1'), TypeError),
193
+                }
194
+        for badarg_name in badargs:
195
+            (badarg,expt) = badargs[badarg_name]
196
+            with self.assertRaises(expt, msg="Should raise because trying to give "+badarg_name+" as first argument"):
197
+                fg = EmFieldGroup.create(badarg, EmClass('entity1'))
203
 
198
 
204
 #=====================#
199
 #=====================#
205
 # EmFieldgroup.fields #
200
 # EmFieldgroup.fields #
206
 #=====================#
201
 #=====================#
207
 class TestFields(FieldGroupTestCase):
202
 class TestFields(FieldGroupTestCase):
208
-    
203
+
209
     def setUp(self):
204
     def setUp(self):
210
         self.fg1 = EmFieldGroup.create('testfg', EmClass('entity1'))
205
         self.fg1 = EmFieldGroup.create('testfg', EmClass('entity1'))
211
         self.fg2 = EmFieldGroup.create('testfg2', EmClass('entry1'))
206
         self.fg2 = EmFieldGroup.create('testfg2', EmClass('entry1'))
217
 
212
 
218
         #Creating fields
213
         #Creating fields
219
         test_fields1 = [
214
         test_fields1 = [
220
-            { 'name': 'field1', 'em_fieldgroup': self.fg1, 'em_fieldtype': EmField_integer() },
221
-            { 'name': 'field2', 'em_fieldgroup': self.fg1, 'em_fieldtype': EmField_integer() },
222
-            { 'name': 'field4', 'em_fieldgroup': self.fg1, 'em_fieldtype': EmField_integer() },
215
+            { 'name': 'field1', 'fieldgroup': self.fg1, 'fieldtype': EmField_integer() },
216
+            { 'name': 'field2', 'fieldgroup': self.fg1, 'fieldtype': EmField_integer() },
217
+            { 'name': 'field4', 'fieldgroup': self.fg1, 'fieldtype': EmField_integer() },
223
         ]
218
         ]
224
 
219
 
225
         test_fields2 = [ 
220
         test_fields2 = [ 
226
-            { 'name': 'field3', 'em_fieldgroup': self.fg2, 'em_fieldtype': EmField_integer() },
221
+            { 'name': 'field3', 'fieldgroup': self.fg2, 'fieldtype': EmField_integer() },
227
         ]
222
         ]
228
-            
223
+
229
         excepted1 = []
224
         excepted1 = []
230
 
225
 
231
         for finfo in test_fields1:
226
         for finfo in test_fields1:
236
             f = EmField.create(**finfo)
231
             f = EmField.create(**finfo)
237
 
232
 
238
         excepted1 = set(excepted1)
233
         excepted1 = set(excepted1)
239
- 
234
+
240
         tests = {
235
         tests = {
241
             'newly': EmFieldGroup('testfg'),
236
             'newly': EmFieldGroup('testfg'),
242
             'old' : self.fg1
237
             'old' : self.fg1

Loading…
Cancel
Save