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
9cca45a0
Commit
9cca45a0
authored
Jan 29, 2021
by
Ralf W. Grosse-Kunstleve
Browse files
Adding test_open_spiel_pattern. It builds and run with py::class_ or py::classh.
parent
94900266
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
0 deletions
+45
-0
tests/test_open_spiel_pattern.cpp
tests/test_open_spiel_pattern.cpp
+37
-0
tests/test_open_spiel_pattern.py
tests/test_open_spiel_pattern.py
+8
-0
No files found.
tests/test_open_spiel_pattern.cpp
0 → 100644
View file @
9cca45a0
#include "pybind11_tests.h"
#include <pybind11/functional.h>
#include <pybind11/smart_holder.h>
#include <functional>
namespace
pybind11_tests
{
namespace
open_spiel_pattern
{
class
Foo
{
public:
int
num
;
Foo
(
int
i
)
:
num
{
i
}
{}
int
bar
(
int
i
)
{
return
num
+
i
;
}
};
using
FooFactory
=
std
::
function
<
Foo
()
>
;
int
MakeAndUseFoo
(
FooFactory
f
)
{
auto
foo
=
f
();
return
foo
.
bar
(
456
);
}
}
// namespace open_spiel_pattern
}
// namespace pybind11_tests
// To use py::smart_holder, uncomment the next line and change py::class_ below to py::classh.
// PYBIND11_SMART_HOLDER_TYPE_CASTERS(pybind11_tests::open_spiel_pattern::Foo)
TEST_SUBMODULE
(
open_spiel_pattern
,
m
)
{
using
namespace
pybind11_tests
::
open_spiel_pattern
;
py
::
class_
<
Foo
>
(
m
,
"Foo"
).
def
(
py
::
init
<
int
>
()).
def
(
"bar"
,
&
Foo
::
bar
);
m
.
def
(
"make_and_use_foo"
,
MakeAndUseFoo
);
}
tests/test_open_spiel_pattern.py
0 → 100644
View file @
9cca45a0
# -*- coding: utf-8 -*-
import
pytest
from
pybind11_tests
import
open_spiel_pattern
as
m
def
test_make_and_use_foo
():
res
=
m
.
make_and_use_foo
(
lambda
:
m
.
Foo
(
123
))
assert
res
==
579
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