File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -548,4 +548,7 @@ TEST_SUBMODULE(stl, m) {
548548 []() { return new std::vector<bool >(4513 ); },
549549 // Without explicitly specifying `take_ownership`, this function leaks.
550550 py::return_value_policy::take_ownership);
551+
552+ m.def (" pass_std_vector_int" , [](const std::vector<int > &vec_int) { return vec_int.size (); });
553+ m.def (" pass_std_set_int" , [](const std::set<int > &set_int) { return set_int.size (); });
551554}
Original file line number Diff line number Diff line change @@ -379,3 +379,32 @@ def test_return_vector_bool_raw_ptr():
379379 v = m .return_vector_bool_raw_ptr ()
380380 assert isinstance (v , list )
381381 assert len (v ) == 4513
382+
383+
384+ def test_pass_std_vector_int ():
385+ fn = m .pass_std_vector_int
386+ assert fn ([1 , 2 ]) == 2
387+ assert fn ((1 , 2 )) == 2
388+ with pytest .raises (TypeError ):
389+ fn (set ())
390+ with pytest .raises (TypeError ):
391+ fn ({})
392+ with pytest .raises (TypeError ):
393+ fn ({}.keys ())
394+ with pytest .raises (TypeError ):
395+ fn (i for i in range (3 ))
396+
397+
398+ def test_pass_std_set_int ():
399+ fn = m .pass_std_set_int
400+ assert fn ({1 , 2 }) == 2
401+ with pytest .raises (TypeError ):
402+ fn ([1 , 2 ])
403+ with pytest .raises (TypeError ):
404+ fn ((1 , 2 ))
405+ with pytest .raises (TypeError ):
406+ fn ({})
407+ with pytest .raises (TypeError ):
408+ fn ({}.keys ())
409+ with pytest .raises (TypeError ):
410+ fn (i for i in range (3 ))
You can’t perform that action at this time.
0 commit comments