Mercurial > pytave
comparison pycall.cc @ 281:b06df69f4b37
Remove unused code and add tests to pycall
* pycall.cc: Cleanup unused code and add tests to verify conversion of lists,
dicts and tuples to pyobject
author | Abhinav Tripathi <genuinelucifer@gmail.com> |
---|---|
date | Sun, 31 Jul 2016 12:29:15 -0700 |
parents | 6e83efbcf1bc |
children | 0d94e42bacf6 2ecae5c6eeb6 |
comparison
equal
deleted
inserted
replaced
280:3bf799e80ca5 | 281:b06df69f4b37 |
---|---|
201 default: | 201 default: |
202 error ("pycall: more than 10 arguments are not yet supported"); | 202 error ("pycall: more than 10 arguments are not yet supported"); |
203 break; | 203 break; |
204 } | 204 } |
205 | 205 |
206 object hex_function = builtins_module.attr ("hex"); | |
207 object id_function = builtins_module.attr ("id"); | |
208 object idtmp = hex_function (id_function (res)); | |
209 id = extract<std::string> (idtmp); | |
210 | |
211 // Ensure reasonable "ans" behaviour, consistent with Python's "_". | 206 // Ensure reasonable "ans" behaviour, consistent with Python's "_". |
212 if (nargout > 0 || ! res.is_none ()) | 207 if (nargout > 0 || ! res.is_none ()) |
213 { | 208 { |
214 octave_value val; | 209 octave_value val; |
215 pytave::pyobj_to_octvalue (val, res); | 210 pytave::pyobj_to_octvalue (val, res); |
240 %!assert (pycall ("math.trunc", pi), fix (pi)) | 235 %!assert (pycall ("math.trunc", pi), fix (pi)) |
241 %!assert (pycall ("math.sqrt", 2), sqrt (2)) | 236 %!assert (pycall ("math.sqrt", 2), sqrt (2)) |
242 %!assert (pycall ("cmath.sqrt", 2j), sqrt (2j)) | 237 %!assert (pycall ("cmath.sqrt", 2j), sqrt (2j)) |
243 %!assert (pycall ("int", 10.2), 10) | 238 %!assert (pycall ("int", 10.2), 10) |
244 %!assert (isa (pycall ("object"), "pyobject")) | 239 %!assert (isa (pycall ("object"), "pyobject")) |
240 %!assert (isa (pycall ("dict"), "pyobject")) | |
241 %!assert (isa (pycall ("list"), "pyobject")) | |
242 %!assert (isa (pycall ("tuple"), "pyobject")) | |
245 | 243 |
246 ## Test argument type conversion of values into Python | 244 ## Test argument type conversion of values into Python |
247 %!test | 245 %!test |
248 %! pyexec (["def typename(x):\n" ... | 246 %! pyexec (["def typename(x):\n" ... |
249 %! " s = type(x).__name__\n" ... | 247 %! " s = type(x).__name__\n" ... |