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
23919174
Commit
23919174
authored
Aug 25, 2016
by
Dean Moldovan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix test suite failure without numpy and improve module init diagnostics
Fixes #357.
parent
69b62466
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
11 deletions
+40
-11
tests/conftest.py
+24
-0
tests/test_eigen.py
+5
-6
tests/test_numpy_dtypes.cpp
+6
-0
tests/test_numpy_dtypes.py
+5
-5
No files found.
tests/conftest.py
View file @
23919174
...
...
@@ -202,3 +202,27 @@ def pytest_namespace():
'requires_eigen_and_scipy'
:
skipif
(
not
have_eigen
or
not
scipy
,
reason
=
"eigen and/or scipy are not installed"
),
}
def
_test_import_pybind11
():
"""Early diagnostic for test module initialization errors
When there is an error during initialization, the first import will report the
real error while all subsequent imports will report nonsense. This import test
is done early (in the pytest configuration file, before any tests) in order to
avoid the noise of having all tests fail with identical error messages.
Any possible exception is caught here and reported manually *without* the stack
trace. This further reduces noise since the trace would only show pytest internals
which are not useful for debugging pybind11 module issues.
"""
# noinspection PyBroadException
try
:
import
pybind11_tests
except
Exception
as
e
:
print
(
"Failed to import pybind11_tests from pytest:"
)
print
(
" {}: {}"
.
format
(
type
(
e
)
.
__name__
,
e
))
sys
.
exit
(
1
)
_test_import_pybind11
()
tests/test_eigen.py
View file @
23919174
...
...
@@ -3,12 +3,11 @@ import pytest
with
pytest
.
suppress
(
ImportError
):
import
numpy
as
np
ref
=
np
.
array
([[
0
,
3
,
0
,
0
,
0
,
11
],
[
22
,
0
,
0
,
0
,
17
,
11
],
[
7
,
5
,
0
,
1
,
0
,
11
],
[
0
,
0
,
0
,
0
,
0
,
11
],
[
0
,
0
,
14
,
0
,
8
,
11
]])
ref
=
np
.
array
([[
0
,
3
,
0
,
0
,
0
,
11
],
[
22
,
0
,
0
,
0
,
17
,
11
],
[
7
,
5
,
0
,
1
,
0
,
11
],
[
0
,
0
,
0
,
0
,
0
,
11
],
[
0
,
0
,
14
,
0
,
8
,
11
]])
def
assert_equal_ref
(
mat
):
...
...
tests/test_numpy_dtypes.cpp
View file @
23919174
...
...
@@ -268,6 +268,12 @@ py::list test_dtype_methods() {
}
void
init_ex_numpy_dtypes
(
py
::
module
&
m
)
{
try
{
py
::
module
::
import
(
"numpy"
);
}
catch
(...)
{
return
;
}
PYBIND11_NUMPY_DTYPE
(
SimpleStruct
,
x
,
y
,
z
);
PYBIND11_NUMPY_DTYPE
(
PackedStruct
,
x
,
y
,
z
);
PYBIND11_NUMPY_DTYPE
(
NestedStruct
,
a
,
b
);
...
...
tests/test_numpy_dtypes.py
View file @
23919174
...
...
@@ -2,15 +2,15 @@ import pytest
with
pytest
.
suppress
(
ImportError
):
import
numpy
as
np
simple_dtype
=
np
.
dtype
({
'names'
:
[
'x'
,
'y'
,
'z'
],
'formats'
:
[
'?'
,
'u4'
,
'f4'
],
'offsets'
:
[
0
,
4
,
8
]})
packed_dtype
=
np
.
dtype
([(
'x'
,
'?'
),
(
'y'
,
'u4'
),
(
'z'
,
'f4'
)])
def
assert_equal
(
actual
,
expected_data
,
expected_dtype
):
np
.
testing
.
assert_equal
(
actual
,
np
.
array
(
expected_data
,
dtype
=
expected_dtype
))
simple_dtype
=
np
.
dtype
({
'names'
:
[
'x'
,
'y'
,
'z'
],
'formats'
:
[
'?'
,
'u4'
,
'f4'
],
'offsets'
:
[
0
,
4
,
8
]})
packed_dtype
=
np
.
dtype
([(
'x'
,
'?'
),
(
'y'
,
'u4'
),
(
'z'
,
'f4'
)])
@pytest.requires_numpy
def
test_format_descriptors
():
...
...
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