diff --git a/tests/test_methods.rs b/tests/test_methods.rs index ec983842..872f3c0b 100644 --- a/tests/test_methods.rs +++ b/tests/test_methods.rs @@ -176,6 +176,11 @@ struct MethArgs { #[pymethods] impl MethArgs { + #[args(test)] + fn get_optional(&self, test: Option) -> PyResult { + Ok(test.unwrap_or(10)) + } + #[args(test="10")] fn get_default(&self, test: i32) -> PyResult { 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); -} \ No newline at end of file +} diff --git a/tests/test_module.rs b/tests/test_module.rs index 66e24f94..086ab040 100644 --- a/tests/test_module.rs +++ b/tests/test_module.rs @@ -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();