GCC Code Coverage Report


Directory: ./
File: bindings/python/utils/path.cpp
Date: 2025-02-12 21:03:38
Exec Total Coverage
Lines: 19 23 82.6%
Branches: 28 80 35.0%

Line Branch Exec Source
1 //
2 // Copyright (c) 2024 CNRS
3 //
4
5 #include "pinocchio/bindings/python/utils/path.hpp"
6
7 namespace pinocchio
8 {
9 namespace python
10 {
11 namespace bp = boost::python;
12
13 147 std::string path(const bp::object & path)
14 {
15
16
1/2
✓ Branch 1 taken 147 times.
✗ Branch 2 not taken.
147 auto str_path = path;
17
4/8
✓ Branch 1 taken 147 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 147 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 147 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 147 times.
✗ Branch 11 not taken.
294 const bp::object Path = bp::import("pathlib").attr("Path");
18
19
3/4
✓ Branch 3 taken 147 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 131 times.
✓ Branch 6 taken 16 times.
147 if (PyObject_IsInstance(str_path.ptr(), Path.ptr()))
20
3/6
✓ Branch 1 taken 131 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 131 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 131 times.
✗ Branch 8 not taken.
131 str_path = str_path.attr("__str__")();
21
22
2/4
✓ Branch 2 taken 147 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 147 times.
147 if (!PyObject_IsInstance(str_path.ptr(), reinterpret_cast<PyObject *>(&PyUnicode_Type)))
23 {
24 std::string what = bp::extract<std::string>(str_path.attr("__str__")())();
25 throw std::invalid_argument(what + " is neither a Path nor a str.");
26 }
27
28
3/6
✓ Branch 1 taken 147 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 147 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 147 times.
✗ Branch 8 not taken.
441 return bp::extract<std::string>(str_path);
29 147 };
30
31 22 std::vector<std::string> pathList(const bp::object & path_list)
32 {
33
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 22 times.
22 if (!PyList_Check(path_list.ptr()))
34 {
35 std::string what = bp::extract<std::string>(path_list.attr("__str__")())();
36 throw std::invalid_argument(what + " is not a list.");
37 }
38
39 // Retrieve the underlying list
40
2/4
✓ Branch 3 taken 22 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 22 times.
✗ Branch 7 not taken.
22 bp::object bp_obj(bp::handle<>(bp::borrowed(path_list.ptr())));
41
1/2
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
22 bp::list bp_list(bp_obj);
42
1/2
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
22 bp::ssize_t list_size = bp::len(bp_list);
43
44 22 std::vector<std::string> path_vec;
45
1/2
✓ Branch 1 taken 22 times.
✗ Branch 2 not taken.
22 path_vec.reserve(list_size);
46 // Check if all the elements contained in the current vector is of type T
47
2/2
✓ Branch 0 taken 23 times.
✓ Branch 1 taken 22 times.
45 for (bp::ssize_t k = 0; k < list_size; ++k)
48 {
49
4/8
✓ Branch 1 taken 23 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 23 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 23 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 23 times.
✗ Branch 11 not taken.
23 path_vec.push_back(path(bp_list[k]));
50 }
51 44 return path_vec;
52 22 };
53 } // namespace python
54 } // namespace pinocchio
55