diff --git a/typed_python/compiler/tests/numpy_interaction_test.py b/typed_python/compiler/tests/numpy_interaction_test.py index f15bfea9..aa7ee9b9 100644 --- a/typed_python/compiler/tests/numpy_interaction_test.py +++ b/typed_python/compiler/tests/numpy_interaction_test.py @@ -1,4 +1,4 @@ -from typed_python import ListOf, Entrypoint +from typed_python import ListOf, Entrypoint, SerializationContext import numpy import numpy.linalg @@ -44,3 +44,22 @@ def test_listof_from_sliced_numpy_array(): y = x[::2] assert ListOf(int)(y) == [0, 2] + + +def test_can_serialize_numpy_ufuncs(): + assert numpy.sin == SerializationContext().deserialize(SerializationContext().serialize(numpy.sin)) + assert numpy.max == SerializationContext().deserialize(SerializationContext().serialize(numpy.max)) + + +def test_can_serialize_numpy_array_from_builtin(): + x = numpy.ones(10) + assert (x == SerializationContext().deserialize(SerializationContext().serialize(x))).all() + + +def test_can_serialize_numpy_array_from_list(): + x = numpy.array([1, 2, 3]) + assert (x == SerializationContext().deserialize(SerializationContext().serialize(x))).all() + + +def test_can_serialize_numpy_array_constructor(): + assert numpy.array == SerializationContext().deserialize(SerializationContext().serialize(numpy.array)) diff --git a/typed_python/types_serialization_test.py b/typed_python/types_serialization_test.py index c5f33c2a..5f7e4423 100644 --- a/typed_python/types_serialization_test.py +++ b/typed_python/types_serialization_test.py @@ -1339,6 +1339,29 @@ def f(self, x=10): self.assertLess(currentMemUsageMb(), usage+.5) + def test_serialize_class_with_bound_methods(self): + class SomeClass: + pass + + class SomeSubclass(SomeClass): + def __init__(self, x): + self.x = x + + class ClassWithBoundMethod(Class, Final): + x = Member(OneOf(None, SomeClass)) + + def __init__(self): + self.x = None + + def increment(self, y): + if self.x is None: + self.x = SomeSubclass(y) + else: + self.x = SomeSubclass(self.x.x + y) + + self.assertEqual(ClassWithBoundMethod, ping_pong(ClassWithBoundMethod)) + self.assertEqual(ClassWithBoundMethod.increment, ping_pong(ClassWithBoundMethod.increment)) + def test_serialize_named_tuples_with_extra_fields(self): T1 = NamedTuple(x=int) T2 = NamedTuple(x=int, y=float, z=str)