opentf-toolkit-nightly 0.62.0.dev1330__py3-none-any.whl → 0.62.0.dev1338__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -830,16 +830,22 @@ def validate_inputs(
830
830
  declaration: Dict[str, Dict[str, Any]],
831
831
  inputs: Dict[str, Any],
832
832
  additional_inputs: bool = False,
833
+ normalize: bool = True,
833
834
  ) -> None:
834
835
  """Validate inputs.
835
836
 
836
837
  Default values are filled in `inputs` as appropriate.
837
838
 
838
- Input names are normalized to use hyphens instead of underscores.
839
+ Input names are normalized to use hyphens instead of underscores
840
+ by default (declaration is expected to be normalized).
839
841
 
840
- Non-normalized inputs are removed from the dictionary.
842
+ If `normalize` is set, non-normalized inputs are removed from the
843
+ dictionary.
844
+
845
+ Choices values are validated.
841
846
 
842
- Choices values are validated. Types are not checked.
847
+ Types are enforced if declared as `boolean`, `number`, or `string`.
848
+ Conversion is performed if needed.
843
849
 
844
850
  # Required parameters
845
851
 
@@ -849,16 +855,14 @@ def validate_inputs(
849
855
  # Optional parameters
850
856
 
851
857
  - additional_inputs: a boolean (False by default)
858
+ - normalize: a boolean (True by default)
852
859
 
853
860
  # Raised exceptions
854
861
 
855
862
  A _ValueError_ exception is raised if inputs do not match
856
863
  declaration.
857
864
  """
858
- for key in declaration:
859
- if key.startswith('{'): # Skip template entries
860
- break
861
- else:
865
+ if normalize and not any(key.startswith('{') for key in declaration):
862
866
  _normalize_inputs(inputs)
863
867
 
864
868
  for key, definition in declaration.items():
@@ -868,19 +872,41 @@ def validate_inputs(
868
872
  if definition.get('required', False):
869
873
  raise ValueError(f'Mandatory input "{key}" not provided.')
870
874
  _set_default(inputs, key, definition)
871
- if definition.get('type') == 'choice':
872
- if (val := inputs.get(key)) not in definition['options']:
875
+ continue
876
+ val = inputs.get(key)
877
+ type_ = definition.get('type')
878
+ if type_ == 'choice':
879
+ if val not in definition['options']:
873
880
  allowed = '", "'.join(sorted(definition['options']))
874
881
  raise ValueError(
875
882
  f'Invalid value "{val}" for input "{key}". Allowed values: "{allowed}".'
876
883
  )
884
+ elif type_ == 'boolean' and not isinstance(val, bool):
885
+ if isinstance(val, str) and val.lower() in ('true', 'false'):
886
+ inputs[key] = val.lower() == 'true'
887
+ continue
888
+ raise ValueError(
889
+ f'Invalid value "{val}" for input "{key}". Allowed values: "true", "false".'
890
+ )
891
+ elif type_ == 'number':
892
+ try:
893
+ inputs[key] = int(val)
894
+ except ValueError:
895
+ try:
896
+ inputs[key] = float(val)
897
+ except ValueError:
898
+ raise ValueError(
899
+ f'Invalid value "{val}" for input "{key}". Expected a number.'
900
+ )
901
+ elif type_ == 'string':
902
+ inputs[key] = str(val)
877
903
 
878
904
  if additional_inputs:
879
905
  return
880
906
 
881
- for key in inputs:
882
- if key not in declaration and key.replace('_', '-') not in declaration:
883
- allowed = '", "'.join(sorted(declaration))
884
- raise ValueError(
885
- f'Unexpected input "{key}" found. Allowed inputs: "{allowed}".'
886
- )
907
+ if unexpected := set(inputs) - set(declaration):
908
+ allowed = '", "'.join(sorted(declaration))
909
+ unexpected = '", "'.join(sorted(unexpected))
910
+ raise ValueError(
911
+ f'Unexpected inputs "{unexpected}" found. Allowed inputs: "{allowed}".'
912
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: opentf-toolkit-nightly
3
- Version: 0.62.0.dev1330
3
+ Version: 0.62.0.dev1338
4
4
  Summary: OpenTestFactory Orchestrator Toolkit
5
5
  Home-page: https://gitlab.com/henixdevelopment/open-source/opentestfactory/python-toolkit
6
6
  Author: Martin Lafaix
@@ -1,4 +1,4 @@
1
- opentf/commons/__init__.py,sha256=zyXR1ivlO_PZipQzRA2156qPMA0z7SpeFOOalQ7EG0Y,27075
1
+ opentf/commons/__init__.py,sha256=HOqPRAFWWg5kGvxzTxoMtj7WeTDggQfR9vyBiu6vXhQ,28116
2
2
  opentf/commons/auth.py,sha256=gXRp_0Tf3bfd65F4QiQmh6C6vR9y3ugag_0DSvozJFk,15898
3
3
  opentf/commons/config.py,sha256=RVSSdQhMle4oCo_z_AR2EQ4U6sUjSxw-qVBtjKuJVfo,10219
4
4
  opentf/commons/exceptions.py,sha256=7dhUXO8iyAbqVwlUKxZhgRzGqVcb7LkG39hFlm-VxIA,2407
@@ -59,8 +59,8 @@ opentf/scripts/startup.py,sha256=AcVXU2auPvqMb_6OpGzkVqrpgYV6vz7x_Rnv8YbAEkk,231
59
59
  opentf/toolkit/__init__.py,sha256=7MGAfKb5V9ckzWE8ozfj0PcC7g0a-0VfdyrClkWTk38,22319
60
60
  opentf/toolkit/channels.py,sha256=6qKSsAgq_oJpuDRiKqVUz-EAjdfikcCG3SFAGmKZdhQ,25551
61
61
  opentf/toolkit/core.py,sha256=fqnGgaYnuVcd4fyeNIwpc0QtyUo7jsKeVgdkBfY3iqo,9443
62
- opentf_toolkit_nightly-0.62.0.dev1330.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
63
- opentf_toolkit_nightly-0.62.0.dev1330.dist-info/METADATA,sha256=IN0fv6k0RErVnPzp5ZrrjdNSvDoyP2vKQIODmDm_dVc,2214
64
- opentf_toolkit_nightly-0.62.0.dev1330.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
65
- opentf_toolkit_nightly-0.62.0.dev1330.dist-info/top_level.txt,sha256=_gPuE6GTT6UNXy1DjtmQSfCcZb_qYA2vWmjg7a30AGk,7
66
- opentf_toolkit_nightly-0.62.0.dev1330.dist-info/RECORD,,
62
+ opentf_toolkit_nightly-0.62.0.dev1338.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
63
+ opentf_toolkit_nightly-0.62.0.dev1338.dist-info/METADATA,sha256=J1Ur6xkpKWdkQWJFP_ET1DFldSrsilHsmB91B7pmfMI,2214
64
+ opentf_toolkit_nightly-0.62.0.dev1338.dist-info/WHEEL,sha256=DK49LOLCYiurdXXOXwGJm6U4DkHkg4lcxjhqwRa0CP4,91
65
+ opentf_toolkit_nightly-0.62.0.dev1338.dist-info/top_level.txt,sha256=_gPuE6GTT6UNXy1DjtmQSfCcZb_qYA2vWmjg7a30AGk,7
66
+ opentf_toolkit_nightly-0.62.0.dev1338.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (77.0.3)
2
+ Generator: setuptools (78.0.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5