Ejemplo n.º 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)
Ejemplo n.º 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.')
Ejemplo n.º 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)
Ejemplo n.º 4
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)
Ejemplo n.º 5
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)
Ejemplo n.º 6
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.')
Ejemplo n.º 7
0
    def test_init_raises_value_error_with_context(self):
        context = execution_contexts.create_local_python_execution_context()

        with self.assertRaises(ValueError):
            native_platform.NativeFederatedContext(context)
Ejemplo n.º 8
0
 def test_init_raises_type_error_with_context(self, context):
     with self.assertRaises(TypeError):
         native_platform.NativeFederatedContext(context)