def test_type_create_from_numpy_dtypes(np): assert Type(np.dtype("void")) == Type.void assert Type(np.dtype("bool")) == Type.bool8 assert Type(np.dtype("int8")) == Type.int8 assert Type(np.dtype("int16")) == Type.int16 assert Type(np.dtype("int32")) == Type.int32 assert Type(np.dtype("int64")) == Type.int64 assert Type(np.dtype("float16")) == Type.float32 assert Type(np.dtype("float32")) == Type.float32 assert Type(np.dtype("float64")) == Type.float64 assert Type(np.dtype("str")) == Type.str32
def test_type_create_from_numpy_classes(np): assert Type(np.void) == Type.void assert Type(np.bool_) == Type.bool8 assert Type(np.int8) == Type.int8 assert Type(np.int16) == Type.int16 assert Type(np.int32) == Type.int32 assert Type(np.int64) == Type.int64 assert Type(np.float16) == Type.float32 assert Type(np.float32) == Type.float32 assert Type(np.float64) == Type.float64 assert Type(np.str_) == Type.str32
def test_type_create_invalid(): msg = "Cannot create Type object from" with pytest.raises(ValueError, match=msg): Type(0) with pytest.raises(ValueError, match=msg): Type(0.5) with pytest.raises(ValueError, match=msg): Type("nothing") with pytest.raises(ValueError, match=msg): Type(type) with pytest.raises(TypeError): Type()
def test_type_create_from_python_types(): assert Type(None) == Type.void assert Type(bool) == Type.bool8 assert Type(int) == Type.int64 assert Type(float) == Type.float64 assert Type(str) == Type.str32 assert Type(object) == Type.obj64
def test_type_create_from_names(): assert Type("void") == Type.void assert Type("bool8") == Type.bool8 assert Type("int8") == Type.int8 assert Type("int16") == Type.int16 assert Type("int32") == Type.int32 assert Type("int64") == Type.int64 assert Type("float32") == Type.float32 assert Type("float64") == Type.float64 assert Type("str32") == Type.str32 assert Type("str64") == Type.str64 assert Type("obj64") == Type.obj64
def test_type_create_from_strings(): assert Type("V") == Type.void assert Type("bool") == Type.bool8 assert Type("boolean") == Type.bool8 assert Type("int") == Type.int64 assert Type("integer") == Type.int64 assert Type("float") == Type.float32 assert Type("double") == Type.float64 assert Type("<U") == Type.str32 assert Type("str") == Type.str32 assert Type("string") == Type.str32 assert Type("obj") == Type.obj64 assert Type("object") == Type.obj64
def test_type_create_from_types(): assert Type(Type.void) == Type.void assert Type(Type.bool8) == Type.bool8 assert Type(Type.int8) == Type.int8 assert Type(Type.int16) == Type.int16 assert Type(Type.int32) == Type.int32 assert Type(Type.int64) == Type.int64 assert Type(Type.float32) == Type.float32 assert Type(Type.float64) == Type.float64 assert Type(Type.str32) == Type.str32 assert Type(Type.str64) == Type.str64 assert Type(Type.obj64) == Type.obj64