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,9 +284,9 @@ class Model(object):
284 284
     # - rfields : Maximum number of relation_to_type attributes fields (default 5)
285 285
     # - optfield : Chances for a field to be optionnal (default 2)
286 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 288
     # @return A randomly generate EM
289
-    def random(cls, backend, **chances):
289
+    def random(cls, backend, **kwargs):
290 290
         em = Model(backend)
291 291
 
292 292
         chances = {
@@ -304,6 +304,13 @@ class Model(object):
304 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 314
         #classes creation
308 315
         for classtype in EmClassType.getall():
309 316
             if random.randint(0,chances['classtype']) == 0:
@@ -404,8 +411,8 @@ class Model(object):
404 411
     ## @brief returns randomly generated datas for an EmComponent
405 412
     # @return a dict with name, string and help_text
406 413
     def _rnd_component_datas(cls):
407
-        mlstr_nlang = 5;
408
-        ret = {}
414
+        mlstr_nlang = 2;
415
+        ret = dict()
409 416
         ret['name'] = cls._rnd_str()
410 417
         ret['string'] = cls._rnd_mlstr(mlstr_nlang)
411 418
         ret['help_text'] = cls._rnd_mlstr(mlstr_nlang)

Loading…
Cancel
Save