From 7d16bad5a94315d02d74d5333d32d395d9d52267 Mon Sep 17 00:00:00 2001 From: Tim Ohliger Date: Fri, 6 Sep 2024 18:06:54 +0200 Subject: [PATCH] Added unit test for list/vector of paths. --- tests/test_stl.cpp | 7 +++++++ tests/test_stl.py | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/tests/test_stl.cpp b/tests/test_stl.cpp index dd93d51d0..08456b3c0 100644 --- a/tests/test_stl.cpp +++ b/tests/test_stl.cpp @@ -454,6 +454,13 @@ TEST_SUBMODULE(stl, m) { // test_fs_path m.attr("has_filesystem") = true; m.def("parent_path", [](const std::filesystem::path &p) { return p.parent_path(); }); + m.def("parent_paths", [](const std::vector &p) { + std::vector result; + for (const auto &i : p) { + result.push_back(i.parent_path()); + } + return result; + }); #endif #ifdef PYBIND11_TEST_VARIANT diff --git a/tests/test_stl.py b/tests/test_stl.py index d2d89420f..2c3172703 100644 --- a/tests/test_stl.py +++ b/tests/test_stl.py @@ -265,6 +265,11 @@ def test_fs_path(doc): doc(m.parent_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 ")