| 310 | |
| 311 | #[test] |
| 312 | fn test_conversion_error() { |
| 313 | Python::attach(|py| { |
| 314 | let conversion_error = wrap_pyfunction!(conversion_error)(py).unwrap(); |
| 315 | py_expect_exception!( |
| 316 | py, |
| 317 | conversion_error, |
| 318 | "conversion_error(None, None, None, None, None)", |
| 319 | PyTypeError, |
| 320 | "'None' is not an instance of 'str'", |
| 321 | "while processing 'str_arg'" |
| 322 | ); |
| 323 | py_expect_exception!( |
| 324 | py, |
| 325 | conversion_error, |
| 326 | "conversion_error(100, None, None, None, None)", |
| 327 | PyTypeError, |
| 328 | "'int' object is not an instance of 'str'", |
| 329 | "while processing 'str_arg'" |
| 330 | ); |
| 331 | py_expect_exception!( |
| 332 | py, |
| 333 | conversion_error, |
| 334 | "conversion_error('string1', 'string2', None, None, None)", |
| 335 | PyTypeError, |
| 336 | "'str' object cannot be interpreted as an integer", |
| 337 | "while processing 'int_arg'" |
| 338 | ); |
| 339 | py_expect_exception!( |
| 340 | py, |
| 341 | conversion_error, |
| 342 | "conversion_error('string1', -100, 'string2', None, None)", |
| 343 | PyTypeError, |
| 344 | "'str' object is not an instance of 'tuple'", |
| 345 | "while processing 'tuple_arg'" |
| 346 | ); |
| 347 | py_expect_exception!( |
| 348 | py, |
| 349 | conversion_error, |
| 350 | "conversion_error('string1', -100, ('string2', 10.), 'string3', None)", |
| 351 | PyTypeError, |
| 352 | "'str' object cannot be interpreted as an integer", |
| 353 | "while processing 'option_arg'" |
| 354 | ); |
| 355 | let exception = py_expect_exception!( |
| 356 | py, |
| 357 | conversion_error, |
| 358 | " |
| 359 | class ValueClass: |
| 360 | def __init__(self, value): |
| 361 | self.value = value |
| 362 | conversion_error('string1', -100, ('string2', 10.), None, ValueClass(\"no_expected_type\"))", |
| 363 | PyTypeError |
| 364 | ); |
| 365 | if exception.value(py).hasattr("add_note").unwrap() { |
| 366 | assert_eq!( |
| 367 | exception |
| 368 | .value(py) |
| 369 | .getattr("__notes__") |