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

Function test_seq_get_item

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

Source from the content-addressed store, hash-verified

378
379 #[test]
380 fn test_seq_get_item() {
381 let gil = Python::acquire_gil();
382 let py = gil.python();
383 let v: Vec<i32> = vec![1, 1, 2, 3, 5, 8];
384 let seq = v
385 .to_py_object(py)
386 .into_object()
387 .cast_into::<PySequence>(py)
388 .unwrap();
389 assert_eq!(1, seq.get_item(py, 0).unwrap().extract::<i32>(py).unwrap());
390 assert_eq!(1, seq.get_item(py, 1).unwrap().extract::<i32>(py).unwrap());
391 assert_eq!(2, seq.get_item(py, 2).unwrap().extract::<i32>(py).unwrap());
392 assert_eq!(3, seq.get_item(py, 3).unwrap().extract::<i32>(py).unwrap());
393 assert_eq!(5, seq.get_item(py, 4).unwrap().extract::<i32>(py).unwrap());
394 assert_eq!(8, seq.get_item(py, 5).unwrap().extract::<i32>(py).unwrap());
395 assert_eq!(8, seq.get_item(py, -1).unwrap().extract::<i32>(py).unwrap());
396 assert_eq!(5, seq.get_item(py, -2).unwrap().extract::<i32>(py).unwrap());
397 assert_eq!(3, seq.get_item(py, -3).unwrap().extract::<i32>(py).unwrap());
398 assert_eq!(2, seq.get_item(py, -4).unwrap().extract::<i32>(py).unwrap());
399 assert_eq!(1, seq.get_item(py, -5).unwrap().extract::<i32>(py).unwrap());
400 assert!(seq.get_item(py, 10).is_err());
401 }
402
403 // fn test_get_slice() {}
404 // fn test_set_slice() {}

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