Mercurial > pytave
comparison @pyobject/subsref.m @ 290:f2b4576879a6
Edit tests in subsref to use and verify cell indexing
* @pyobject/subsref.m: Edit an existing test to use the available cell indexing
syntax and also add a test to verify that None is returned if nargout > 0
author | Abhinav Tripathi <genuinelucifer@gmail.com> |
---|---|
date | Wed, 03 Aug 2016 00:26:44 -0700 |
parents | f5282c87e5d5 |
children | e7ee2c2e64e8 |
comparison
equal
deleted
inserted
replaced
289:49832ca978fd | 290:f2b4576879a6 |
---|---|
117 %! pyexec ("L = [10, 20]") | 117 %! pyexec ("L = [10, 20]") |
118 %! L = pyobject.fromPythonVarName ("L"); | 118 %! L = pyobject.fromPythonVarName ("L"); |
119 %! assert (L{1}, 10) | 119 %! assert (L{1}, 10) |
120 %! assert (L{2}, 20) | 120 %! assert (L{2}, 20) |
121 | 121 |
122 %!xtest | 122 %!test |
123 %! % list indexing, slice | 123 %! % list indexing, slice |
124 %! pyexec ("L = [10, 20, [30, 40]]") | 124 %! pyexec ("L = [10, 20, [30, 40]]") |
125 %! L = pyobject.fromPythonVarName ("L"); | 125 %! L = pyobject.fromPythonVarName ("L"); |
126 %! L2 = L{:}; | 126 %! [L2{1:length(L)}] = L{:}; |
127 %! assert (L2{1}, 10) | 127 %! assert (L2{1}, 10) |
128 %! assert (L2{2}, 20) | 128 %! assert (L2{2}, 20) |
129 %! assert (L2{3}{1}, 30) | 129 %! assert (L2{3}{1}, 30) |
130 %! assert (L2{3}{2}, 40) | 130 %! assert (L2{3}{2}, 40) |
131 | 131 |
240 %! % multiple return values: set ans | 240 %! % multiple return values: set ans |
241 %! f = pyeval ("lambda: (1, 2, 3)"); | 241 %! f = pyeval ("lambda: (1, 2, 3)"); |
242 %! f (); | 242 %! f (); |
243 %! assert (length (ans) == 3) | 243 %! assert (length (ans) == 3) |
244 | 244 |
245 %!test | |
246 %! % ensure None is returned if nargout > 0 | |
247 %! L = pyeval ("[1, None, 3]"); | |
248 %! a = L{2}; | |
249 %! assert (char (a), "None") | |
250 | |
245 %!error <outputs must match> | 251 %!error <outputs must match> |
246 %! % multiple return values: too many outputs | 252 %! % multiple return values: too many outputs |
247 %! f = pyeval ("lambda: (1, 2)"); | 253 %! f = pyeval ("lambda: (1, 2)"); |
248 %! [a, b, c] = f (); | 254 %! [a, b, c] = f (); |
249 | 255 |