22from functools import wraps
33from typing import Any , TypeVar
44
5- F = TypeVar ('F' , bound = Callable [..., Any ])
5+ F = TypeVar ("F" , bound = Callable [..., Any ])
66
77
88# Legacy weight decorator (kept for backward compatibility)
@@ -18,15 +18,12 @@ def decorator(func: F) -> F:
1818
1919# New decorator-based API
2020
21+
2122class StepDecorator :
2223 """Decorator for marking test steps."""
2324
2425 def __init__ (
25- self ,
26- name : str | None = None ,
27- * ,
28- weight_value : int | float | None = None ,
29- enabled : bool = True
26+ self , name : str | None = None , * , weight_value : int | float | None = None , enabled : bool = True
3027 ) -> None :
3128 self .name = name
3229 self .weight_value = weight_value
@@ -50,7 +47,7 @@ def step(
5047 name_or_func : str | Callable [..., Any ] | None = None ,
5148 * ,
5249 weight_value : int | float | None = None ,
53- enabled : bool = True
50+ enabled : bool = True ,
5451) -> Callable [..., Any ] | StepDecorator :
5552 """Mark a method as a test step.
5653
@@ -80,11 +77,7 @@ def my_step(self): pass
8077 return StepDecorator (name_or_func , weight_value = weight_value , enabled = enabled )
8178
8279
83- def guard (
84- step_name_or_func : str | Callable [..., Any ],
85- * ,
86- invert : bool = False
87- ) -> Callable [..., Any ]:
80+ def guard (step_name_or_func : str | Callable [..., Any ], * , invert : bool = False ) -> Callable [..., Any ]:
8881 """Mark a method as a guard for a step.
8982
9083 Can be used as inline lambda or separate method:
@@ -110,12 +103,14 @@ def can_process(self) -> bool:
110103 func ._osmo_guard_inline = True # type: ignore[attr-defined]
111104 func ._osmo_guard_invert = invert # type: ignore[attr-defined]
112105 return func
106+
113107 # Named guard
114108 def decorator (func : Callable [..., Any ]) -> Callable [..., Any ]:
115109 func ._osmo_guard = True # type: ignore[attr-defined]
116110 func ._osmo_guard_for = step_name_or_func # type: ignore[attr-defined]
117111 func ._osmo_guard_invert = invert # type: ignore[attr-defined]
118112 return func
113+
119114 return decorator
120115
121116
@@ -133,10 +128,12 @@ def before_login(self):
133128 Returns:
134129 Decorated function
135130 """
131+
136132 def decorator (func : F ) -> F :
137133 func ._osmo_pre = True # type: ignore[attr-defined]
138134 func ._osmo_pre_for = step_name # type: ignore[attr-defined]
139135 return func
136+
140137 return decorator
141138
142139
@@ -154,10 +151,12 @@ def after_login(self):
154151 Returns:
155152 Decorated function
156153 """
154+
157155 def decorator (func : F ) -> F :
158156 func ._osmo_post = True # type: ignore[attr-defined]
159157 func ._osmo_post_for = step_name # type: ignore[attr-defined]
160158 return func
159+
161160 return decorator
162161
163162
@@ -176,9 +175,11 @@ def checkout(self):
176175 Returns:
177176 Decorated function
178177 """
178+
179179 def decorator (func : F ) -> F :
180180 func ._osmo_requires = list (requirements ) # type: ignore[attr-defined]
181181 return func
182+
182183 return decorator
183184
184185
@@ -197,10 +198,12 @@ def complete_order(self):
197198 Returns:
198199 Decorated function
199200 """
201+
200202 def decorator (func : F ) -> F :
201203 func ._osmo_requires = list (requirements ) # type: ignore[attr-defined]
202204 func ._osmo_requires_all = True # type: ignore[attr-defined]
203205 return func
206+
204207 return decorator
205208
206209
@@ -219,10 +222,12 @@ def check_auth(self):
219222 Returns:
220223 Decorated function
221224 """
225+
222226 def decorator (func : F ) -> F :
223227 func ._osmo_requires = list (requirements ) # type: ignore[attr-defined]
224228 func ._osmo_requires_any = True # type: ignore[attr-defined]
225229 return func
230+
226231 return decorator
227232
228233
@@ -243,11 +248,13 @@ def get_cart_size(self) -> str:
243248 Returns:
244249 Decorated function
245250 """
251+
246252 def decorator (func : F ) -> F :
247253 func ._osmo_variable = True # type: ignore[attr-defined]
248254 func ._osmo_variable_name = name # type: ignore[attr-defined]
249255 func ._osmo_variable_categories = categories # type: ignore[attr-defined]
250256 return func
257+
251258 return decorator
252259
253260
0 commit comments