Mercurial > pytave
changeset 330:5c63651b0ec4
Merged in genuinelucifer/pytave_main (pull request #40)
Add isequal method to allow comparing pyobjects (fixes issue #53)
author | Mike Miller <mtmiller@octave.org> |
---|---|
date | Sat, 13 Aug 2016 23:59:49 -0700 |
parents | 5782d7932529 (current diff) 778c91283a73 (diff) |
children | cee203ea6245 |
files | @pyobject/pyobject.m |
diffstat | 1 files changed, 23 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/@pyobject/pyobject.m Sat Aug 13 23:52:57 2016 -0700 +++ b/@pyobject/pyobject.m Sat Aug 13 23:59:49 2016 -0700 @@ -217,6 +217,17 @@ r = size (x, index_pos); endif endfunction + + function res = isequal (varargin) + assert (nargin >= 2) + res = all (strcmp ("pyobject", cellfun ("class", varargin, "uniformoutput", false))); + for i = 2:nargin + if (! res) + return; + endif + res = res && pycall("bool", pycall ("operator.eq", varargin{1}, varargin{i})); + endfor + endfunction endmethods endclassdef @@ -329,3 +340,15 @@ %!error double (pyobject ("this is not a number")) %!error double (pyobject ()) %!error double (pyeval ("[1, 2, 3]")) + +%!error (isequal (pyobject ())) +%!assert (! isequal (pyobject (1.2), 1.2)) +%!assert (isequal (pyobject ("a string"), pyobject ("a string"))) +%!assert (isequal (pyeval ("None"), pyeval ("None"))) +%!assert (! isequal (pyeval ("None"), pyeval ("None"), pyobject (10))) +%!assert (isequal (pyobject (10), pyobject (10.0), pyobject (int8 (10)))) + +%!test +%! A = pyeval ("[1, 2, 3]"); +%! B = pycall ("list", {1, 2, 3}); +%! assert (isequal (A, B))