From 1f3c59737a597f2ea92678d31b0dadc7b553d9ff Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Fri, 4 Nov 2022 19:42:16 +0100 Subject: [PATCH] support of number value in yaml --- doc/param/simple.md | 2 +- doc/variable/choice.md | 8 ++++---- src/rougail/data/rougail.yml | 12 ++++++++++++ tests/dictionaries/01fill_number/yml/00-base.yml | 2 +- tests/dictionaries/10check_base/yml/00-base.yml | 4 ++-- .../10check_base_target_optional/yml/00-base.yml | 4 ++-- tests/dictionaries/10check_option/yml/00-base.yml | 4 ++-- .../yml/00-base.yml | 10 +++++----- .../dictionaries/10valid_enum_number/yml/00-base.yml | 8 ++++---- .../10valid_enum_numberdefault/yml/00-base.yml | 8 ++++---- .../11valid_enum_function/yml/00-base.yml | 6 +++--- tests/dictionaries/40empty_param/yml/00_base.yml | 2 +- tests/dictionaries/40empty_param2/yml/00_base.yml | 2 +- tests/dictionaries/40space_param/yml/00_base.yml | 2 +- .../yml/extra_dirs/extra/00-base.yml | 4 ++-- .../60familyaction/yml/extra_dirs/extra/00-base.yml | 2 +- .../yml/extra_dirs/extra/00-base.yml | 2 +- tests/dictionaries/80check_self/yml/00-base.yml | 2 +- tests/dictionaries/80check_unknown/yml/00-base.yml | 4 ++-- .../80check_without_target/yml/00-base.yml | 4 ++-- .../80empty_param_number/yml/00_base.yml | 2 +- .../80empty_typeeole_eole/yml/00_base.yml | 4 ++-- .../80empty_typeeole_number/yml/00_base.yml | 4 ++-- .../80family_dynamic_check/yml/00-base.yml | 4 ++-- .../yml/extra_dirs/extra/00-base.yml | 2 +- .../80frozenifin_unknown/yml/00-base.yml | 10 +++++----- .../80valid_entier_invalid_param/yml/00-base.yml | 2 +- .../80valid_entier_not_number/yml/00-base.yml | 4 ++-- .../88valid_enum_invalid_default/yml/00-base.yml | 6 +++--- tests/test_1_flattener.py | 9 ++++++++- tests/test_others.py | 3 ++- 31 files changed, 81 insertions(+), 61 deletions(-) diff --git a/doc/param/simple.md b/doc/param/simple.md index e682df373..44d118736 100644 --- a/doc/param/simple.md +++ b/doc/param/simple.md @@ -29,7 +29,7 @@ En YAML : ```yml param: - type: number - text: '1' + text: 1 ``` Créons la fonction correspondante : diff --git a/doc/variable/choice.md b/doc/variable/choice.md index 69148b016..534b5effa 100644 --- a/doc/variable/choice.md +++ b/doc/variable/choice.md @@ -77,7 +77,7 @@ En YAML : - type: string text: val2 - type: number - text: '3' + text: 3 - type: boolean text: true - type: 'nil' @@ -177,10 +177,10 @@ En YAML : name: range param: - type: number - text: '0' + text: 0 - type: number - text: '10' + text: 10 value: - type: number - text: '9' + text: 9 ``` diff --git a/src/rougail/data/rougail.yml b/src/rougail/data/rougail.yml index e97c1ed91..ae93c8a64 100644 --- a/src/rougail/data/rougail.yml +++ b/src/rougail/data/rougail.yml @@ -147,6 +147,7 @@ mapping: mapping: text: required: false + type: any param: required: false type: seq @@ -287,6 +288,7 @@ mapping: mapping: text: required: false + type: any param: required: false type: seq @@ -428,6 +430,7 @@ mapping: mapping: text: required: false + type: any param: required: false type: seq @@ -569,6 +572,7 @@ mapping: mapping: text: required: false + type: any param: required: false type: seq @@ -710,6 +714,7 @@ mapping: mapping: text: required: false + type: any param: required: false type: seq @@ -909,6 +914,7 @@ mapping: mapping: text: required: false + type: any param: required: false type: seq @@ -1049,6 +1055,7 @@ mapping: mapping: text: required: false + type: any param: required: false type: seq @@ -1206,6 +1213,7 @@ mapping: mapping: text: required: false + type: any param: required: false type: seq @@ -1346,6 +1354,7 @@ mapping: mapping: text: required: false + type: any param: required: false type: seq @@ -1503,6 +1512,7 @@ mapping: mapping: text: required: false + type: any param: required: false type: seq @@ -1643,6 +1653,7 @@ mapping: mapping: text: required: false + type: any param: required: false type: seq @@ -1800,6 +1811,7 @@ mapping: mapping: text: required: false + type: any param: required: false type: seq diff --git a/tests/dictionaries/01fill_number/yml/00-base.yml b/tests/dictionaries/01fill_number/yml/00-base.yml index eccaee564..0510f69f3 100644 --- a/tests/dictionaries/01fill_number/yml/00-base.yml +++ b/tests/dictionaries/01fill_number/yml/00-base.yml @@ -19,6 +19,6 @@ constraints: - name: calc_val param: - type: number - text: '3' + text: 3 target: - text: mode_conteneur_actif diff --git a/tests/dictionaries/10check_base/yml/00-base.yml b/tests/dictionaries/10check_base/yml/00-base.yml index ed73d2656..312f29ab3 100644 --- a/tests/dictionaries/10check_base/yml/00-base.yml +++ b/tests/dictionaries/10check_base/yml/00-base.yml @@ -19,9 +19,9 @@ constraints: param: - name: mini type: number - text: '0' + text: 0 - name: maxi type: number - text: '100' + text: 100 target: - text: int diff --git a/tests/dictionaries/10check_base_target_optional/yml/00-base.yml b/tests/dictionaries/10check_base_target_optional/yml/00-base.yml index 651d8191f..46e0bf922 100644 --- a/tests/dictionaries/10check_base_target_optional/yml/00-base.yml +++ b/tests/dictionaries/10check_base_target_optional/yml/00-base.yml @@ -8,10 +8,10 @@ constraints: param: - name: mini type: number - text: '0' + text: 0 - name: maxi type: number - text: '100' + text: 100 target: - optional: true text: int diff --git a/tests/dictionaries/10check_option/yml/00-base.yml b/tests/dictionaries/10check_option/yml/00-base.yml index 3c00d9e94..5ad3d45b9 100644 --- a/tests/dictionaries/10check_option/yml/00-base.yml +++ b/tests/dictionaries/10check_option/yml/00-base.yml @@ -14,7 +14,7 @@ variables: type: number description: No change value: - - text: '100' + - text: 100 - variable: name: int type: number @@ -25,7 +25,7 @@ constraints: param: - name: mini type: number - text: '0' + text: 0 - name: maxi type: variable text: int2 diff --git a/tests/dictionaries/10frozenifin_unknown_valid_enum_number/yml/00-base.yml b/tests/dictionaries/10frozenifin_unknown_valid_enum_number/yml/00-base.yml index 05a9c3762..17f624bfb 100644 --- a/tests/dictionaries/10frozenifin_unknown_valid_enum_number/yml/00-base.yml +++ b/tests/dictionaries/10frozenifin_unknown_valid_enum_number/yml/00-base.yml @@ -21,14 +21,14 @@ variables: help: bla bla bla choice: - type: number - text: '1' + text: 1 - type: number - text: '2' + text: 2 - type: number - text: '3' + text: 3 value: - type: number - text: '1' + text: 1 - variable: name: test_variable type: number @@ -38,7 +38,7 @@ constraints: - name: hidden_if_in source: enumvar param: - - text: '4' + - text: 4 target: - type: variable text: test_variable diff --git a/tests/dictionaries/10valid_enum_number/yml/00-base.yml b/tests/dictionaries/10valid_enum_number/yml/00-base.yml index 00470fad0..18d19ef84 100644 --- a/tests/dictionaries/10valid_enum_number/yml/00-base.yml +++ b/tests/dictionaries/10valid_enum_number/yml/00-base.yml @@ -21,11 +21,11 @@ variables: help: bla bla bla choice: - type: number - text: '1' + text: 1 - type: number - text: '2' + text: 2 - type: number - text: '3' + text: 3 value: - type: number - text: '1' + text: 1 diff --git a/tests/dictionaries/10valid_enum_numberdefault/yml/00-base.yml b/tests/dictionaries/10valid_enum_numberdefault/yml/00-base.yml index 25d9a5a90..d36c20e54 100644 --- a/tests/dictionaries/10valid_enum_numberdefault/yml/00-base.yml +++ b/tests/dictionaries/10valid_enum_numberdefault/yml/00-base.yml @@ -21,11 +21,11 @@ variables: help: bla bla bla value: - type: number - text: '3' + text: 3 choice: - type: number - text: '1' + text: 1 - type: number - text: '2' + text: 2 - type: number - text: '3' + text: 3 diff --git a/tests/dictionaries/11valid_enum_function/yml/00-base.yml b/tests/dictionaries/11valid_enum_function/yml/00-base.yml index 6c2e17353..e857d81d7 100644 --- a/tests/dictionaries/11valid_enum_function/yml/00-base.yml +++ b/tests/dictionaries/11valid_enum_function/yml/00-base.yml @@ -9,12 +9,12 @@ variables: description: New variable value: - type: number - text: '9' + text: 9 choice: - type: function name: trange param: - type: number - text: '0' + text: 0 - type: number - text: '10' + text: 10 diff --git a/tests/dictionaries/40empty_param/yml/00_base.yml b/tests/dictionaries/40empty_param/yml/00_base.yml index 4fabafb79..07b741470 100644 --- a/tests/dictionaries/40empty_param/yml/00_base.yml +++ b/tests/dictionaries/40empty_param/yml/00_base.yml @@ -15,7 +15,7 @@ variables: description: "Port d'\xE9coute du proxy NTLM" mode: expert value: - - text: '3127' + - text: 3127 constraints: - fill: - name: calc_multi_condition diff --git a/tests/dictionaries/40empty_param2/yml/00_base.yml b/tests/dictionaries/40empty_param2/yml/00_base.yml index 8f0a6cafd..b3771ddc2 100644 --- a/tests/dictionaries/40empty_param2/yml/00_base.yml +++ b/tests/dictionaries/40empty_param2/yml/00_base.yml @@ -15,7 +15,7 @@ variables: description: "Port d'\xE9coute du proxy NTLM" mode: expert value: - - text: '3127' + - text: 3127 constraints: - fill: - name: calc_multi_condition diff --git a/tests/dictionaries/40space_param/yml/00_base.yml b/tests/dictionaries/40space_param/yml/00_base.yml index a15e4720b..667d51215 100644 --- a/tests/dictionaries/40space_param/yml/00_base.yml +++ b/tests/dictionaries/40space_param/yml/00_base.yml @@ -15,7 +15,7 @@ variables: description: "Port d'\xE9coute du proxy NTLM" mode: expert value: - - text: '3127' + - text: 3127 constraints: - fill: - name: calc_multi_condition diff --git a/tests/dictionaries/60action_external/yml/extra_dirs/extra/00-base.yml b/tests/dictionaries/60action_external/yml/extra_dirs/extra/00-base.yml index 4d33907db..782aaa93f 100644 --- a/tests/dictionaries/60action_external/yml/extra_dirs/extra/00-base.yml +++ b/tests/dictionaries/60action_external/yml/extra_dirs/extra/00-base.yml @@ -8,14 +8,14 @@ variables: type: number description: "d\xE9lai en minutes avant lancement" value: - - text: '0' + - text: 0 - variable: name: calc_url type: web_address description: domain hidden: true value: - - text: '0' + - text: 0 constraints: - fill: - name: calc_val diff --git a/tests/dictionaries/60familyaction/yml/extra_dirs/extra/00-base.yml b/tests/dictionaries/60familyaction/yml/extra_dirs/extra/00-base.yml index 0cc90f3c6..8b854298f 100644 --- a/tests/dictionaries/60familyaction/yml/extra_dirs/extra/00-base.yml +++ b/tests/dictionaries/60familyaction/yml/extra_dirs/extra/00-base.yml @@ -8,4 +8,4 @@ variables: type: number description: "d\xE9lai en minutes avant lancement" value: - - text: '0' + - text: 0 diff --git a/tests/dictionaries/60familyaction_mandatory/yml/extra_dirs/extra/00-base.yml b/tests/dictionaries/60familyaction_mandatory/yml/extra_dirs/extra/00-base.yml index 164df9197..72c618f11 100644 --- a/tests/dictionaries/60familyaction_mandatory/yml/extra_dirs/extra/00-base.yml +++ b/tests/dictionaries/60familyaction_mandatory/yml/extra_dirs/extra/00-base.yml @@ -8,7 +8,7 @@ variables: type: number description: "d\xE9lai en minutes avant lancement" value: - - text: '0' + - text: 0 - variable: name: day type: number diff --git a/tests/dictionaries/80check_self/yml/00-base.yml b/tests/dictionaries/80check_self/yml/00-base.yml index 50bb47536..5a3011e39 100644 --- a/tests/dictionaries/80check_self/yml/00-base.yml +++ b/tests/dictionaries/80check_self/yml/00-base.yml @@ -19,7 +19,7 @@ constraints: param: - name: mini type: number - text: '0' + text: 0 - name: maxi type: variable text: int diff --git a/tests/dictionaries/80check_unknown/yml/00-base.yml b/tests/dictionaries/80check_unknown/yml/00-base.yml index f8960647e..63958c388 100644 --- a/tests/dictionaries/80check_unknown/yml/00-base.yml +++ b/tests/dictionaries/80check_unknown/yml/00-base.yml @@ -18,8 +18,8 @@ constraints: - name: unknown param: - name: mini - text: '0' + text: 0 - name: maxi - text: '100' + text: 100 target: - text: int diff --git a/tests/dictionaries/80check_without_target/yml/00-base.yml b/tests/dictionaries/80check_without_target/yml/00-base.yml index 684e2c395..afca03569 100644 --- a/tests/dictionaries/80check_without_target/yml/00-base.yml +++ b/tests/dictionaries/80check_without_target/yml/00-base.yml @@ -18,6 +18,6 @@ constraints: - name: valid_entier param: - name: mini - text: '0' + text: 0 - name: maxi - text: '100' + text: 100 diff --git a/tests/dictionaries/80empty_param_number/yml/00_base.yml b/tests/dictionaries/80empty_param_number/yml/00_base.yml index 52b266cd2..171b7fa70 100644 --- a/tests/dictionaries/80empty_param_number/yml/00_base.yml +++ b/tests/dictionaries/80empty_param_number/yml/00_base.yml @@ -14,7 +14,7 @@ variables: description: "Port d'\xE9coute du proxy NTLM" mode: expert value: - - text: '3127' + - text: 3127 constraints: - fill: - name: calc_multi_condition diff --git a/tests/dictionaries/80empty_typeeole_eole/yml/00_base.yml b/tests/dictionaries/80empty_typeeole_eole/yml/00_base.yml index b0d79a8ca..eb0f55224 100644 --- a/tests/dictionaries/80empty_typeeole_eole/yml/00_base.yml +++ b/tests/dictionaries/80empty_typeeole_eole/yml/00_base.yml @@ -14,7 +14,7 @@ variables: description: "Port d'\xE9coute du proxy NTLM" mode: expert value: - - text: '3127' + - text: 3127 constraints: - fill: - name: calc_multi_condition @@ -24,7 +24,7 @@ constraints: name: condition_1 propertyerror: true - name: match - text: '3128' + text: 3128 - name: mismatch type: variable propertyerror: true diff --git a/tests/dictionaries/80empty_typeeole_number/yml/00_base.yml b/tests/dictionaries/80empty_typeeole_number/yml/00_base.yml index 9773a1bce..8cb176c1e 100644 --- a/tests/dictionaries/80empty_typeeole_number/yml/00_base.yml +++ b/tests/dictionaries/80empty_typeeole_number/yml/00_base.yml @@ -11,7 +11,7 @@ variables: description: "Port d'\xE9coute du proxy NTLM" mode: expert value: - - text: '3127' + - text: 3127 constraints: - fill: - name: calc_multi_condition @@ -21,7 +21,7 @@ constraints: name: condition_2 propertyerror: true - name: match - text: '3128' + text: 3128 - name: mismatch type: variable propertyerror: true diff --git a/tests/dictionaries/80family_dynamic_check/yml/00-base.yml b/tests/dictionaries/80family_dynamic_check/yml/00-base.yml index 239b8e381..620a4f99b 100644 --- a/tests/dictionaries/80family_dynamic_check/yml/00-base.yml +++ b/tests/dictionaries/80family_dynamic_check/yml/00-base.yml @@ -25,9 +25,9 @@ constraints: param: - name: mini type: number - text: '0' + text: 0 - name: maxi type: number - text: '100' + text: 100 target: - text: vardynval1 diff --git a/tests/dictionaries/80familyaction_accent/yml/extra_dirs/extra/00-base.yml b/tests/dictionaries/80familyaction_accent/yml/extra_dirs/extra/00-base.yml index 0cc90f3c6..8b854298f 100644 --- a/tests/dictionaries/80familyaction_accent/yml/extra_dirs/extra/00-base.yml +++ b/tests/dictionaries/80familyaction_accent/yml/extra_dirs/extra/00-base.yml @@ -8,4 +8,4 @@ variables: type: number description: "d\xE9lai en minutes avant lancement" value: - - text: '0' + - text: 0 diff --git a/tests/dictionaries/80frozenifin_unknown/yml/00-base.yml b/tests/dictionaries/80frozenifin_unknown/yml/00-base.yml index 0eecb57fd..e7adda643 100644 --- a/tests/dictionaries/80frozenifin_unknown/yml/00-base.yml +++ b/tests/dictionaries/80frozenifin_unknown/yml/00-base.yml @@ -21,14 +21,14 @@ variables: help: bla bla bla choice: - type: number - text: '1' + text: 1 - type: number - text: '2' + text: 2 - type: number - text: '3' + text: 3 value: - type: number - text: '1' + text: 1 - variable: name: test_variable type: number @@ -38,7 +38,7 @@ constraints: - name: hidden_if_in source: condition param: - - text: '4' + - text: 4 target: - type: variable text: test_variable diff --git a/tests/dictionaries/80valid_entier_invalid_param/yml/00-base.yml b/tests/dictionaries/80valid_entier_invalid_param/yml/00-base.yml index 57dbabfb5..fc69b7ca7 100644 --- a/tests/dictionaries/80valid_entier_invalid_param/yml/00-base.yml +++ b/tests/dictionaries/80valid_entier_invalid_param/yml/00-base.yml @@ -19,6 +19,6 @@ constraints: param: - name: unknown type: number - text: '0' + text: 0 target: - text: int diff --git a/tests/dictionaries/80valid_entier_not_number/yml/00-base.yml b/tests/dictionaries/80valid_entier_not_number/yml/00-base.yml index 2e07335d2..964dc1a70 100644 --- a/tests/dictionaries/80valid_entier_not_number/yml/00-base.yml +++ b/tests/dictionaries/80valid_entier_not_number/yml/00-base.yml @@ -18,9 +18,9 @@ constraints: - name: valid_entier param: - name: mini - text: '0' + text: 0 - name: maxi type: number - text: '100' + text: 100 target: - text: int diff --git a/tests/dictionaries/88valid_enum_invalid_default/yml/00-base.yml b/tests/dictionaries/88valid_enum_invalid_default/yml/00-base.yml index 32326e532..cf517fc79 100644 --- a/tests/dictionaries/88valid_enum_invalid_default/yml/00-base.yml +++ b/tests/dictionaries/88valid_enum_invalid_default/yml/00-base.yml @@ -23,8 +23,8 @@ variables: text: a choice: - type: string - text: '1' + text: 1 - type: string - text: '2' + text: 2 - type: string - text: '3' + text: 3 diff --git a/tests/test_1_flattener.py b/tests/test_1_flattener.py index b1870b0da..44f0f85e6 100644 --- a/tests/test_1_flattener.py +++ b/tests/test_1_flattener.py @@ -115,6 +115,13 @@ def xml_to_yaml(filename, destfilename): value = True elif value == 'False': value = False + try: + # if it's a number + nvalue = int(value) + assert str(nvalue) == value + value = nvalue + except: + pass if key.startswith('@'): # remove @ dico[key[1:]] = value @@ -127,7 +134,7 @@ def xml_to_yaml(filename, destfilename): dico[key] = value elif key == 'value': dico[key] = [{'text': value}] - elif isinstance(value, (str, bool)): + elif isinstance(value, (str, bool, int)): dico[key] = [{'text': value}] else: dico[key] = [value] diff --git a/tests/test_others.py b/tests/test_others.py index 9d88924c9..757690d53 100644 --- a/tests/test_others.py +++ b/tests/test_others.py @@ -19,7 +19,8 @@ def parse_dtd_subelement(obj_name, content, default_required=False): yield {'name': content.name, 'type': None, 'required': default_required} if content.left: if content.left.type == 'pcdata': - yield {'name': 'text', 'type': None, 'required': False} + # choice + yield {'name': 'text', 'type': 'any', 'required': False} else: yield {'name': content.left.name, 'type': None, 'required': default_required} if content.right: