MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / run_v1_only

Function run_v1_only

tensorflow/python/framework/test_util.py:1230–1280  ·  view source on GitHub ↗

Execute the decorated test only if running in v1 mode. This function is intended to be applied to tests that exercise v1 only functionality. If the test is run in v2 mode it will simply be skipped. `deprecated_graph_mode_only`, `run_v1_only`, `run_v2_only`, and `run_in_graph_and_eager_mode

(reason, func=None)

Source from the content-addressed store, hash-verified

1228
1229
1230def run_v1_only(reason, func=None):
1231 """Execute the decorated test only if running in v1 mode.
1232
1233 This function is intended to be applied to tests that exercise v1 only
1234 functionality. If the test is run in v2 mode it will simply be skipped.
1235
1236 `deprecated_graph_mode_only`, `run_v1_only`, `run_v2_only`, and
1237 `run_in_graph_and_eager_modes` are available decorators for different
1238 v1/v2/eager/graph combinations.
1239
1240 Args:
1241 reason: string giving a reason for limiting the test to v1 only.
1242 func: function to be annotated. If `func` is None, this method returns a
1243 decorator the can be applied to a function. If `func` is not None this
1244 returns the decorator applied to `func`.
1245
1246 Returns:
1247 Returns a decorator that will conditionally skip the decorated test method.
1248 """
1249 if not isinstance(reason, str):
1250 raise ValueError("'reason' should be string, got {}".format(type(reason)))
1251
1252 def decorator(f):
1253 if tf_inspect.isclass(f):
1254 # To skip an entire test suite class, we only decorate the setUp method
1255 # to skip all tests. There are cases when setUp is not defined (not
1256 # overridden in subclasses of TestCase, so not available in f.__dict__
1257 # below). For those cases, we walk the method resolution order list and
1258 # pick the first setUp method we find (usually this should be the one in
1259 # the parent class since that's the TestCase class).
1260 for cls in type.mro(f):
1261 setup = cls.__dict__.get("setUp")
1262 if setup is not None:
1263 setattr(f, "setUp", decorator(setup))
1264 break
1265
1266 return f
1267 else:
1268 # If f is just a function, just create a decorator for it and return it
1269 def decorated(self, *args, **kwargs):
1270 if tf2.enabled():
1271 self.skipTest(reason)
1272
1273 return f(self, *args, **kwargs)
1274
1275 return decorated
1276
1277 if func is not None:
1278 return decorator(func)
1279
1280 return decorator
1281
1282
1283def run_v2_only(func=None):

Callers

nothing calls this directly

Calls 3

typeFunction · 0.85
decoratorFunction · 0.70
formatMethod · 0.45

Tested by

no test coverage detected