Mercurial > pytave
diff pycall.cc @ 197:d6c44d680482
Convert Octave scalars into Python scalars (fixes issue #14)
* octave_to_python.cc (octscalar_to_pyobject): New function.
(octvalue_to_pyobj): Call it when argument is a scalar.
* pycall.cc: Enable previously failing tests for scalar type conversion.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Thu, 14 Jul 2016 23:56:40 -0700 |
parents | 459b6f5c56ed |
children | 377f2dc057ea |
line wrap: on
line diff
--- a/pycall.cc Thu Jul 14 23:42:45 2016 -0700 +++ b/pycall.cc Thu Jul 14 23:56:40 2016 -0700 @@ -204,20 +204,20 @@ %!assert (ischar (pycall ("os.getcwd"))) %!assert (isreal (pycall ("random.random"))) %!assert (pycall ("math.exp", 3), exp (3)) -%!xtest assert (pycall ("math.trunc", pi), fix (pi)) +%!assert (pycall ("math.trunc", pi), fix (pi)) %!assert (pycall ("math.sqrt", 2), sqrt (2)) -%!xtest assert (pycall ("cmath.sqrt", 2j), sqrt (2j)) +%!assert (pycall ("cmath.sqrt", 2j), sqrt (2j)) %!assert (pycall ("int", 10.2), 10) ## Test argument type conversion of values into Python %!test %! pyexec ("def typename(x): return type(x).__name__"); -%!xtest assert (pycall ("typename", 0), "double") -%!xtest assert (pycall ("typename", pi), "double") -%!xtest assert (pycall ("typename", 2j), "complex") -%!xtest assert (pycall ("typename", int32 (0)), "int") -%!xtest assert (pycall ("typename", false), "bool") -%!xtest assert (pycall ("typename", true), "bool") +%!assert (pycall ("typename", 0), "float") +%!assert (pycall ("typename", pi), "float") +%!assert (pycall ("typename", 2j), "complex") +%!assert (pycall ("typename", int32 (0)), "int") +%!assert (pycall ("typename", false), "bool") +%!assert (pycall ("typename", true), "bool") %!assert (pycall ("typename", "Hello world"), "str") %!assert (pycall ("typename", char ([1, 2, 3])), "str") @@ -232,8 +232,8 @@ %!test %! pyexec (["def pyfunc(x):\n" ... -%! " if x.item((0,0)) is True:\n return 30\n" ... -%! " elif x.item((0,0)) is False:\n return 20\n" ... +%! " if x is True:\n return 30\n" ... +%! " elif x is False:\n return 20\n" ... %! " else:\n return 10"]); %! assert (pycall ("pyfunc", true), 30) %! assert (pycall ("pyfunc", false), 20)