Rust library cleanup

* Fix error code extraction from Python to Rust
* Add documentation for dealing with HCI packets
This commit is contained in:
Gabriel White-Vega
2023-10-11 10:32:33 -04:00
parent dedc0aca54
commit ae23ef7b9b
4 changed files with 93 additions and 3 deletions

View File

@@ -28,7 +28,7 @@ use bumble::wrapper::{
};
use pyo3::{
exceptions::PyException,
{PyErr, PyResult},
FromPyObject, IntoPy, Python, {PyErr, PyResult},
};
#[pyo3_asyncio::tokio::test]
@@ -78,6 +78,28 @@ async fn test_hci_roundtrip_success_and_failure() -> PyResult<()> {
Ok(())
}
#[pyo3_asyncio::tokio::test]
fn valid_error_code_extraction_succeeds() -> PyResult<()> {
let error_code = Python::with_gil(|py| {
let python_error_code_success = 0x00_u8.into_py(py);
ErrorCode::extract(python_error_code_success.as_ref(py))
})?;
assert_eq!(ErrorCode::Success, error_code);
Ok(())
}
#[pyo3_asyncio::tokio::test]
fn invalid_error_code_extraction_fails() -> PyResult<()> {
let failed_extraction = Python::with_gil(|py| {
let python_invalid_error_code = 0xFE_u8.into_py(py);
ErrorCode::extract(python_invalid_error_code.as_ref(py))
});
assert!(failed_extraction.is_err());
Ok(())
}
async fn create_local_device(address: Address) -> PyResult<Device> {
let link = Link::new_local_link()?;
let controller = Controller::new("C1", None, None, Some(link), Some(address.clone())).await?;