Mercurial > pytave
annotate @pyobject/methods.m @ 376:d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
author | NVS Abhilash <nvs232@gmail.com> |
---|---|
date | Wed, 18 Jan 2017 17:06:34 +0530 |
parents | 0e4097c66788 |
children | cfd01e91d8e6 |
rev | line source |
---|---|
222
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
1 ## Copyright (C) 2016 Colin B. Macdonald |
376
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
2 ## Copyright (C) 2017 NVS Abhilash |
222
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
3 ## |
246
4acc64f89d67
maint: fix copyright header comment blocks
Mike Miller <mtmiller@octave.org>
parents:
227
diff
changeset
|
4 ## This file is part of Pytave |
222
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
5 ## |
246
4acc64f89d67
maint: fix copyright header comment blocks
Mike Miller <mtmiller@octave.org>
parents:
227
diff
changeset
|
6 ## Pytave is free software; you can redistribute it and/or modify |
222
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
7 ## it under the terms of the GNU General Public License as published |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
8 ## by the Free Software Foundation; either version 3 of the License, |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
9 ## or (at your option) any later version. |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
10 ## |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
11 ## This software is distributed in the hope that it will be useful, |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
13 ## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
14 ## the GNU General Public License for more details. |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
15 ## |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
16 ## You should have received a copy of the GNU General Public |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
17 ## License along with this software; see the file COPYING. |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
18 ## If not, see <http://www.gnu.org/licenses/>. |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
19 |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
20 ## -*- texinfo -*- |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
21 ## @documentencoding UTF-8 |
376
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
22 ## @defmethod @@pyobject methods (@var{x}) |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
23 ## @defmethodx @@pyobject methods (@var{x}, "-all") |
222
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
24 ## List the properties/callables of a Python object. |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
25 ## |
256 | 26 ## Returns a cell array of strings, the names of the ``callables'' |
27 ## of @var{x}. | |
222
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
28 ## |
376
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
29 ## If provided with an option @qcode{"-all"}, private methods are also included. |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
30 ## |
222
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
31 ## Example: |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
32 ## @example |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
33 ## @group |
250
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
34 ## pyexec ("import os") |
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
35 ## os = pyeval ("os"); |
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
36 ## methods (os) |
255
9eaed3b11829
Indicate this is a Python class/module in method output
Colin Macdonald <cbm@m.fsf.org>
parents:
254
diff
changeset
|
37 ## @print{} Methods for Python module 'os': |
250
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
38 ## @print{} ... |
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
39 ## @print{} chdir ... |
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
40 ## @print{} ... |
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
41 ## x = methods (os) |
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
42 ## @result{} x = |
222
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
43 ## @{ |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
44 ## [1,1] = ... |
254
a3660e7f8dc9
Make methods output shape consistent with fieldnames
Colin Macdonald <cbm@m.fsf.org>
parents:
250
diff
changeset
|
45 ## [2,1] = ... |
250
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
46 ## ... = chdir |
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
47 ## ... = getenv |
222
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
48 ## ... |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
49 ## @} |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
50 ## @end group |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
51 ## @end example |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
52 ## |
256 | 53 ## To get the properties (non-callables) of an object, |
54 ## @pxref{@@pyobject/fieldnames}. | |
55 ## | |
222
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
56 ## Note that if you instead want the methods implemented by |
257 | 57 ## the Octave class @code{@@pyobject}, you can always do: |
222
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
58 ## @example |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
59 ## @group |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
60 ## methods pyobject |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
61 ## @print{} Methods for class pyobject: |
302
de98627cf8ae
Minor fixes for failing doctests
Colin Macdonald <cbm@m.fsf.org>
parents:
298
diff
changeset
|
62 ## @print{} ... display ... |
222
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
63 ## @comment this doctest may need updating as we add methods |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
64 ## @end group |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
65 ## @end example |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
66 ## |
256 | 67 ## @seealso{methods, @@pyobject/fieldnames} |
222
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
68 ## @end defmethod |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
69 |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
70 |
376
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
71 function mtds = methods (x, option) |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
72 |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
73 if (nargin < 1 || nargin > 2) |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
74 print_usage (); |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
75 endif |
250
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
76 |
376
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
77 show_all = false; |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
78 if (nargin == 2) |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
79 if (ischar (option)) |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
80 switch (tolower (option)) |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
81 case "-all" |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
82 show_all = true; |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
83 otherwise |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
84 warning ("methods: unrecognized OPTION '%s'", option); |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
85 endswitch |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
86 else |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
87 error ("methods: OPTION must be a string"); |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
88 endif |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
89 endif |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
90 |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
91 query_end = ""; |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
92 if (! show_all) |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
93 query_end = "and not a.startswith('_')"; |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
94 endif |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
95 |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
96 query = sprintf (["lambda x: [a for a in dir(x)" ... |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
97 " if callable(getattr(x, a)) %s]"], query_end); |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
98 |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
99 cmd = pyeval (query); |
250
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
100 |
289
49832ca978fd
Use new subsref indexing to fix the failing tests
Abhinav Tripathi <genuinelucifer@gmail.com>
parents:
285
diff
changeset
|
101 mtds_list_obj = pycall (cmd, x); |
292
510ed59a61d3
pyobject: fix fieldnames and methods when result is an empty list
Mike Miller <mtmiller@octave.org>
parents:
289
diff
changeset
|
102 |
298
df1bddece9d5
Use subsref in "cell" method for casting to cell
Colin Macdonald <cbm@m.fsf.org>
parents:
292
diff
changeset
|
103 mtds_list = cellfun (@char, cell (mtds_list_obj), "uniformoutput", false); |
250
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
104 |
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
105 if (nargout == 0) |
367
9d7188514f2c
Use pyobject.isa instead of lambda to check Python types
Mike Miller <mtmiller@octave.org>
parents:
365
diff
changeset
|
106 if (isa (x, "py.types.ModuleType")) |
365
087e7bc3697f
Do not automatically convert Python strings to Octave strings (fixes issue #65)
Mike Miller <mtmiller@octave.org>
parents:
302
diff
changeset
|
107 modulename = char (pycall ("getattr", x, "__name__")); |
255
9eaed3b11829
Indicate this is a Python class/module in method output
Colin Macdonald <cbm@m.fsf.org>
parents:
254
diff
changeset
|
108 printf ("Methods for Python module '%s':\n", modulename); |
250
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
109 else |
373
0e4097c66788
Report a Python object's fully qualified class name correctly
Mike Miller <mtmiller@octave.org>
parents:
367
diff
changeset
|
110 printf ("Methods for Python class '%s':\n", __py_class_name__ (x)); |
250
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
111 endif |
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
112 disp (list_in_columns (mtds_list)); |
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
113 else |
254
a3660e7f8dc9
Make methods output shape consistent with fieldnames
Colin Macdonald <cbm@m.fsf.org>
parents:
250
diff
changeset
|
114 mtds = mtds_list(:); |
250
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
115 endif |
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
116 |
222
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
117 endfunction |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
118 |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
119 |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
120 %!test |
250
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
121 %! sys = pycall ("__import__", "sys"); |
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
122 %! m = methods (sys); |
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
123 %! assert (iscellstr (m)) |
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
124 %! assert (any (strcmp (m, "exit"))) |
222
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
125 |
e2e64ee571b7
pyobject: rename whatmethods to methods (fixes #21)
Colin Macdonald <cbm@m.fsf.org>
parents:
diff
changeset
|
126 %!test |
250
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
127 %! os = pycall ("__import__", "os"); |
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
128 %! m = methods (os); |
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
129 %! assert (iscellstr (m)) |
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
130 %! assert (any (strcmp (m, "chdir"))) |
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
131 %! assert (any (strcmp (m, "getcwd"))) |
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
132 %! assert (any (strcmp (m, "getenv"))) |
a4a2c214415e
@pyobject/methods: Only list callable methods, format output with no lvalue
Mike Miller <mtmiller@octave.org>
parents:
246
diff
changeset
|
133 %! assert (any (strcmp (m, "getpid"))) |
292
510ed59a61d3
pyobject: fix fieldnames and methods when result is an empty list
Mike Miller <mtmiller@octave.org>
parents:
289
diff
changeset
|
134 |
510ed59a61d3
pyobject: fix fieldnames and methods when result is an empty list
Mike Miller <mtmiller@octave.org>
parents:
289
diff
changeset
|
135 %!assert (methods (pyeval ("object()")), cell (0, 1)) |
510ed59a61d3
pyobject: fix fieldnames and methods when result is an empty list
Mike Miller <mtmiller@octave.org>
parents:
289
diff
changeset
|
136 %!assert (ismember ("append", methods (pyeval ("[]")))) |
510ed59a61d3
pyobject: fix fieldnames and methods when result is an empty list
Mike Miller <mtmiller@octave.org>
parents:
289
diff
changeset
|
137 %!assert (ismember ("keys", methods (pyeval ("{}")))) |
376
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
138 %!assert (! ismember ("__getslice__", methods (pyeval ("[]")))) |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
139 |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
140 %!assert (ismember ("__getslice__", methods (pyeval ("[]"), "-all"))) |
d1e00e614b4c
* @pyobject/methods.m: OPTION to view private methods added (fixes issue #22)
NVS Abhilash <nvs232@gmail.com>
parents:
373
diff
changeset
|
141 %!assert (ismember ("__repr__", methods (pyeval ("{}"), "-all"))) |