Added unit test for list/vector of paths.

This commit is contained in:
Tim Ohliger 2024-09-06 18:06:54 +02:00
parent 23ceaba974
commit 7d16bad5a9
2 changed files with 12 additions and 0 deletions

View File

@ -454,6 +454,13 @@ TEST_SUBMODULE(stl, m) {
// test_fs_path // test_fs_path
m.attr("has_filesystem") = true; m.attr("has_filesystem") = true;
m.def("parent_path", [](const std::filesystem::path &p) { return p.parent_path(); }); m.def("parent_path", [](const std::filesystem::path &p) { return p.parent_path(); });
m.def("parent_paths", [](const std::vector<std::filesystem::path> &p) {
std::vector<std::filesystem::path> result;
for (const auto &i : p) {
result.push_back(i.parent_path());
}
return result;
});
#endif #endif
#ifdef PYBIND11_TEST_VARIANT #ifdef PYBIND11_TEST_VARIANT

View File

@ -265,6 +265,11 @@ def test_fs_path(doc):
doc(m.parent_path) doc(m.parent_path)
== "parent_path(arg0: Union[os.PathLike, str, bytes]) -> Path" == "parent_path(arg0: Union[os.PathLike, str, bytes]) -> Path"
) )
assert m.parent_paths(["foo/bar", "foo/baz"]) == [Path("foo"), Path("foo")]
assert (
doc(m.parent_paths)
== "parent_paths(arg0: list[Union[os.PathLike, str, bytes]]) -> list[Path]"
)
@pytest.mark.skipif(not hasattr(m, "load_variant"), reason="no <variant>") @pytest.mark.skipif(not hasattr(m, "load_variant"), reason="no <variant>")