comparison @pyobject/subsref.m @ 312:d9f9156a13c9

Remove unncessary calls to fromPythonVarName * @pyobject/subsasgn.m: Drop fromPythonVarName * @pyobject/subsref.m: Drop fromPythonVarName
author Colin Macdonald <cbm@m.fsf.org>
date Tue, 09 Aug 2016 11:08:58 -0700
parents 714d1bf1ef78
children 6bba42371afa
comparison
equal deleted inserted replaced
311:77af526c687a 312:d9f9156a13c9
112 endfunction 112 endfunction
113 113
114 114
115 %!test 115 %!test
116 %! % list indexing 116 %! % list indexing
117 %! pyexec ("L = [10, 20]") 117 %! L = pyeval ("[10, 20]");
118 %! L = pyobject.fromPythonVarName ("L");
119 %! assert (L{1}, 10) 118 %! assert (L{1}, 10)
120 %! assert (L{2}, 20) 119 %! assert (L{2}, 20)
121 120
122 %!test 121 %!test
123 %! % list indexing, slice 122 %! % list indexing, slice
124 %! pyexec ("L = [10, 20, [30, 40]]") 123 %! L = pyeval ("[10, 20, [30, 40]]");
125 %! L = pyobject.fromPythonVarName ("L");
126 %! L2 = L{:}; 124 %! L2 = L{:};
127 %! assert (L2{1}, 10) 125 %! assert (L2{1}, 10)
128 %! assert (L2{2}, 20) 126 %! assert (L2{2}, 20)
129 %! assert (L2{3}{1}, 30) 127 %! assert (L2{3}{1}, 30)
130 %! assert (L2{3}{2}, 40) 128 %! assert (L2{3}{2}, 40)
131 129
132 %!test 130 %!test
133 %! % list indexing, nested list 131 %! % list indexing, nested list
134 %! pyexec ("L = [1, 2, [10, 11, 12]]") 132 %! L = pyeval ("[1, 2, [10, 11, 12]]");
135 %! L = pyobject.fromPythonVarName ("L");
136 %! assert (L{2}, 2) 133 %! assert (L{2}, 2)
137 %! assert (L{3}{1}, 10) 134 %! assert (L{3}{1}, 10)
138 %! assert (L{3}{3}, 12) 135 %! assert (L{3}{3}, 12)
139 136
140 %!test 137 %!test
146 %! assert (c, "Octave") 143 %! assert (c, "Octave")
147 144
148 %!test 145 %!test
149 %! % 2D array indexing 146 %! % 2D array indexing
150 %! pyexec ("import numpy") 147 %! pyexec ("import numpy")
151 %! pyexec ("A = numpy.array([[1, 2], [3, 4]])") 148 %! A = pyobject (pyeval ("numpy.array([[1, 2], [3, 4]])"));
152 %! A = pyobject.fromPythonVarName ("A");
153 %! assert (A{1, 1}, 1) 149 %! assert (A{1, 1}, 1)
154 %! assert (A{2, 1}, 3) 150 %! assert (A{2, 1}, 3)
155 %! assert (A{1, 2}, 2) 151 %! assert (A{1, 2}, 2)
156 152
157 %!test 153 %!test
158 %! % dict: str key access 154 %! % dict: str key access
159 %! pyexec ("d = {'one':1, 5:5, 6:6}") 155 %! d = pyeval ("{'one':1, 5:5, 6:6}");
160 %! d = pyobject.fromPythonVarName ("d");
161 %! assert (d{"one"}, 1) 156 %! assert (d{"one"}, 1)
162 157
163 %!test 158 %!test
164 %! % dict: integer key access 159 %! % dict: integer key access
165 %! pyexec ("d = {5:42, 6:42}") 160 %! d = pyeval ("{5:42, 6:42}");
166 %! d = pyobject.fromPythonVarName ("d");
167 %! assert (d{6}, 42) 161 %! assert (d{6}, 42)
168 162
169 %!test 163 %!test
170 %! % dict: integer key should not subtract one 164 %! % dict: integer key should not subtract one
171 %! pyexec ("d = {5:40, 6:42}") 165 %! d = pyeval ("{5:40, 6:42}");
172 %! d = pyobject.fromPythonVarName ("d");
173 %! assert (d{6}, 42) 166 %! assert (d{6}, 42)
174 167
175 %!test 168 %!test
176 %! % dict: floating point keys should work 169 %! % dict: floating point keys should work
177 %! pyexec ("d = {5.5:'ok'}") 170 %! d = pyeval ("{5.5:'ok'}");
178 %! d = pyobject.fromPythonVarName ("d");
179 %! assert (d{5.5}, "ok") 171 %! assert (d{5.5}, "ok")
180 172
181 %!test 173 %!test
182 %! % dict: make sure key ":" doesn't break anything 174 %! % dict: make sure key ":" doesn't break anything
183 %! pyexec ("d = {'a':1, ':':2}") 175 %! d = pyeval ("{'a':1, ':':2}");
184 %! d = pyobject.fromPythonVarName ("d");
185 %! assert (d{'a'}, 1) 176 %! assert (d{'a'}, 1)
186 %! assert (d{':'}, 2) 177 %! assert (d{':'}, 2)
187 178
188 %!test 179 %!test
189 %! % method call with args 180 %! % method call with args