diff options
author | Yaroslav Brustinov <ybrustin@cisco.com> | 2016-02-11 12:53:07 +0200 |
---|---|---|
committer | Yaroslav Brustinov <ybrustin@cisco.com> | 2016-02-11 12:53:07 +0200 |
commit | 9adfbada8a429dcdd7bf95d9b52d28bb3448e1d4 (patch) | |
tree | d8473c54c1520103a5ae45200868ffb949d11592 /scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py | |
parent | 4b3092339d578f2c08de2fa1a55de5dea5ecf053 (diff) |
validate_type for easier type checks, hltapi move to trex_stl_lib
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py')
-rw-r--r-- | scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py index 1164076b..d387ac9c 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_types.py @@ -1,6 +1,7 @@ from collections import namedtuple from utils.text_opts import * +from trex_stl_exceptions import * RpcCmdData = namedtuple('RpcCmdData', ['method', 'params']) @@ -93,3 +94,17 @@ def RC_ERR (err): def RC_WARN (warn): return RC(True, warn, is_warn = True) + + +# validate type of arg +# example1: validate_type('somearg', somearg, [int, long]) +# example2: validate_type('another_arg', another_arg, str) +def validate_type(arg_name, arg, valid_types): + if type(valid_types) is list: + valid_types = tuple(valid_types) + if type(valid_types) is type or type(valid_types) is tuple: + if isinstance(arg, valid_types): + return + raise STLTypeError(arg_name, type(arg), valid_types) + else: + raise STLError('validate_type: valid_types should be type or list or tuple of types') |