Skip to content

Commit 4a71fc5

Browse files
committed
Fix issue with Rust test driver for Python unit tests
1 parent eb5dffe commit 4a71fc5

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/pyskani/tests/unittest.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ extern crate pyo3;
22
extern crate pyskani;
33

44
use std::path::Path;
5+
use std::str::FromStr;
56

67
use pyo3::prelude::*;
78
use pyo3::types::PyDict;
@@ -12,6 +13,8 @@ use pyo3::Python;
1213
pub fn main() -> PyResult<()> {
1314
// get the relative path to the project folder
1415
let folder = Path::new(file!())
16+
.canonicalize()
17+
.unwrap()
1518
.parent()
1619
.unwrap()
1720
.parent()
@@ -27,21 +30,16 @@ pub fn main() -> PyResult<()> {
2730
Python::with_gil(|py| {
2831
// insert the project folder in `sys.modules` so that
2932
// the main module can be imported by Python
30-
let sys = py.import("sys").unwrap();
31-
sys.getattr("path")
32-
.unwrap()
33-
.downcast::<PyList>()
34-
.unwrap()
35-
.insert(0, folder)
36-
.unwrap();
33+
let sys = py.import("sys")?;
34+
sys.getattr("path")?
35+
.downcast::<PyList>()?
36+
.insert(0, folder.to_str().unwrap())?;
3737

3838
// create a Python module from our rust code with debug symbols
39-
let module = PyModule::new(py, "pyskani._skani").unwrap();
40-
pyskani::init(py, &module).unwrap();
41-
sys.getattr("modules")
42-
.unwrap()
43-
.downcast::<PyDict>()
44-
.unwrap()
39+
let module = PyModule::new(py, "pyskani._skani")?;
40+
pyskani::init(py, &module)?;
41+
sys.getattr("modules")?
42+
.downcast::<PyDict>()?
4543
.set_item("pyskani._skani", module)
4644
.unwrap();
4745

0 commit comments

Comments
 (0)