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

Function test_seq_repeat

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

Source from the content-addressed store, hash-verified

549
550 #[test]
551 fn test_seq_repeat() {
552 let gil = Python::acquire_gil();
553 let py = gil.python();
554 let v = vec!["foo", "bar"];
555 let seq = v
556 .to_py_object(py)
557 .into_object()
558 .cast_into::<PySequence>(py)
559 .unwrap();
560 let repeat_seq = seq
561 .repeat(py, 3)
562 .unwrap()
563 .cast_into::<PySequence>(py)
564 .unwrap();
565 assert_eq!(6, repeat_seq.len(py).unwrap());
566 let repeated = vec!["foo", "bar", "foo", "bar", "foo", "bar"];
567 for (el, rpt) in seq.iter(py).unwrap().zip(repeated.iter()) {
568 assert_eq!(*rpt, el.unwrap().extract::<String>(py).unwrap());
569 }
570 }
571
572 #[test]
573 fn test_list_coercion() {

Callers

nothing calls this directly

Calls 5

pythonMethod · 0.80
repeatMethod · 0.80
into_objectMethod · 0.45
to_py_objectMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected