]> gerrit.simantics Code Review - simantics/python.git/blobdiff - org.simantics.pythonlink/test/org/simantics/pythonlink/test/scripts/Python.sts
Initial commit of Python Integration feature.
[simantics/python.git] / org.simantics.pythonlink / test / org / simantics / pythonlink / test / scripts / Python.sts
diff --git a/org.simantics.pythonlink/test/org/simantics/pythonlink/test/scripts/Python.sts b/org.simantics.pythonlink/test/org/simantics/pythonlink/test/scripts/Python.sts
new file mode 100644 (file)
index 0000000..409d9b2
--- /dev/null
@@ -0,0 +1,48 @@
+> import "Simantics/Python"\r
+> import "Vector"\r
+> \r
+> runPython do\r
+>     executePythonStatement "foo = 'bar'\nd = dir()"\r
+>     getPythonStringArrayVariable "d"\r
+vector ["__builtins__", "__doc__", "__loader__", "__name__", "__package__", "__spec__", "foo"]\r
+> runPython do\r
+>     setPythonDoubleVariable "foo" 1\r
+>     executePythonStatement "foo = foo + 1"\r
+>     getPythonDoubleVariable "foo"\r
+2.0\r
+> runPython do\r
+>     setPythonDoubleArrayVariable "foo" (vector [1.0, 2.0, 3.0])\r
+>     executePythonStatement "foo = foo + [4.0]"\r
+>     getPythonDoubleArrayVariable "foo"\r
+vector [1.0, 2.0, 3.0, 4.0]\r
+> runPython do\r
+>     setPythonIntegerVariable "foo" 5\r
+>     executePythonStatement "import math"\r
+>     executePythonStatement "bar = math.factorial(foo)"\r
+>     getPythonIntegerVariable "bar"\r
+120\r
+> runPython do\r
+>     setPythonIntegerArrayVariable "foo" (vector [1, 2, 3, 4])\r
+>     executePythonStatement "foo.append(sum(foo))"\r
+>     getPythonIntegerArrayVariable "foo"\r
+vector [1, 2, 3, 4, 10]\r
+> ndarray (vector [1, 2, 3])\r
+ndarray(3) [1.0, 2.0, 3.0]\r
+> ndarrayM 2 2 (vector [1, 2, 3, 4])\r
+ndarray(2x2) [1.0, 2.0, 3.0, 4.0]\r
+> a = ndarrayN (vector [2, 2, 3]) (vector [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])\r
+> a\r
+ndarray(2x2x3) [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, ...]\r
+> ndarrayDims a\r
+vector [2, 2, 3]\r
+> ndarrayValues a\r
+vector [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0]\r
+> ndarrayElement a 5\r
+6.0\r
+> ndarrayElementN a (vector [0, 1, 2])\r
+6.0\r
+> runPython do\r
+>     setPythonNDArrayVariable "foo" (ndarrayM 2 3 (vector [1, 2, 3,  4, 5, 6]))\r
+>     executePythonStatement "bar = foo.cumsum(1)"\r
+>     getPythonNDArrayVariable "bar"\r
+ndarray(2x3) [1.0, 3.0, 6.0, 4.0, 9.0, 15.0]\r