Browse Source

Use the kwargs parameter to tune generation

Yann Weber 9 years ago
parent
commit
32975049d1
1 changed files with 11 additions and 4 deletions
  1. 11
    4
      EditorialModel/model.py

+ 11
- 4
EditorialModel/model.py View File

284
     # - rfields : Maximum number of relation_to_type attributes fields (default 5)
284
     # - rfields : Maximum number of relation_to_type attributes fields (default 5)
285
     # - optfield : Chances for a field to be optionnal (default 2)
285
     # - optfield : Chances for a field to be optionnal (default 2)
286
     # @param backend : A backend to use with the new EM
286
     # @param backend : A backend to use with the new EM
287
-    # @param **chances dict : Provide tunable generation parameter
287
+    # @param **kwargs dict : Provide tunable generation parameter
288
     # @return A randomly generate EM
288
     # @return A randomly generate EM
289
-    def random(cls, backend, **chances):
289
+    def random(cls, backend, **kwargs):
290
         em = Model(backend)
290
         em = Model(backend)
291
 
291
 
292
         chances = {
292
         chances = {
304
             'optfield': 2, #chances to be optionnal
304
             'optfield': 2, #chances to be optionnal
305
         }
305
         }
306
 
306
 
307
+        for name,value in kwargs.items():
308
+            if name not in chances:
309
+                #warning
310
+                pass
311
+            else:
312
+                chances[name] = value
313
+
307
         #classes creation
314
         #classes creation
308
         for classtype in EmClassType.getall():
315
         for classtype in EmClassType.getall():
309
             if random.randint(0,chances['classtype']) == 0:
316
             if random.randint(0,chances['classtype']) == 0:
404
     ## @brief returns randomly generated datas for an EmComponent
411
     ## @brief returns randomly generated datas for an EmComponent
405
     # @return a dict with name, string and help_text
412
     # @return a dict with name, string and help_text
406
     def _rnd_component_datas(cls):
413
     def _rnd_component_datas(cls):
407
-        mlstr_nlang = 5;
408
-        ret = {}
414
+        mlstr_nlang = 2;
415
+        ret = dict()
409
         ret['name'] = cls._rnd_str()
416
         ret['name'] = cls._rnd_str()
410
         ret['string'] = cls._rnd_mlstr(mlstr_nlang)
417
         ret['string'] = cls._rnd_mlstr(mlstr_nlang)
411
         ret['help_text'] = cls._rnd_mlstr(mlstr_nlang)
418
         ret['help_text'] = cls._rnd_mlstr(mlstr_nlang)

Loading…
Cancel
Save