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,7 +57,7 @@ def setUpModule():
57 57
     EmClass.create("entry2", EmClassType.entry)
58 58
     EmClass.create("person1", EmClassType.person)
59 59
     EmClass.create("person2", EmClassType.person)
60
-    
60
+
61 61
     saveDbState(TEST_FIELDGROUP_DBNAME)
62 62
 
63 63
     #shutil.copyfile(TEST_FIELDGROUP_DBNAME, globals()['fieldgroup_test_dbfilename']+'_bck')
@@ -81,7 +81,7 @@ class TestInit(FieldGroupTestCase):
81 81
     def setUp(self):
82 82
         super(TestInit, self).setUp()
83 83
         conn = sqlutils.getEngine().connect()
84
-        
84
+
85 85
         ent1 = EmClass('entity1')
86 86
         idx1 = EmClass('entry1')
87 87
 
@@ -101,25 +101,23 @@ class TestInit(FieldGroupTestCase):
101 101
 
102 102
     def test_init(self):
103 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 122
         pass
125 123
 
@@ -142,7 +140,7 @@ class TestInit(FieldGroupTestCase):
142 140
 # EmFieldgroup.create #
143 141
 #=====================#
144 142
 class TestCreate(FieldGroupTestCase):
145
-    
143
+
146 144
     def test_create(self):
147 145
         """ Does create actually create a fieldgroup ? """
148 146
 
@@ -154,58 +152,55 @@ class TestCreate(FieldGroupTestCase):
154 152
                 }
155 153
 
156 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 171
         pass
175 172
 
176 173
     def test_create_badargs(self):
177 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 200
 # EmFieldgroup.fields #
206 201
 #=====================#
207 202
 class TestFields(FieldGroupTestCase):
208
-    
203
+
209 204
     def setUp(self):
210 205
         self.fg1 = EmFieldGroup.create('testfg', EmClass('entity1'))
211 206
         self.fg2 = EmFieldGroup.create('testfg2', EmClass('entry1'))
@@ -217,15 +212,15 @@ class TestFields(FieldGroupTestCase):
217 212
 
218 213
         #Creating fields
219 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 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 224
         excepted1 = []
230 225
 
231 226
         for finfo in test_fields1:
@@ -236,7 +231,7 @@ class TestFields(FieldGroupTestCase):
236 231
             f = EmField.create(**finfo)
237 232
 
238 233
         excepted1 = set(excepted1)
239
- 
234
+
240 235
         tests = {
241 236
             'newly': EmFieldGroup('testfg'),
242 237
             'old' : self.fg1

Loading…
Cancel
Save