Add some additional test cases to `test_methods`
This commit is contained in:
parent
8e4e446e32
commit
31ff8356b6
|
@ -176,6 +176,11 @@ struct MethArgs {
|
|||
#[pymethods]
|
||||
impl MethArgs {
|
||||
|
||||
#[args(test)]
|
||||
fn get_optional(&self, test: Option<i32>) -> PyResult<i32> {
|
||||
Ok(test.unwrap_or(10))
|
||||
}
|
||||
|
||||
#[args(test="10")]
|
||||
fn get_default(&self, test: i32) -> PyResult<i32> {
|
||||
Ok(test)
|
||||
|
@ -196,6 +201,8 @@ fn meth_args() {
|
|||
let py = gil.python();
|
||||
let inst = py.init(|t| MethArgs{token: t}).unwrap();
|
||||
|
||||
py_run!(py, inst, "assert inst.get_optional() == 10");
|
||||
py_run!(py, inst, "assert inst.get_optional(100) == 100");
|
||||
py_run!(py, inst, "assert inst.get_default() == 10");
|
||||
py_run!(py, inst, "assert inst.get_default(100) == 100");
|
||||
py_run!(py, inst, "assert inst.get_kwarg() == 10");
|
||||
|
@ -206,4 +213,4 @@ fn meth_args() {
|
|||
py_run!(py, inst, "assert inst.get_kwargs(t=1,n=2) == [(), {'t': 1, 'n': 2}]");
|
||||
py_run!(py, inst, "assert inst.get_kwargs(1,2,3,t=1,n=2) == [(1,2,3), {'t': 1, 'n': 2}]");
|
||||
// py_expect_exception!(py, inst, "inst.get_kwarg(100)", TypeError);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ fn test_module_with_functions() {
|
|||
|
||||
let d = PyDict::new(py);
|
||||
d.set_item("module_with_functions", unsafe { PyObject::from_owned_ptr(py, PyInit_module_with_functions()) }).unwrap();
|
||||
py.run("assert module_with_functions.__doc__.strip() == 'This module is implemented in Rust.'", None, Some(d)).unwrap();
|
||||
py.run("assert module_with_functions.__doc__ == 'This module is implemented in Rust.'", None, Some(d)).unwrap();
|
||||
py.run("assert module_with_functions.sum_as_string(1, 2) == '3'", None, Some(d)).unwrap();
|
||||
py.run("assert module_with_functions.no_parameters() == 42", None, Some(d)).unwrap();
|
||||
py.run("assert module_with_functions.foo == 'bar'", None, Some(d)).unwrap();
|
||||
|
|
Loading…
Reference in New Issue