From 1ca23ca4cf27201c142b6bd5b47026f672110711 Mon Sep 17 00:00:00 2001 From: Tom Date: Wed, 19 Feb 2025 15:08:21 +0000 Subject: [PATCH] Add a basic rust test in --- src/rust/lib.rs | 21 ++++++++++++++++++--- tests/test_rust.py | 5 +++++ 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 tests/test_rust.py diff --git a/src/rust/lib.rs b/src/rust/lib.rs index ab2d34e..865bacd 100644 --- a/src/rust/lib.rs +++ b/src/rust/lib.rs @@ -1,7 +1,24 @@ -// #![allow(unused_imports)] +#![allow(unused_imports)] // #![allow(dead_code)] // #![allow(unused_variables)] + +use pyo3::prelude::*; +use pyo3::wrap_pyfunction; +use pyo3::types::{PyDict, PyInt, PyList, PyString}; + +#[pyfunction] +fn hello(_py: Python, name: &str) -> PyResult { + Ok(format!("Hello, {}!", name)) +} + +#[pymodule] +fn rust(m: &Bound<'_, PyModule>) -> PyResult<()> { + m.add_function(wrap_pyfunction!(hello, m)?).unwrap(); + Ok(()) +} + + // use rsfdb::listiterator::KeyValueLevel; // use rsfdb::request::Request; // use rsfdb::FDB; @@ -9,8 +26,6 @@ // use serde_json::{json, Value}; // use std::time::Instant; -// use pyo3::prelude::*; -// use pyo3::types::{PyDict, PyInt, PyList, PyString}; // use std::collections::HashMap; diff --git a/tests/test_rust.py b/tests/test_rust.py new file mode 100644 index 0000000..0931c5e --- /dev/null +++ b/tests/test_rust.py @@ -0,0 +1,5 @@ +from qubed.rust import hello + + +def test_hello(): + assert hello("World") == "Hello, World!" \ No newline at end of file