Adds methods that call original methods with WhileV2 and CondV2 enabled. Note this enables CondV2 and WhileV2 in new methods after running the test class's setup method. In addition to this, callers must import the while_v2 module in order to set the _while_v2 module in control_flow_ops.
(cls)
| 465 | |
| 466 | |
| 467 | def with_control_flow_v2(cls): |
| 468 | """Adds methods that call original methods with WhileV2 and CondV2 enabled. |
| 469 | |
| 470 | Note this enables CondV2 and WhileV2 in new methods after running the test |
| 471 | class's setup method. |
| 472 | |
| 473 | In addition to this, callers must import the while_v2 module in order to set |
| 474 | the _while_v2 module in control_flow_ops. |
| 475 | |
| 476 | If a test function has _disable_control_flow_v2 attr set to True (using the |
| 477 | @disable_control_flow_v2 decorator), the v2 function is not generated for it. |
| 478 | |
| 479 | Example: |
| 480 | |
| 481 | @test_util.with_control_flow_v2 |
| 482 | class ControlFlowTest(test.TestCase): |
| 483 | |
| 484 | def testEnabledForV2(self): |
| 485 | ... |
| 486 | |
| 487 | @test_util.disable_control_flow_v2("b/xyzabc") |
| 488 | def testDisabledForV2(self): |
| 489 | ... |
| 490 | |
| 491 | Generated class: |
| 492 | class ControlFlowTest(test.TestCase): |
| 493 | |
| 494 | def testEnabledForV2(self): |
| 495 | ... |
| 496 | |
| 497 | def testEnabledForV2WithControlFlowV2(self): |
| 498 | // Enable V2 flags. |
| 499 | testEnabledForV2(self) |
| 500 | // Restore V2 flags. |
| 501 | |
| 502 | def testDisabledForV2(self): |
| 503 | ... |
| 504 | |
| 505 | Args: |
| 506 | cls: class to decorate |
| 507 | |
| 508 | Returns: |
| 509 | cls with new test methods added |
| 510 | """ |
| 511 | if control_flow_util.ENABLE_CONTROL_FLOW_V2: |
| 512 | return cls |
| 513 | |
| 514 | for name, value in cls.__dict__.copy().items(): |
| 515 | if (callable(value) and |
| 516 | name.startswith(unittest.TestLoader.testMethodPrefix) and |
| 517 | not getattr(value, "_disable_control_flow_v2", False)): |
| 518 | setattr(cls, name + "WithControlFlowV2", enable_control_flow_v2(value)) |
| 519 | return cls |
| 520 | |
| 521 | |
| 522 | def disable_control_flow_v2(unused_msg): |
nothing calls this directly
no test coverage detected