-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Execute UniFFI bindings via a simple Python test (#87)
This uses the UniFFI test helpers to make the `libmls_rs_uniffi.so` file available to the Python script. I would have liked to use `$CARGO_TARGET_TMPDIR` to place the temporary files in a stable place under `target/`, but this variable is only set for integration tests, not unit tests. So the script now ends up somewhere in your system temp directory. We could decide to only use integration tests for these tests, let me know what you think! The test is very simple here: it simply executes the Python script, which then has to return with a zero exit code. If it fails, the output is printed and you then have to debug the Python code by hand. Related to #81.
- Loading branch information
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use uniffi_bindgen::bindings::python; | ||
|
||
/// Run Python code in `script`. | ||
/// | ||
/// The script can use `import mls_rs_uniffi` to get access to the | ||
/// Python bindings. | ||
pub fn run_python(script: &str) -> Result<(), Box<dyn std::error::Error>> { | ||
let tmp_dir = tempfile::TempDir::with_prefix("run-python-")?; | ||
let script_path = tmp_dir.path().join("script.py"); | ||
std::fs::write(&script_path, script)?; | ||
|
||
python::run_script( | ||
tmp_dir.path().to_str().unwrap(), | ||
"mls-rs-uniffi", | ||
script_path.to_str().unwrap(), | ||
vec![], | ||
&uniffi_bindgen::bindings::RunScriptOptions::default(), | ||
)?; | ||
|
||
Ok(()) | ||
} |