@@ -36,67 +36,73 @@ def ensure_activity_is_valid(activity: Activity):
3636
3737 In all failing cases, raises :exc:`InvalidActivity`.
3838 """
39+ errors = []
3940 if not activity :
40- raise InvalidActivity ("empty activity is no activity" )
41+ errors .append (InvalidActivity ("empty activity is no activity" ))
42+ return errors
4143
4244 # when the activity is just a ref, there is little to validate
4345 ref = activity .get ("ref" )
4446 if ref is not None :
4547 if not isinstance (ref , str ) or ref == '' :
46- raise InvalidActivity (
47- "reference to activity must be non-empty strings" )
48- return
48+ errors . append ( InvalidActivity (
49+ "reference to activity must be non-empty strings" ))
50+ return errors
4951
5052 activity_type = activity .get ("type" )
5153 if not activity_type :
52- raise InvalidActivity ("an activity must have a type" )
54+ errors . append ( InvalidActivity ("an activity must have a type" ) )
5355
5456 if activity_type not in ("probe" , "action" ):
55- raise InvalidActivity (
56- "'{t}' is not a supported activity type" .format (t = activity_type ))
57+ errors . append ( InvalidActivity (
58+ "'{t}' is not a supported activity type" .format (t = activity_type )))
5759
5860 if not activity .get ("name" ):
59- raise InvalidActivity ("an activity must have a name" )
61+ errors . append ( InvalidActivity ("an activity must have a name" ) )
6062
6163 provider = activity .get ("provider" )
6264 if not provider :
63- raise InvalidActivity ("an activity requires a provider" )
65+ errors .append (InvalidActivity ("an activity requires a provider" ))
66+ provider_type = None
67+ else :
68+ provider_type = provider .get ("type" )
69+ if not provider_type :
70+ errors .append (InvalidActivity ("a provider must have a type" ))
6471
65- provider_type = provider .get ("type" )
66- if not provider_type :
67- raise InvalidActivity ("a provider must have a type" )
68-
69- if provider_type not in ("python" , "process" , "http" ):
70- raise InvalidActivity (
71- "unknown provider type '{type}'" .format (type = provider_type ))
72-
73- if not activity .get ("name" ):
74- raise InvalidActivity ("activity must have a name (cannot be empty)" )
72+ if provider_type not in ("python" , "process" , "http" ):
73+ errors .append (InvalidActivity (
74+ "unknown provider type '{type}'" .format (type = provider_type )))
7575
7676 timeout = activity .get ("timeout" )
7777 if timeout is not None :
7878 if not isinstance (timeout , numbers .Number ):
79- raise InvalidActivity ("activity timeout must be a number" )
79+ errors .append (
80+ InvalidActivity ("activity timeout must be a number" ))
8081
8182 pauses = activity .get ("pauses" )
8283 if pauses is not None :
8384 before = pauses .get ("before" )
8485 if before is not None and not isinstance (before , numbers .Number ):
85- raise InvalidActivity ("activity before pause must be a number" )
86+ errors .append (
87+ InvalidActivity ("activity before pause must be a number" ))
8688 after = pauses .get ("after" )
8789 if after is not None and not isinstance (after , numbers .Number ):
88- raise InvalidActivity ("activity after pause must be a number" )
90+ errors .append (
91+ InvalidActivity ("activity after pause must be a number" ))
8992
9093 if "background" in activity :
9194 if not isinstance (activity ["background" ], bool ):
92- raise InvalidActivity ("activity background must be a boolean" )
95+ errors .append (
96+ InvalidActivity ("activity background must be a boolean" ))
9397
9498 if provider_type == "python" :
95- validate_python_activity (activity )
99+ errors . extend ( validate_python_activity (activity ) )
96100 elif provider_type == "process" :
97- validate_process_activity (activity )
101+ errors . extend ( validate_process_activity (activity ) )
98102 elif provider_type == "http" :
99- validate_http_activity (activity )
103+ errors .extend (validate_http_activity (activity ))
104+
105+ return errors
100106
101107
102108def run_activities (experiment : Experiment , configuration : Configuration ,
0 commit comments