Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
34b7b54f
Commit
34b7b54f
authored
May 09, 2017
by
Andreas Bergmeier
Committed by
Dean Moldovan
Jun 27, 2017
Browse files
Add tests for passing STL containers by pointer
`nullptr` is not expected to work in this case.
parent
c67033a9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
0 deletions
+25
-0
tests/test_stl.cpp
tests/test_stl.cpp
+2
-0
tests/test_stl.py
tests/test_stl.py
+23
-0
No files found.
tests/test_stl.cpp
View file @
34b7b54f
...
...
@@ -160,4 +160,6 @@ TEST_SUBMODULE(stl, m) {
};
});
// test_stl_pass_by_pointer
m
.
def
(
"stl_pass_by_pointer"
,
[](
std
::
vector
<
int
>*
v
)
{
return
*
v
;
},
"v"
_a
=
nullptr
);
}
tests/test_stl.py
View file @
34b7b54f
...
...
@@ -131,3 +131,26 @@ def test_vec_of_reference_wrapper():
"""#171: Can't return reference wrappers (or STL structures containing them)"""
assert
str
(
m
.
return_vec_of_reference_wrapper
(
UserType
(
4
)))
==
\
"[UserType(1), UserType(2), UserType(3), UserType(4)]"
def
test_stl_pass_by_pointer
(
msg
):
"""Passing nullptr or None to an STL container pointer is not expected to work"""
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
m
.
stl_pass_by_pointer
()
# default value is `nullptr`
assert
msg
(
excinfo
.
value
)
==
"""
stl_pass_by_pointer(): incompatible function arguments. The following argument types are supported:
1. (v: List[int]=None) -> List[int]
Invoked with:
"""
# noqa: E501 line too long
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
m
.
stl_pass_by_pointer
(
None
)
assert
msg
(
excinfo
.
value
)
==
"""
stl_pass_by_pointer(): incompatible function arguments. The following argument types are supported:
1. (v: List[int]=None) -> List[int]
Invoked with: None
"""
# noqa: E501 line too long
assert
m
.
stl_pass_by_pointer
([
1
,
2
,
3
])
==
[
1
,
2
,
3
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment