2022-09-18 18:09:23 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from pyo3_pytests import sequence
|
|
|
|
|
|
|
|
|
|
|
|
def test_vec_from_list_i32():
|
|
|
|
assert sequence.vec_to_vec_i32([1, 2, 3]) == [1, 2, 3]
|
|
|
|
|
|
|
|
|
|
|
|
def test_vec_from_list_pystring():
|
|
|
|
assert sequence.vec_to_vec_pystring(["1", "2", "3"]) == ["1", "2", "3"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_vec_from_bytes():
|
|
|
|
assert sequence.vec_to_vec_i32(b"123") == [49, 50, 51]
|
|
|
|
|
|
|
|
|
|
|
|
def test_vec_from_str():
|
2022-10-14 01:14:44 +00:00
|
|
|
with pytest.raises(TypeError):
|
2022-09-18 18:09:23 +00:00
|
|
|
sequence.vec_to_vec_pystring("123")
|
|
|
|
|
|
|
|
|
|
|
|
def test_vec_from_array():
|
2023-07-22 20:38:57 +00:00
|
|
|
# binary numpy wheel not available on all platforms
|
|
|
|
numpy = pytest.importorskip("numpy")
|
2022-09-18 18:09:23 +00:00
|
|
|
|
|
|
|
assert sequence.vec_to_vec_i32(numpy.array([1, 2, 3])) == [1, 2, 3]
|
2022-10-11 16:05:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_rust_array_from_array():
|
2023-07-22 20:38:57 +00:00
|
|
|
# binary numpy wheel not available on all platforms
|
|
|
|
numpy = pytest.importorskip("numpy")
|
2022-10-11 16:05:02 +00:00
|
|
|
|
|
|
|
assert sequence.array_to_array_i32(numpy.array([1, 2, 3])) == [1, 2, 3]
|