Merge pull request #355 from PyO3/pytuple_3
Into PyTuple tests, third attempt
This commit is contained in:
commit
61194abf1c
|
@ -1,5 +1,6 @@
|
|||
use pyo3::prelude::*;
|
||||
use pyo3::types::PyDict;
|
||||
use pyo3::types::PyTuple;
|
||||
use pyo3::wrap_pyfunction;
|
||||
use std::isize;
|
||||
|
||||
|
@ -62,3 +63,59 @@ fn return_custom_class() {
|
|||
let get_zero = wrap_pyfunction!(get_zero)(py);
|
||||
py_assert!(py, get_zero, "get_zero().value == 0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn intopytuple_primitive() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let tup = (1, 2, "foo");
|
||||
py_assert!(py, tup, "tup == (1, 2, 'foo')");
|
||||
py_assert!(py, tup, "tup[0] == 1");
|
||||
py_assert!(py, tup, "tup[1] == 2");
|
||||
py_assert!(py, tup, "tup[2] == 'foo'");
|
||||
}
|
||||
|
||||
#[pyclass]
|
||||
struct SimplePyClass {}
|
||||
|
||||
#[test]
|
||||
fn intopytuple_pyclass() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let tup = (
|
||||
PyRef::new(py, SimplePyClass {}).unwrap(),
|
||||
PyRef::new(py, SimplePyClass {}).unwrap(),
|
||||
);
|
||||
py_assert!(py, tup, "type(tup[0]).__name__ == 'SimplePyClass'");
|
||||
py_assert!(py, tup, "type(tup[0]).__name__ == type(tup[1]).__name__");
|
||||
py_assert!(py, tup, "tup[0] != tup[1]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pytuple_primitive_iter() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let tup = PyTuple::new(py, [1u32, 2, 3].into_iter());
|
||||
py_assert!(py, tup, "tup == (1, 2, 3)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pytuple_pyclass_iter() {
|
||||
let gil = Python::acquire_gil();
|
||||
let py = gil.python();
|
||||
|
||||
let tup = PyTuple::new(
|
||||
py,
|
||||
[
|
||||
PyRef::new(py, SimplePyClass {}).unwrap(),
|
||||
PyRef::new(py, SimplePyClass {}).unwrap(),
|
||||
]
|
||||
.into_iter(),
|
||||
);
|
||||
py_assert!(py, tup, "type(tup[0]).__name__ == 'SimplePyClass'");
|
||||
py_assert!(py, tup, "type(tup[0]).__name__ == type(tup[0]).__name__");
|
||||
py_assert!(py, tup, "tup[0] != tup[1]");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue