Import LinuxCNC source tree
This commit is contained in:
8
tests/interp/python-self/README
Normal file
8
tests/interp/python-self/README
Normal file
@@ -0,0 +1,8 @@
|
||||
Exercise the behaviour of 'self' in Interpreter Embedded Python.
|
||||
|
||||
So far it wasn't possible to tack an attribute to self, and have it
|
||||
retained across several calls (basically using self.attr as extension
|
||||
of _setup on the Python side).
|
||||
|
||||
This test shows that attributes on 'self' were not retained across calls.
|
||||
A following patch will fix this.
|
||||
17
tests/interp/python-self/expected
Normal file
17
tests/interp/python-self/expected
Normal file
@@ -0,0 +1,17 @@
|
||||
executing
|
||||
1 N..... USE_LENGTH_UNITS(CANON_UNITS_MM)
|
||||
2 N..... SET_G5X_OFFSET(1, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000)
|
||||
3 N..... SET_G92_OFFSET(0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000)
|
||||
4 N..... SET_XY_ROTATION(0.0000)
|
||||
5 N..... SET_FEED_REFERENCE(CANON_XYZ)
|
||||
6 N..... ON_RESET()
|
||||
param1 was retained, value = 25.0
|
||||
this is self: True
|
||||
7 N..... SET_G5X_OFFSET(1, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000)
|
||||
8 N..... SET_XY_ROTATION(0.0000)
|
||||
9 N..... SET_FEED_MODE(0, 0)
|
||||
10 N..... SET_FEED_RATE(0.0000)
|
||||
11 N..... STOP_SPINDLE_TURNING(0)
|
||||
12 N..... SET_SPINDLE_MODE(0 0.0000)
|
||||
13 N..... PROGRAM_END()
|
||||
14 N..... ON_RESET()
|
||||
34
tests/interp/python-self/oword.py
Normal file
34
tests/interp/python-self/oword.py
Normal file
@@ -0,0 +1,34 @@
|
||||
# This is a component of LinuxCNC
|
||||
# Copyright 2012 Michael Haberler <git@mah.priv.at>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
import interpreter
|
||||
|
||||
def retainparam1(self,x):
|
||||
self.param1 = x
|
||||
|
||||
def checkparam1_retained(self):
|
||||
if hasattr(self,'param1'):
|
||||
print("param1 was retained, value = {}".format(self.param1))
|
||||
else:
|
||||
return "param1 was not retained across invocations"
|
||||
|
||||
# test object identity
|
||||
if hasattr(interpreter,'this'):
|
||||
print("this is self: {}".format(self is interpreter.this))
|
||||
else:
|
||||
print("module interpreter: no 'this' attribute")
|
||||
|
||||
27
tests/interp/python-self/subs.py
Normal file
27
tests/interp/python-self/subs.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# This is a component of LinuxCNC
|
||||
# Copyright 2012 Michael Haberler <git@mah.priv.at>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
import oword
|
||||
import interpreter
|
||||
|
||||
def __init__(self):
|
||||
if hasattr(interpreter,'this'):
|
||||
if self is not interpreter.this:
|
||||
print("__init__: self not is this")
|
||||
else:
|
||||
print("__init__: no 'this' attribute")
|
||||
|
||||
13
tests/interp/python-self/test.ini
Normal file
13
tests/interp/python-self/test.ini
Normal file
@@ -0,0 +1,13 @@
|
||||
[EMC]
|
||||
DEBUG=0
|
||||
LOG_LEVEL=0
|
||||
|
||||
[RS274NGC]
|
||||
SUBROUTINE_PATH = .
|
||||
|
||||
[PYTHON]
|
||||
PATH_PREPEND=.
|
||||
TOPLEVEL=subs.py
|
||||
|
||||
|
||||
|
||||
15
tests/interp/python-self/test.ngc
Normal file
15
tests/interp/python-self/test.ngc
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
;py,import interpreter
|
||||
|
||||
; pass value to Python and store in a self.attribute
|
||||
o<retainparam1> call [25.0]
|
||||
|
||||
; now check it's still there
|
||||
o<checkparam1_retained> call
|
||||
|
||||
; since 'self' is aliased to 'interpreter.this'
|
||||
; the same value must show up here too:
|
||||
|
||||
;py,assert interpreter.this.param1 == 25.0
|
||||
M2
|
||||
|
||||
3
tests/interp/python-self/test.sh
Executable file
3
tests/interp/python-self/test.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
export PYTHONUNBUFFERED=1
|
||||
exec rs274 -i test.ini -n 0 -g test.ngc 2>&1
|
||||
Reference in New Issue
Block a user