source: git/Tst/Short/pyobject.tst @ 5ebd4bc

spielwiese
Last change on this file since 5ebd4bc was 5ebd4bc, checked in by Alexander Dreyer <alexander.dreyer@…>, 12 years ago
fix: test for
  • Property mode set to 100644
File size: 2.6 KB
Line 
1LIB "tst.lib";
2tst_init();
3
4// Assignment of string literals and integers
5pyobject pystr = "a string literal";
6pyobject pyone = 1;
7
8
9pystr;
10pyone;
11
12
13// Checking python errors
14pystr + pyone;
15pystr();
16pystr(1, pyone);
17
18// Compute something in python
19def result = python_eval("4+5");
20result;
21
22int(result);
23
24// Execute python commands from Singular
25python_run("def myprint(*args): print args");
26
27myprint("Seventeen: ", 17);
28myprint();
29
30// Get type
31typeof(myprint);
32
33// Get String
34string(python_eval("'pystring'"));
35
36// Get attribute
37attrib(myprint, "func_name");
38
39// Check initialization
40pyobject empty;
41empty;
42typeof(empty);
43
44
45// python list from Singular list and access item
46pyobject ll = list(1, 2, 3);
47ll;
48ll[1];
49proc(attrib(ll,"__getitem__"))(2);
50
51
52//// Works, is PolyBoRi is also delivered
53// python_import("polybori");
54// declare_ring(list(Block("x", 10), Block("y", 10)));
55// list polybori_ideal = (x(1)+x(2),x(2)+y(1));
56// def result1 = groebner_basis(polybori_ideal);
57// result1;
58// typeof(result1);
59// result1[1];
60
61
62// Check whether already defined objects will be overwritten
63def already_defined = list(1);
64already_defined;
65
66python_run("def already_defined(): return 17");
67already_defined();
68
69def already_defined = "overwritten";
70already_defined;
71
72python_run("defined_by_python = range(10)");
73
74defined_by_python;
75python_run("del defined_by_python");
76
77// Should rise error message now:
78defined_by_python;
79
80// Test python import
81python_import("os");
82name;
83sep;
84linesep;
85
86// Numerical operations
87pyobject two = 2;
88pyobject three = 3;
89
90two + three;
91two - three;
92two * three;
93two / three;
94two ^ three;
95two ** three;
96
97three < two;
98two < three;
99three <= two;
100two <= three;
101two == three;
102two == two;
103three > two;
104two > three;
105three >= two;
106two >= three;
107two != two;
108two != three;
109
110pyobject pystr = "Hello";
111pystr + " World!";
112pystr * 3;
113
114// Test attrib command
115attrib(myprint);
116attrib(myprint, "func_name");
117attrib(myprint, "func_name", "byAnyOtherName");
118attrib(myprint, "func_name");
119
120pyobject pystr2 = "pypypypyp";
121proc(attrib(pystr2, "count"))("y");
122pystr2::"count"("p"); // simplified notation
123pystr2::count("y");   // even more simplified
124pystr2.count("y");    // simplest
125
126// testing member function call
127python_run("def new_pyobj(): pass");
128attrib(new_pyobj, "new_attr", "something");
129attrib(new_pyobj, "new_attr");
130attrib(new_pyobj);
131
132killattrib(new_pyobj, "new_attr");
133attrib(new_pyobj);
134
135killattrib(new_pyobj, "new_attr"); // -> error message
136killattrib(new_pyobj, 17);         // -> error message
137
138attrib(new_pyobj, "new_attr");     // -> error message
139
140// python list from empty Singular list (bug fixed?)
141pyobject ll_empty = list();
142ll_empty;
143
144
145tst_status(1);
146$
Note: See TracBrowser for help on using the repository browser.