Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
77eefd0b
Commit
77eefd0b
authored
Jan 23, 2021
by
Ralf W. Grosse-Kunstleve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adopting systematic naming scheme from test_classh_wip. NO functional changes.
parent
66a3c01e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
40 deletions
+40
-40
tests/classh_module_local_0.cpp
+7
-7
tests/classh_module_local_1.cpp
+10
-10
tests/classh_module_local_2.cpp
+10
-10
tests/test_classh_module_local.py
+13
-13
No files found.
tests/classh_module_local_0.cpp
View file @
77eefd0b
...
...
@@ -5,23 +5,23 @@
namespace
pybind11_tests
{
namespace
classh_module_local
{
struct
bottle
{
std
::
string
m
sg
;
struct
atyp
{
// Short for "any type".
std
::
string
m
txt
;
};
std
::
string
get_m
sg
(
const
bottle
&
b
)
{
return
b
.
msg
;
}
std
::
string
get_m
txt
(
const
atyp
&
obj
)
{
return
obj
.
mtxt
;
}
bottle
make_bottle
()
{
return
bottle
();
}
atyp
rtrn_valu_atyp
()
{
return
atyp
();
}
}
// namespace classh_module_local
}
// namespace pybind11_tests
PYBIND11_CLASSH_TYPE_CASTERS
(
pybind11_tests
::
classh_module_local
::
bottle
)
PYBIND11_CLASSH_TYPE_CASTERS
(
pybind11_tests
::
classh_module_local
::
atyp
)
PYBIND11_MODULE
(
classh_module_local_0
,
m
)
{
using
namespace
pybind11_tests
::
classh_module_local
;
m
.
def
(
"get_m
sg"
,
get_msg
);
m
.
def
(
"get_m
txt"
,
get_mtxt
);
m
.
def
(
"
make_bottle"
,
make_bottle
);
m
.
def
(
"
rtrn_valu_atyp"
,
rtrn_valu_atyp
);
}
tests/classh_module_local_1.cpp
View file @
77eefd0b
...
...
@@ -6,28 +6,28 @@
namespace
pybind11_tests
{
namespace
classh_module_local
{
struct
bottle
{
std
::
string
m
sg
;
struct
atyp
{
// Short for "any type".
std
::
string
m
txt
;
};
std
::
string
get_m
sg
(
const
bottle
&
b
)
{
return
b
.
msg
;
}
std
::
string
get_m
txt
(
const
atyp
&
obj
)
{
return
obj
.
mtxt
;
}
}
// namespace classh_module_local
}
// namespace pybind11_tests
PYBIND11_CLASSH_TYPE_CASTERS
(
pybind11_tests
::
classh_module_local
::
bottle
)
PYBIND11_CLASSH_TYPE_CASTERS
(
pybind11_tests
::
classh_module_local
::
atyp
)
PYBIND11_MODULE
(
classh_module_local_1
,
m
)
{
namespace
py
=
pybind11
;
using
namespace
pybind11_tests
::
classh_module_local
;
py
::
classh
<
bottle
>
(
m
,
"bottle
"
,
py
::
module_local
())
.
def
(
py
::
init
([](
const
std
::
string
&
m
sg
)
{
bottle
obj
;
obj
.
m
sg
=
msg
;
py
::
classh
<
atyp
>
(
m
,
"atyp
"
,
py
::
module_local
())
.
def
(
py
::
init
([](
const
std
::
string
&
m
txt
)
{
atyp
obj
;
obj
.
m
txt
=
mtxt
;
return
obj
;
}))
.
def
(
"tag"
,
[](
const
bottle
&
)
{
return
1
;
});
.
def
(
"tag"
,
[](
const
atyp
&
)
{
return
1
;
});
m
.
def
(
"get_m
sg"
,
get_msg
);
m
.
def
(
"get_m
txt"
,
get_mtxt
);
}
tests/classh_module_local_2.cpp
View file @
77eefd0b
...
...
@@ -6,28 +6,28 @@
namespace
pybind11_tests
{
namespace
classh_module_local
{
struct
bottle
{
std
::
string
m
sg
;
struct
atyp
{
// Short for "any type".
std
::
string
m
txt
;
};
std
::
string
get_m
sg
(
const
bottle
&
b
)
{
return
b
.
msg
;
}
std
::
string
get_m
txt
(
const
atyp
&
obj
)
{
return
obj
.
mtxt
;
}
}
// namespace classh_module_local
}
// namespace pybind11_tests
PYBIND11_CLASSH_TYPE_CASTERS
(
pybind11_tests
::
classh_module_local
::
bottle
)
PYBIND11_CLASSH_TYPE_CASTERS
(
pybind11_tests
::
classh_module_local
::
atyp
)
PYBIND11_MODULE
(
classh_module_local_2
,
m
)
{
namespace
py
=
pybind11
;
using
namespace
pybind11_tests
::
classh_module_local
;
py
::
classh
<
bottle
>
(
m
,
"bottle
"
,
py
::
module_local
())
.
def
(
py
::
init
([](
const
std
::
string
&
m
sg
)
{
bottle
obj
;
obj
.
m
sg
=
msg
;
py
::
classh
<
atyp
>
(
m
,
"atyp
"
,
py
::
module_local
())
.
def
(
py
::
init
([](
const
std
::
string
&
m
txt
)
{
atyp
obj
;
obj
.
m
txt
=
mtxt
;
return
obj
;
}))
.
def
(
"tag"
,
[](
const
bottle
&
)
{
return
2
;
});
.
def
(
"tag"
,
[](
const
atyp
&
)
{
return
2
;
});
m
.
def
(
"get_m
sg"
,
get_msg
);
m
.
def
(
"get_m
txt"
,
get_mtxt
);
}
tests/test_classh_module_local.py
View file @
77eefd0b
...
...
@@ -6,22 +6,22 @@ import classh_module_local_1 as m1
import
classh_module_local_2
as
m2
def
test_cross_module_get_m
sg
():
b1
=
m1
.
bottle
(
"A"
)
assert
b
1
.
tag
()
==
1
b2
=
m2
.
bottle
(
"B"
)
assert
b
2
.
tag
()
==
2
assert
m1
.
get_m
sg
(
b
1
)
==
"A"
assert
m2
.
get_m
sg
(
b
2
)
==
"B"
assert
m1
.
get_m
sg
(
b
2
)
==
"B"
assert
m2
.
get_m
sg
(
b
1
)
==
"A"
assert
m0
.
get_m
sg
(
b
1
)
==
"A"
assert
m0
.
get_m
sg
(
b
2
)
==
"B"
def
test_cross_module_get_m
txt
():
obj1
=
m1
.
atyp
(
"A"
)
assert
obj
1
.
tag
()
==
1
obj2
=
m2
.
atyp
(
"B"
)
assert
obj
2
.
tag
()
==
2
assert
m1
.
get_m
txt
(
obj
1
)
==
"A"
assert
m2
.
get_m
txt
(
obj
2
)
==
"B"
assert
m1
.
get_m
txt
(
obj
2
)
==
"B"
assert
m2
.
get_m
txt
(
obj
1
)
==
"A"
assert
m0
.
get_m
txt
(
obj
1
)
==
"A"
assert
m0
.
get_m
txt
(
obj
2
)
==
"B"
def
test_m0_
make_bottle
():
def
test_m0_
rtrn_valu_atyp
():
with
pytest
.
raises
(
TypeError
)
as
exc_info
:
m0
.
make_bottle
()
m0
.
rtrn_valu_atyp
()
assert
str
(
exc_info
.
value
)
.
startswith
(
"Unable to convert function return value to a Python type!"
)
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