Skip to content

Commit

Permalink
Replace extract with downcast for ros2-beidge
Browse files Browse the repository at this point in the history
  • Loading branch information
haixuanTao committed Sep 27, 2024
1 parent 0a91ce3 commit ee45beb
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions libraries/extensions/ros2-bridge/python/src/typed/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ mod tests {
use arrow::pyarrow::FromPyArrow;
use arrow::pyarrow::ToPyArrow;

use eyre::eyre;
use pyo3::types::IntoPyDict;
use pyo3::types::PyAnyMethods;
use pyo3::types::PyDict;
use pyo3::types::PyList;
use pyo3::types::PyListMethods;
use pyo3::types::PyModule;
use pyo3::types::PyTuple;
use pyo3::PyNativeType;

use pyo3::Python;
use serde::de::DeserializeSeed;
use serde::Serialize;
Expand Down Expand Up @@ -71,9 +73,14 @@ mod tests {

let my_module = PyModule::import_bound(py, "test_utils")?;

let arrays: &PyList = my_module.getattr("TEST_ARRAYS")?.extract()?;
let arrays = my_module.getattr("TEST_ARRAYS")?;
let arrays = arrays
.downcast::<PyList>()
.map_err(|err| eyre!("Could not downcast PyAny. Err: {}", err))?;
for array_wrapper in arrays.iter() {
let arrays: &PyTuple = array_wrapper.extract()?;
let arrays = array_wrapper.downcast::<PyTuple>().map_err(|err| {
eyre!("Could not downcast expected tuple test array. Err: {}", err)
})?;
let package_name: String = arrays.get_item(0)?.extract()?;
let message_name: String = arrays.get_item(1)?.extract()?;
println!("Checking {}::{}", package_name, message_name);
Expand Down

0 comments on commit ee45beb

Please sign in to comment.