-
Notifications
You must be signed in to change notification settings - Fork 782
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for extracting PathBuf from pathlib.Path
- Loading branch information
Showing
4 changed files
with
59 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use pyo3::prelude::*; | ||
use pyo3::wrap_pyfunction; | ||
use std::path::{Path, PathBuf}; | ||
|
||
#[pyfunction] | ||
fn make_path() -> PathBuf { | ||
Path::new("/root").to_owned() | ||
} | ||
|
||
#[pyfunction] | ||
fn take_pathbuf(path: PathBuf) -> PathBuf { | ||
path | ||
} | ||
|
||
#[pymodule] | ||
fn path(_py: Python<'_>, m: &PyModule) -> PyResult<()> { | ||
m.add_function(wrap_pyfunction!(make_path, m)?)?; | ||
m.add_function(wrap_pyfunction!(take_pathbuf, m)?)?; | ||
|
||
Ok(()) | ||
} |
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,18 @@ | ||
import pathlib | ||
|
||
import pyo3_pytests.path as rpath | ||
|
||
|
||
def test_make_path(): | ||
p = rpath.make_path() | ||
assert p == "/root" | ||
|
||
|
||
def test_take_pathbuf(): | ||
p = "/root" | ||
assert rpath.take_pathbuf(p) == p | ||
|
||
|
||
def test_take_pathlib(): | ||
p = pathlib.Path("/root") | ||
assert rpath.take_pathbuf(p) == str(p) |
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