Skip to content

Commit 9a885e2

Browse files
committed
Add tests for python and numpy casting
1 parent a37617b commit 9a885e2

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

mojo/stdlib/test/python/test_python_to_mojo.mojo

+37
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,45 @@ fn test_python_to_string() raises:
5757
assert_true(String(os.environ).startswith("environ({"))
5858

5959

60+
fn test_python_to_int() raises:
61+
var py_int = PythonObject(1)
62+
var mojo_int = Int(1)
63+
assert_equal(Int(py_int), mojo_int)
64+
65+
66+
fn test_python_to_float() raises:
67+
var py_float = PythonObject(1.0)
68+
var mojo_float = Float64(1.0)
69+
assert_equal(Float64(py_float), mojo_float)
70+
71+
72+
fn test_python_to_bool() raises:
73+
var py_bool = PythonObject(True)
74+
var mojo_bool = Bool(True)
75+
assert_equal(Bool(py_bool), mojo_bool)
76+
77+
78+
fn test_python_numpy_int_to_mojo_int() raises:
79+
var np = Python.import_module("numpy")
80+
var py_numpy_int = np.int64(1)
81+
var mojo_int = Int(1)
82+
assert_equal(Int(py_numpy_int), mojo_int)
83+
84+
85+
fn test_python_numpy_float_to_mojo_float() raises:
86+
var np = Python.import_module("numpy")
87+
var py_numpy_float = np.float64(1.0)
88+
var mojo_float = Float64(1.0)
89+
assert_equal(Float64(py_numpy_float), mojo_float)
90+
91+
6092
def main():
6193
var python = Python()
6294
test_string_to_python_to_mojo(python)
6395
test_range()
6496
test_python_to_string()
97+
test_python_to_int()
98+
test_python_to_float()
99+
test_python_to_bool()
100+
test_python_numpy_int_to_mojo_int()
101+
test_python_numpy_float_to_mojo_float()

0 commit comments

Comments
 (0)