ariatosca-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject incubator-ariatosca git commit: improved type check
Date Thu, 06 Apr 2017 10:50:50 GMT
Repository: incubator-ariatosca
Updated Branches:
  refs/heads/ARIA-48-aria-cli ef3f6a070 -> e04ba1fb1


improved type check


Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/e04ba1fb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/e04ba1fb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/e04ba1fb

Branch: refs/heads/ARIA-48-aria-cli
Commit: e04ba1fb127484a011f6e6829800b9dcc27ec3b2
Parents: ef3f6a0
Author: Ran Ziv <ran@gigaspaces.com>
Authored: Thu Apr 6 13:50:46 2017 +0300
Committer: Ran Ziv <ran@gigaspaces.com>
Committed: Thu Apr 6 13:50:46 2017 +0300

----------------------------------------------------------------------
 aria/modeling/utils.py |  9 +++++----
 aria/utils/type.py     | 16 +++++++++-------
 2 files changed, 14 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e04ba1fb/aria/modeling/utils.py
----------------------------------------------------------------------
diff --git a/aria/modeling/utils.py b/aria/modeling/utils.py
index 35ce991..34c2ac7 100644
--- a/aria/modeling/utils.py
+++ b/aria/modeling/utils.py
@@ -78,12 +78,13 @@ def _merge_and_validate_inputs(inputs, template_inputs):
         else:
             # Validate input type
             try:
-                # TODO: improve type validation; Needs to consider custom data_types as well
-                if input_template.type_name in ('list', 'dict', 'tuple', 'string', 'integer',
-                                                'boolean', 'float'):
-                    validate_value_type(inputs[input_name], input_template.type_name)
+                validate_value_type(inputs[input_name], input_template.type_name)
             except ValueError:
                 wrong_type_inputs[input_name] = input_template.type_name
+            except RuntimeError:
+                # TODO: This error shouldn't be raised (or caught), but right now we lack
support
+                # for custom data_types, which will raise this error. Skipping their validation.
+                pass
 
     if missing_inputs:
         raise exceptions.MissingRequiredInputsException(

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/e04ba1fb/aria/utils/type.py
----------------------------------------------------------------------
diff --git a/aria/utils/type.py b/aria/utils/type.py
index 292225a..abcf422 100644
--- a/aria/utils/type.py
+++ b/aria/utils/type.py
@@ -15,9 +15,13 @@
 
 
 def validate_value_type(value, type_name):
-    """Supports both python and yaml type names"""
-    #TODO add timestamp type?
+    """
+    Validate a value is of a specific type.
+    A ValueError will be raised on type mismatch.
+    Supports both python and yaml type names.
+    """
 
+    #TODO add timestamp type?
     name_to_type = {
         'list': list,
         'dict': dict,
@@ -34,11 +38,9 @@ def validate_value_type(value, type_name):
 
     type = name_to_type.get(type_name.lower())
     if type is None:
-        raise ValueError('No supported type_name was provided')
-    try:
-        type(value)
-    except ValueError:
-        raise
+        raise RuntimeError('No supported type_name was provided')
+    # validating value type - ValueError will be raised on type mismatch
+    type(value)
 
 
 def convert_value_to_type(str_value, type_name):


Mime
View raw message