Fix Eigen argument doc strings

Many of the Eigen type casters' name() methods weren't wrapping the type
description in a `type_descr` object, which thus wasn't adding the
"{...}" annotation used to identify an argument which broke the help
output by skipping eigen arguments.

The test code I had added even had some (unnoticed) broken output (with
the "arg0: " showing up in the return value).

This commit also adds test code to ensure that named eigen arguments
actually work properly, despite the invalid help output.  (The added
tests pass without the rest of this commit).
This commit is contained in:
Jason Rhinelander
2017-04-08 19:26:42 -04:00
parent 501135fa76
commit e9e17746c8
3 changed files with 49 additions and 18 deletions

View File

@@ -75,15 +75,15 @@ def test_mutator_descriptors():
fixed_mutator_a(zc)
with pytest.raises(TypeError) as excinfo:
fixed_mutator_r(zc)
assert ('(numpy.ndarray[float32[5, 6], flags.writeable, flags.c_contiguous]) -> arg0: None'
assert ('(arg0: numpy.ndarray[float32[5, 6], flags.writeable, flags.c_contiguous]) -> None'
in str(excinfo.value))
with pytest.raises(TypeError) as excinfo:
fixed_mutator_c(zr)
assert ('(numpy.ndarray[float32[5, 6], flags.writeable, flags.f_contiguous]) -> arg0: None'
assert ('(arg0: numpy.ndarray[float32[5, 6], flags.writeable, flags.f_contiguous]) -> None'
in str(excinfo.value))
with pytest.raises(TypeError) as excinfo:
fixed_mutator_a(np.array([[1, 2], [3, 4]], dtype='float32'))
assert ('(numpy.ndarray[float32[5, 6], flags.writeable]) -> arg0: None'
assert ('(arg0: numpy.ndarray[float32[5, 6], flags.writeable]) -> None'
in str(excinfo.value))
zr.flags.writeable = False
with pytest.raises(TypeError):
@@ -582,6 +582,29 @@ def test_dense_signature(doc):
"""
def test_named_arguments():
from pybind11_tests import matrix_multiply
a = np.array([[1.0, 2], [3, 4], [5, 6]])
b = np.ones((2, 1))
assert np.all(matrix_multiply(a, b) == np.array([[3.], [7], [11]]))
assert np.all(matrix_multiply(A=a, B=b) == np.array([[3.], [7], [11]]))
assert np.all(matrix_multiply(B=b, A=a) == np.array([[3.], [7], [11]]))
with pytest.raises(ValueError) as excinfo:
matrix_multiply(b, a)
assert str(excinfo.value) == 'Nonconformable matrices!'
with pytest.raises(ValueError) as excinfo:
matrix_multiply(A=b, B=a)
assert str(excinfo.value) == 'Nonconformable matrices!'
with pytest.raises(ValueError) as excinfo:
matrix_multiply(B=a, A=b)
assert str(excinfo.value) == 'Nonconformable matrices!'
@pytest.requires_eigen_and_scipy
def test_sparse():
from pybind11_tests import sparse_r, sparse_c, sparse_copy_r, sparse_copy_c