Mercurial > pytave
changeset 190:ac377ace2ee4
More unit tests of pycall and pyeval
* pycall.cc, pyeval.cc: More unit tests of type translation, including
some conversions not yet working correctly.
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Thu, 09 Jun 2016 14:52:06 -0700 |
parents | def67115cbe3 |
children | 0500459a739b 28173dc00d51 |
files | pycall.cc pyeval.cc |
diffstat | 2 files changed, 39 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/pycall.cc Thu Jun 09 12:59:09 2016 -0700 +++ b/pycall.cc Thu Jun 09 14:52:06 2016 -0700 @@ -182,6 +182,25 @@ } /* +%!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.sqrt", 2), sqrt (2)) +%!xtest assert (pycall ("cmath.sqrt", 2j), sqrt (2j)) + +## 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", "Hello world"), "str") +%!assert (pycall ("typename", char ([1, 2, 3])), "str") + %!test %! pyexec ("def pyfunc(x):\n return 2*x"); %! z = pycall ("pyfunc", [20 20]);
--- a/pyeval.cc Thu Jun 09 12:59:09 2016 -0700 +++ b/pyeval.cc Thu Jun 09 14:52:06 2016 -0700 @@ -105,24 +105,33 @@ } /* -%!test -%! q = pyeval ("10.1"); -%! assert (isnumeric (q)) -%! % note: floating-point equality test: usually bad but here we expect the exact same float -%! assert (q, 10.1) +%!assert (isnumeric (pyeval ("0"))) +%!assert (isreal (pyeval ("0"))) +%!assert (pyeval ("0"), 0) -%!test -%! q = pyeval ("\"I <3 Octave\""); -%! assert (ischar (q)) -%! assert (! strcmp (q, "1 <3 Octave")) +%!assert (isnumeric (pyeval ("10.1"))) +%!assert (isreal (pyeval ("10.1"))) +%!assert (pyeval ("10.1"), 10.1) + +%!assert (isnumeric (pyeval ("2j"))) +%!assert (iscomplex (pyeval ("2j"))) +%!assert (pyeval ("2j"), 2j) + +%!assert (ischar (pyeval ("\"I <3 Octave\""))) +%!assert (pyeval ("\"I <3 Octave\""), "I <3 Octave") %!assert (islogical (pyeval ("True"))) %!assert (islogical (pyeval ("False"))) -%!assert (pyeval ("True")) -%!assert (! pyeval ("False")) +%!assert (pyeval ("True"), true) +%!assert (pyeval ("False"), false) %!assert (class (pyeval ("True")), "logical") %!assert (class (pyeval ("False")), "logical") +## FIXME: these will change when dict, list, and tuple are not converted +%!assert (pyeval ("{'x': 1, 'y': 2}"), struct ("x", 1, "y", 2)) +%!assert (pyeval ("[1, 2, 3]"), {1, 2, 3}) +%!assert (pyeval ("(4, 5, 6)"), {4, 5, 6}) + %!test %! % FIXME: this will change when we stop converting lists %! z = pyeval ("[1, [21, 22], 3, [41, [421, 422], 43]]");