def test_variable_reuse_exception_nested(self): with test_util.IsolateTest(), session.Session(): first_container_variable = resource_variable_ops.ResourceVariable( name="first_container_variable", initial_value=1) if context.in_graph_mode(): self.evaluate([variables.global_variables_initializer()]) with test_util.IsolateTest(), session.Session(): if context.in_graph_mode(): with self.assertRaises(RuntimeError): self.evaluate(first_container_variable.read_value()) else: with self.assertRaises(ValueError): first_container_variable.read_value()
def test_no_sharing(self): with test_util.IsolateTest(), session.Session(): first_container_variable = resource_variable_ops.ResourceVariable( name="same_name", initial_value=1) if context.in_graph_mode(): self.evaluate([variables.global_variables_initializer()]) with test_util.IsolateTest(), session.Session(): second_container_variable = resource_variable_ops.ResourceVariable( name="same_name", initial_value=2) if context.in_graph_mode(): self.evaluate([variables.global_variables_initializer()]) self.assertEqual( 2, self.evaluate(second_container_variable.read_value())) self.assertEqual( 1, self.evaluate(first_container_variable.read_value()))
def test_graph_mode_isolation(self): with context.graph_mode(): # Even if we've (accidentally) called IsolateTest in Graph mode, it should # provide Eager isolation. with test_util.IsolateTest(): with context.eager_mode(): first_container_variable = resource_variable_ops.ResourceVariable( name="first_container_variable", initial_value=1) with context.eager_mode(): with self.assertRaises(ValueError): first_container_variable.read_value()