Coverage for portality/lib/argvalidate.py: 92%

12 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-07-22 15:59 +0100

1def argvalidate(caller_name, args_and_rules, exception): 

2 for anr in args_and_rules: 

3 arg = anr.get("arg") 

4 arg_name = anr.get("arg_name") 

5 inst = anr.get("instance") 

6 allow_none = anr.get("allow_none", True) 

7 

8 if not allow_none: 

9 if arg is None: 

10 raise exception(caller_name + " expected '" + arg_name + "' not to be None") 

11 

12 if inst is not None and arg is not None: 

13 if not isinstance(arg, inst): 

14 raise exception(caller_name + " expected '" + arg_name + "' to be " + inst.__name__ + " but got " + type(arg).__name__)