Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
d922dffe
Commit
d922dffe
authored
Sep 19, 2016
by
Wenzel Jakob
Committed by
GitHub
Sep 19, 2016
Browse files
Merge pull request #410 from wjakob/mi
WIP: Multiple inheritance support
parents
7962f30d
e72a676b
Changes
25
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
165 additions
and
10 deletions
+165
-10
tests/test_issues.py
tests/test_issues.py
+9
-6
tests/test_kwargs_and_defaults.py
tests/test_kwargs_and_defaults.py
+3
-2
tests/test_multiple_inheritance.cpp
tests/test_multiple_inheritance.cpp
+85
-0
tests/test_multiple_inheritance.py
tests/test_multiple_inheritance.py
+65
-0
tests/test_opaque_types.py
tests/test_opaque_types.py
+3
-2
No files found.
tests/test_issues.py
View file @
d922dffe
...
@@ -65,16 +65,18 @@ def test_no_id(capture, msg):
...
@@ -65,16 +65,18 @@ def test_no_id(capture, msg):
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
get_element
(
None
)
get_element
(
None
)
assert
msg
(
excinfo
.
value
)
==
"""
assert
msg
(
excinfo
.
value
)
==
"""
I
ncompatible function arguments. The following argument types are supported:
get_element(): i
ncompatible function arguments. The following argument types are supported:
1. (arg0: m.issues.ElementA) -> int
1. (arg0: m.issues.ElementA) -> int
Invoked with: None
Invoked with: None
"""
"""
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
expect_int
(
5.2
)
expect_int
(
5.2
)
assert
msg
(
excinfo
.
value
)
==
"""
assert
msg
(
excinfo
.
value
)
==
"""
I
ncompatible function arguments. The following argument types are supported:
expect_int(): i
ncompatible function arguments. The following argument types are supported:
1. (arg0: int) -> int
1. (arg0: int) -> int
Invoked with: 5.2
Invoked with: 5.2
"""
"""
assert
expect_float
(
12
)
==
12
assert
expect_float
(
12
)
==
12
...
@@ -90,9 +92,10 @@ def test_str_issue(msg):
...
@@ -90,9 +92,10 @@ def test_str_issue(msg):
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
str
(
StrIssue
(
"no"
,
"such"
,
"constructor"
))
str
(
StrIssue
(
"no"
,
"such"
,
"constructor"
))
assert
msg
(
excinfo
.
value
)
==
"""
assert
msg
(
excinfo
.
value
)
==
"""
I
ncompatible constructor arguments. The following argument types are supported:
__init__(): i
ncompatible constructor arguments. The following argument types are supported:
1. m.issues.StrIssue(arg0: int)
1. m.issues.StrIssue(arg0: int)
2. m.issues.StrIssue()
2. m.issues.StrIssue()
Invoked with: no, such, constructor
Invoked with: no, such, constructor
"""
"""
...
...
tests/test_kwargs_and_defaults.py
View file @
d922dffe
...
@@ -35,8 +35,9 @@ def test_named_arguments(msg):
...
@@ -35,8 +35,9 @@ def test_named_arguments(msg):
# noinspection PyArgumentList
# noinspection PyArgumentList
kw_func2
(
x
=
5
,
y
=
10
,
z
=
12
)
kw_func2
(
x
=
5
,
y
=
10
,
z
=
12
)
assert
msg
(
excinfo
.
value
)
==
"""
assert
msg
(
excinfo
.
value
)
==
"""
I
ncompatible function arguments. The following argument types are supported:
kw_func2(): i
ncompatible function arguments. The following argument types are supported:
1. (x: int=100, y: int=200) -> str
1. (x: int=100, y: int=200) -> str
Invoked with:
Invoked with:
"""
"""
...
...
tests/test_multiple_inheritance.cpp
0 → 100644
View file @
d922dffe
/*
tests/test_multiple_inheritance.cpp -- multiple inheritance,
implicit MI casts
Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
All rights reserved. Use of this source code is governed by a
BSD-style license that can be found in the LICENSE file.
*/
#include "pybind11_tests.h"
PYBIND11_DECLARE_HOLDER_TYPE
(
T
,
std
::
shared_ptr
<
T
>
);
struct
Base1
{
Base1
(
int
i
)
:
i
(
i
)
{
}
int
foo
()
{
return
i
;
}
int
i
;
};
struct
Base2
{
Base2
(
int
i
)
:
i
(
i
)
{
}
int
bar
()
{
return
i
;
}
int
i
;
};
struct
Base12
:
Base1
,
Base2
{
Base12
(
int
i
,
int
j
)
:
Base1
(
i
),
Base2
(
j
)
{
}
};
struct
MIType
:
Base12
{
MIType
(
int
i
,
int
j
)
:
Base12
(
i
,
j
)
{
}
};
test_initializer
multiple_inheritance
([](
py
::
module
&
m
)
{
py
::
class_
<
Base1
>
(
m
,
"Base1"
)
.
def
(
py
::
init
<
int
>
())
.
def
(
"foo"
,
&
Base1
::
foo
);
py
::
class_
<
Base2
>
(
m
,
"Base2"
)
.
def
(
py
::
init
<
int
>
())
.
def
(
"bar"
,
&
Base2
::
bar
);
py
::
class_
<
Base12
,
Base1
,
Base2
>
(
m
,
"Base12"
);
py
::
class_
<
MIType
,
Base12
>
(
m
,
"MIType"
)
.
def
(
py
::
init
<
int
,
int
>
());
});
/* Test the case where not all base classes are specified,
and where pybind11 requires the py::multiple_inheritance
flag to perform proper casting between types */
struct
Base1a
{
Base1a
(
int
i
)
:
i
(
i
)
{
}
int
foo
()
{
return
i
;
}
int
i
;
};
struct
Base2a
{
Base2a
(
int
i
)
:
i
(
i
)
{
}
int
bar
()
{
return
i
;
}
int
i
;
};
struct
Base12a
:
Base1a
,
Base2a
{
Base12a
(
int
i
,
int
j
)
:
Base1a
(
i
),
Base2a
(
j
)
{
}
};
test_initializer
multiple_inheritance_nonexplicit
([](
py
::
module
&
m
)
{
py
::
class_
<
Base1a
,
std
::
shared_ptr
<
Base1a
>>
(
m
,
"Base1a"
)
.
def
(
py
::
init
<
int
>
())
.
def
(
"foo"
,
&
Base1a
::
foo
);
py
::
class_
<
Base2a
,
std
::
shared_ptr
<
Base2a
>>
(
m
,
"Base2a"
)
.
def
(
py
::
init
<
int
>
())
.
def
(
"bar"
,
&
Base2a
::
bar
);
py
::
class_
<
Base12a
,
/* Base1 missing */
Base2a
,
std
::
shared_ptr
<
Base12a
>>
(
m
,
"Base12a"
,
py
::
multiple_inheritance
())
.
def
(
py
::
init
<
int
,
int
>
());
m
.
def
(
"bar_base2a"
,
[](
Base2a
*
b
)
{
return
b
->
bar
();
});
m
.
def
(
"bar_base2a_sharedptr"
,
[](
std
::
shared_ptr
<
Base2a
>
b
)
{
return
b
->
bar
();
});
});
tests/test_multiple_inheritance.py
0 → 100644
View file @
d922dffe
import
pytest
def
test_multiple_inheritance_cpp
(
msg
):
from
pybind11_tests
import
MIType
mt
=
MIType
(
3
,
4
)
assert
mt
.
foo
()
==
3
assert
mt
.
bar
()
==
4
def
test_multiple_inheritance_mix1
(
msg
):
from
pybind11_tests
import
Base2
class
Base1
:
def
__init__
(
self
,
i
):
self
.
i
=
i
def
foo
(
self
):
return
self
.
i
class
MITypePy
(
Base1
,
Base2
):
def
__init__
(
self
,
i
,
j
):
Base1
.
__init__
(
self
,
i
)
Base2
.
__init__
(
self
,
j
)
mt
=
MITypePy
(
3
,
4
)
assert
mt
.
foo
()
==
3
assert
mt
.
bar
()
==
4
def
test_multiple_inheritance_mix2
(
msg
):
from
pybind11_tests
import
Base1
class
Base2
:
def
__init__
(
self
,
i
):
self
.
i
=
i
def
bar
(
self
):
return
self
.
i
class
MITypePy
(
Base1
,
Base2
):
def
__init__
(
self
,
i
,
j
):
Base1
.
__init__
(
self
,
i
)
Base2
.
__init__
(
self
,
j
)
mt
=
MITypePy
(
3
,
4
)
assert
mt
.
foo
()
==
3
assert
mt
.
bar
()
==
4
def
test_multiple_inheritance_virtbase
(
msg
):
from
pybind11_tests
import
Base12a
,
bar_base2a
,
bar_base2a_sharedptr
class
MITypePy
(
Base12a
):
def
__init__
(
self
,
i
,
j
):
Base12a
.
__init__
(
self
,
i
,
j
)
mt
=
MITypePy
(
3
,
4
)
assert
mt
.
bar
()
==
4
assert
bar_base2a
(
mt
)
==
4
assert
bar_base2a_sharedptr
(
mt
)
==
4
tests/test_opaque_types.py
View file @
d922dffe
...
@@ -35,8 +35,9 @@ def test_pointers(msg):
...
@@ -35,8 +35,9 @@ def test_pointers(msg):
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
get_void_ptr_value
([
1
,
2
,
3
])
# This should not work
get_void_ptr_value
([
1
,
2
,
3
])
# This should not work
assert
msg
(
excinfo
.
value
)
==
"""
assert
msg
(
excinfo
.
value
)
==
"""
I
ncompatible function arguments. The following argument types are supported:
get_void_ptr_value(): i
ncompatible function arguments. The following argument types are supported:
1. (arg0: capsule) -> int
1. (arg0: capsule) -> int
Invoked with: [1, 2, 3]
Invoked with: [1, 2, 3]
"""
"""
...
...
Prev
1
2
Next
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