MCPcopy Create free account
hub / github.com/dgrunwald/rust-cpython / test_seq_contains

Function test_seq_contains

src/objects/sequence.rs:358–377  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

356
357 #[test]
358 fn test_seq_contains() {
359 let gil = Python::acquire_gil();
360 let py = gil.python();
361 let v: Vec<i32> = vec![1, 1, 2, 3, 5, 8];
362 let seq = v
363 .to_py_object(py)
364 .into_object()
365 .cast_into::<PySequence>(py)
366 .unwrap();
367 assert_eq!(6, seq.len(py).unwrap());
368
369 let bad_needle = 7i32.to_py_object(py).into_object();
370 assert_eq!(false, seq.contains(py, &bad_needle).unwrap());
371
372 let good_needle = 8i32.to_py_object(py).into_object();
373 assert_eq!(true, seq.contains(py, &good_needle).unwrap());
374
375 let type_coerced_needle = 8f32.to_py_object(py).into_object();
376 assert_eq!(true, seq.contains(py, &type_coerced_needle).unwrap());
377 }
378
379 #[test]
380 fn test_seq_get_item() {

Callers

nothing calls this directly

Calls 3

pythonMethod · 0.80
into_objectMethod · 0.45
to_py_objectMethod · 0.45

Tested by

no test coverage detected