Execute the decorated test in graph mode. This function returns a decorator intended to be applied to tests that are not compatible with eager mode. When this decorator is applied, the test body will be run in an environment where API calls construct graphs instead of executing eagerly.
(func=None)
| 1176 | |
| 1177 | |
| 1178 | def deprecated_graph_mode_only(func=None): |
| 1179 | """Execute the decorated test in graph mode. |
| 1180 | |
| 1181 | This function returns a decorator intended to be applied to tests that are not |
| 1182 | compatible with eager mode. When this decorator is applied, the test body will |
| 1183 | be run in an environment where API calls construct graphs instead of executing |
| 1184 | eagerly. |
| 1185 | |
| 1186 | `deprecated_graph_mode_only`, `run_v1_only`, `run_v2_only`, and |
| 1187 | `run_in_graph_and_eager_modes` are available decorators for different |
| 1188 | v1/v2/eager/graph combinations. |
| 1189 | |
| 1190 | Args: |
| 1191 | func: function to be annotated. If `func` is None, this method returns a |
| 1192 | decorator the can be applied to a function. If `func` is not None this |
| 1193 | returns the decorator applied to `func`. |
| 1194 | |
| 1195 | Returns: |
| 1196 | Returns a decorator that will run the decorated test method in graph mode. |
| 1197 | """ |
| 1198 | |
| 1199 | def decorator(f): |
| 1200 | if tf_inspect.isclass(f): |
| 1201 | setup = f.__dict__.get("setUp") |
| 1202 | if setup is not None: |
| 1203 | setattr(f, "setUp", decorator(setup)) |
| 1204 | |
| 1205 | for name, value in f.__dict__.copy().items(): |
| 1206 | if (callable(value) and |
| 1207 | name.startswith(unittest.TestLoader.testMethodPrefix)): |
| 1208 | setattr(f, name, decorator(value)) |
| 1209 | |
| 1210 | return f |
| 1211 | |
| 1212 | def decorated(self, *args, **kwargs): |
| 1213 | if tf2.enabled(): |
| 1214 | with context.graph_mode(): |
| 1215 | return f(self, *args, **kwargs) |
| 1216 | else: |
| 1217 | return f(self, *args, **kwargs) |
| 1218 | |
| 1219 | return decorated |
| 1220 | |
| 1221 | if func is not None: |
| 1222 | return decorator(func) |
| 1223 | |
| 1224 | return decorator |
| 1225 | |
| 1226 | |
| 1227 | run_deprecated_v1 = deprecated_graph_mode_only |
nothing calls this directly
no test coverage detected