@test_util.run_v1_only('b/120545219')
def testControlFlow(self):
    with self.cached_session() as sess:
        v0 = variables.Variable(0, name='v0')
        var_dict = {}

        def var_in_then_clause():
            v1 = variables.Variable(1, name='v1')
            var_dict['v1'] = v1
            return (v1 + v0)

        def var_in_else_clause():
            v2 = variables.Variable(2, name='v2')
            var_dict['v2'] = v2
            return (v2 + v0)
        add = control_flow_ops.cond(math_ops.less(v0, 10), var_in_then_clause, var_in_else_clause)
        v1 = var_dict['v1']
        v2 = var_dict['v2']
        self.evaluate(v1.initializer)
        self.assertEqual([1], self.evaluate(v1))
        self.evaluate(v2.initializer)
        self.assertEqual([2], self.evaluate(v2))
        with self.assertRaisesRegex(errors_impl.OpError, 'uninitialized'):
            self.evaluate(v0)
        with self.assertRaisesRegex(errors_impl.OpError, 'uninitialized'):
            self.evaluate(add)
        self.evaluate(v0.initializer)
        self.evaluate(add)
@test_util.run_v1_only('b/120545219')
def testControlFlow(self):
    with self.cached_session() as sess:
        v0 = variables.Variable(0, name='v0')
        var_dict = {}

        def var_in_then_clause():
            v1 = variables.Variable(1, name='v1')
            var_dict['v1'] = v1
            return (v1 + v0)

        def var_in_else_clause():
            v2 = variables.Variable(2, name='v2')
            var_dict['v2'] = v2
            return (v2 + v0)
        add = control_flow_ops.cond(math_ops.less(v0, 10), var_in_then_clause, var_in_else_clause)
        v1 = var_dict['v1']
        v2 = var_dict['v2']
        self.evaluate(v1.initializer)
        self.assertEqual([1], self.evaluate(v1))
        self.evaluate(v2.initializer)
        self.assertEqual([2], self.evaluate(v2))
        with self.assertRaisesRegex(errors_impl.OpError, 'uninitialized'):
            self.evaluate(v0)
        with self.assertRaisesRegex(errors_impl.OpError, 'uninitialized'):
            self.evaluate(add)
        self.evaluate(v0.initializer)
        self.evaluate(add)