Пример #1
0
    def test_invoke_raises_type_error_with_comp(self, comp):
        context = execution_contexts.create_local_async_python_execution_context(
        )
        context = native_platform.NativeFederatedContext(context)

        with self.assertRaises(TypeError):
            context.invoke(comp, None)
Пример #2
0
    def test_init_does_not_raise_type_error_with_context(self):
        context = execution_contexts.create_local_async_python_execution_context(
        )

        try:
            native_platform.NativeFederatedContext(context)
        except TypeError:
            self.fail('Raised TypeError unexpectedly.')
Пример #3
0
    async def test_invoke_returns_result(self):
        context = execution_contexts.create_local_async_python_execution_context(
        )
        context = native_platform.NativeFederatedContext(context)

        @tensorflow_computation.tf_computation(tf.int32, tf.int32)
        def add(x, y):
            return x + y

        result = context.invoke(add, structure.Struct.unnamed(1, 2))
        actual_value = await result.get_value()
        self.assertEqual(actual_value, 3)
class CheckInFederatedContextTest(parameterized.TestCase):

  def test_does_not_raise_value_error(self):
    context = _TestFederatedContext()

    with self.assertRaises(ValueError):
      federated_context.check_in_federated_context()

    with context_stack_impl.context_stack.install(context):
      try:
        federated_context.check_in_federated_context()
      except TypeError:
        self.fail('Raised TypeError unexpectedly.')

    with self.assertRaises(ValueError):
      federated_context.check_in_federated_context()

  @parameterized.named_parameters(
      ('local_cpp_async',
       execution_contexts.create_local_async_python_execution_context()),
      ('local_cpp_sync',
       execution_contexts.create_local_python_execution_context()),
  )
  def test_raises_value_error_with_context(self, context):
    with self.assertRaises(ValueError):
      federated_context.check_in_federated_context()

    with context_stack_impl.context_stack.install(context):
      with self.assertRaises(ValueError):
        federated_context.check_in_federated_context()

    with self.assertRaises(ValueError):
      federated_context.check_in_federated_context()

  def test_raises_value_error_with_context_nested(self):
    with self.assertRaises(ValueError):
      federated_context.check_in_federated_context()

    context = _TestFederatedContext()
    with context_stack_impl.context_stack.install(context):
      try:
        federated_context.check_in_federated_context()
      except TypeError:
        self.fail('Raised TypeError unexpectedly.')

      context = execution_contexts.create_local_python_execution_context()
      with context_stack_impl.context_stack.install(context):
        with self.assertRaises(ValueError):
          federated_context.check_in_federated_context()

    with self.assertRaises(ValueError):
      federated_context.check_in_federated_context()
Пример #5
0
    async def test_computation_returns_result(self):
        context = execution_contexts.create_local_async_python_execution_context(
        )
        context = native_platform.NativeFederatedContext(context)

        @tensorflow_computation.tf_computation(tf.int32, tf.int32)
        def add(x, y):
            return x + y

        with context_stack_impl.context_stack.install(context):
            result = add(1, 2)

        actual_value = await result.get_value()
        self.assertEqual(actual_value, 3)
Пример #6
0
    def test_invoke_raises_value_error_with_comp(self):
        context = execution_contexts.create_local_async_python_execution_context(
        )
        context = native_platform.NativeFederatedContext(context)

        @tensorflow_computation.tf_computation()
        def return_one():
            return 1

        with self.assertRaises(ValueError):
            with mock.patch.object(federated_context,
                                   'contains_only_server_placed_data',
                                   return_value=False):
                context.invoke(return_one, None)
Пример #7
0
    def test_invoke_does_not_raise_value_error_with_comp(self):
        context = execution_contexts.create_local_async_python_execution_context(
        )
        context = native_platform.NativeFederatedContext(context)

        @tensorflow_computation.tf_computation()
        def return_one():
            return 1

        try:
            with mock.patch.object(federated_context,
                                   'contains_only_server_placed_data',
                                   return_value=True):
                context.invoke(return_one, None)
        except ValueError:
            self.fail('Raised ValueError unexpectedly.')