Пример #1
0
 def test_lifted_capehandler_multiple_inputs(self):
     lifted_multiple_identity = lifting.lift_io(ut.multiple_identity)
     inputs_ser = serde.serialize(1, 2, z=4)
     result = lifted_multiple_identity.as_cape_handler()(inputs_ser)
     result_deser = serde.deserialize(result)
     assert (1, 2) == result_deser[:2]
     assert 4 == result_deser[2]
Пример #2
0
    def test_wrong_liftio_kwargs_raises(self):
        with self.assertRaises(ValueError):
            lifting.lift_io(lambda x: x, encoder_hook=lambda x: x)

        with self.assertRaises(ValueError):
            lifting.lift_io(lambda x: x, decoder_hook=lambda x: x)

        with self.assertRaises(ValueError):
            lifting.lift_io(
                lambda x: x,
                encoder_hook=lambda x: x,
                hook_bundle=(lambda x: x, lambda x: x),
            )
Пример #3
0
    def test_wrong_liftio_types(self):
        @dataclasses.dataclass
        class MyFakeHookBundle:
            encoder_hook: Callable
            decoder_hook: Callable

        with self.assertRaises(TypeError):
            lifting.lift_io(lambda x: x, encoder_hook=1, decoder_hook=2)

        with self.assertRaises(TypeError):
            fake_bundle = MyFakeHookBundle(lambda x: x, lambda x: x)
            lifting.lift_io(lambda x: x, hook_bundle=fake_bundle)

        with self.assertRaises(TypeError):
            also_fake_bundle = serde.SerdeHookBundle(1, 2)
            lifting.lift_io(lambda x: x, hook_bundle=also_fake_bundle)
Пример #4
0
 def test_lifted_call(self, x):
     lifted_identity = lifting.lift_io(ut.identity)
     result = lifted_identity(x)
     assert x == result
Пример #5
0
 def test_lifted_capehandler_wrong_nb_inputs(self):
     lifted_multiple_identity = lifting.lift_io(ut.multiple_identity)
     inputs_ser = serde.serialize(1, z=4)
     with self.assertRaises(ValueError):
         lifted_multiple_identity.as_cape_handler()(inputs_ser)
Пример #6
0
 def test_lifted_capehandler(self, x):
     lifted_identity = lifting.lift_io(ut.identity)
     x_ser = serde.serialize(x)
     result = lifted_identity.as_cape_handler()(x_ser)
     result_deser = serde.deserialize(result)
     assert x == result_deser