python func validation ok.

This commit is contained in:
2026-02-15 15:50:10 +01:00
parent 1da1b2f9fd
commit 02f93df1d5
6 changed files with 150 additions and 142 deletions

View File

@@ -64,6 +64,9 @@ In the example above, the global variable ``$(lfn_activity)``
would be created at the end of the item execution. It would contain the resulting would be created at the end of the item execution. It would contain the resulting
value of the funcToBeExecuted python function. value of the funcToBeExecuted python function.
The ``lua_func`` will always result ``PASS``, except if the called function raises
and exception or if the ``expected_result`` attribute is used.
**Lua Interpreter environment setup** **Lua Interpreter environment setup**
Some global variables have an impact on the ``lua_func`` test item behavior: Some global variables have an impact on the ``lua_func`` test item behavior:

View File

@@ -6,9 +6,9 @@
The ``py_func`` test item is used to execute custom python scripts with the given The ``py_func`` test item is used to execute custom python scripts with the given
input parameters. input parameters.
There are two modes for executing a ``py_func`` item. The class mode and the function mode. There are two modes for executing a ``py_func`` item. The *class* mode and the *function* mode.
class py_func item class ``py_func`` item
------------------------- -------------------------
This is the normal way of calling some custom python code. This is the normal way of calling some custom python code.
@@ -80,7 +80,8 @@ There is no possibility to access the report features in that mode.
**Attributes** **Attributes**
Beside common test items attributes, py_func item has specific attribute, some of which being mandatory. Beside common test items attributes, ``py_func`` item has specific attribute,
some of which being mandatory.
* ``file``: the script file name that contains the function to be executed. * ``file``: the script file name that contains the function to be executed.
Only python script format is supported. Only python script format is supported.
@@ -107,6 +108,9 @@ In the example above, the global variable ``$(pfn_function test item)``
would be created at the end of the item execution. It would contain the resulting would be created at the end of the item execution. It would contain the resulting
value of the funcToBeExecuted python function. value of the funcToBeExecuted python function.
The ``py_func`` will always result ``PASS``, except if the called function raises
and exception or if the ``expected_result`` attribute is used.
**Python Interpreter environment setup** **Python Interpreter environment setup**
Some global variables have an impact on the ``py_func`` test item behavior: Some global variables have an impact on the ``py_func`` test item behavior:

View File

@@ -7,6 +7,7 @@ import libs.testium as tm
from interpreter.utils.paths import sys_app_path_lin, sys_app_path_win from interpreter.utils.paths import sys_app_path_lin, sys_app_path_win
from interpreter.utils.tum_except import ETUMRuntimeError from interpreter.utils.tum_except import ETUMRuntimeError
from interpreter.utils.jrpc import JsonRpcClient from interpreter.utils.jrpc import JsonRpcClient
from interpreter.utils.paths import testium_path
from interpreter.test_items.test_result import TestValue from interpreter.test_items.test_result import TestValue
function_call_process = None function_call_process = None
@@ -147,7 +148,7 @@ class LuaFuncExecEngine:
) )
tm.setgd("lua_bin", lua_bin) tm.setgd("lua_bin", lua_bin)
self._lpath = lua_bin self._lbin = lua_bin
self._req_handler = request_handler self._req_handler = request_handler
self._process = None self._process = None
self._port = 0 self._port = 0
@@ -168,7 +169,7 @@ class LuaFuncExecEngine:
if self._process is not None: if self._process is not None:
raise ETUMRuntimeError("The function subprocess has already been started.") raise ETUMRuntimeError("The function subprocess has already been started.")
func_proc_path = os.path.join(tm.gd("testium_path"),"lua_func") func_proc_path = os.path.realpath(os.path.join(testium_path(), "..", "lua_func"))
# POpen config # POpen config
CUST_ENV = { CUST_ENV = {
@@ -190,9 +191,10 @@ class LuaFuncExecEngine:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(("localhost", 0)) sock.bind(("localhost", 0))
self._port = sock.getsockname()[1] self._port = sock.getsockname()[1]
sock.close()
# POpen params # POpen params
params = [self._lpath, "main.lua", "--timeout", f"{self._timeout}", "--host", "127.0.0.1", "--port", f"{self._port}"] params = [self._lbin, "main.lua", "--timeout", f"{self._timeout}", "--host", "127.0.0.1", "--port", f"{self._port}"]
if tm.debug_enabled() and tm.gd("debug_rpc", False): if tm.debug_enabled() and tm.gd("debug_rpc", False):
params.append("--verbose") params.append("--verbose")
@@ -201,10 +203,6 @@ class LuaFuncExecEngine:
params, env=env, cwd=func_proc_path params, env=env, cwd=func_proc_path
) )
# Port was reserved until the sub-process is started. Now released.
if sock is not None:
sock.close()
self._rpc = JsonRpcClient("localhost", self._port, req_handler=self._req_handler) self._rpc = JsonRpcClient("localhost", self._port, req_handler=self._req_handler)
if tm.debug_enabled() and tm.gd("debug_rpc", False): if tm.debug_enabled() and tm.gd("debug_rpc", False):
self._rpc.dbg_out = sys.stdout self._rpc.dbg_out = sys.stdout

View File

@@ -1,73 +1,61 @@
- let:
name: func test constants,
values:
test parameter: test parameter
- py_func: - lua_func:
name: pass func name: fail lua_func
key: $(test)_PASS
file: $(test_path)$(psep)func.py
func_name: assertparam
param:
- true
- py_func:
name: fail func
key: $(test)_FAIL key: $(test)_FAIL
file: $(test_path)$(psep)func.py file: $(test_path)$(psep)lua_func.lua
func_name: assertparam func_name: assertparam
param: param:
- false - false
- py_func: - lua_func:
name: fail func with expected result "FAIL" name: fail lua_func with expected result FAIL
key: $(test)_PASS key: $(test)_PASS
file: $(test_path)$(psep)func.py file: $(test_path)$(psep)lua_func.lua
func_name: assertparam func_name: assertparam
param: param:
- false - false
expected_result: FAIL expected_result: FAIL
- py_func: - lua_func:
name: pass func with expected result FAIL name: pass lua_func with expected result FAIL
key: $(test)_FAIL key: $(test)_FAIL
file: $(test_path)$(psep)func.py file: $(test_path)$(psep)lua_func.lua
func_name: assertparam func_name: assertparam
param: param:
- true - true
expected_result: FAIL expected_result: FAIL
- py_func: - lua_func:
name: expected -1 name: expected -1
key: $(test)_PASS key: $(test)_PASS
file: $(test_path)$(psep)func.py file: $(test_path)$(psep)lua_func.lua
func_name: echo func_name: echo
param: param:
- -1 - -1
expected_result: -1 expected_result: -1
- py_func: - lua_func:
name: expected eval name: expected eval
key: $(test)_PASS key: $(test)_PASS
file: $(test_path)$(psep)func.py file: $(test_path)$(psep)lua_func.lua
func_name: echo func_name: echo
param: param:
- -1 - -1
expected_result: "354848436 - 354848437" expected_result: "354848436 - 354848437"
- py_func: - lua_func:
name: expected table name: expected table
key: $(test)_PASS key: $(test)_PASS
file: $(test_path)$(psep)func.py file: $(test_path)$(psep)lua_func.lua
func_name: echo func_name: echo
param: param:
- [-1, a, {toto: tata}] - [-1, a, {toto: tata}]
expected_result: "[-1, 'a', {'toto': 'tata'}]" expected_result: "[-1, 'a', {'toto': 'tata'}]"
- py_func: - lua_func:
name: global param func name: global param lua_func
key: $(test)_PASS key: $(test)_PASS
file: $(test_path)$(psep)func.py file: $(test_path)$(psep)lua_func.lua
func_name: checkglobal func_name: checkglobal
param: param:
- $(test parameter) - $(test parameter)
@@ -76,50 +64,50 @@
name: python2func name: python2func
key: $(test)_PASS key: $(test)_PASS
values: values:
- py: $(test_path)$(psep)func.py - py: $(test_path)$(psep)lua_func.lua
- py_func: - lua_func:
name: global param func name: global param lua_func
key: $(test)_PASS key: $(test)_PASS
file: $(py) file: $(py)
func_name: checkglobal func_name: checkglobal
param: param:
- $(test parameter) - $(test parameter)
- py_func: - lua_func:
name: skipped_checkglobal name: skipped_checkglobal
file: $(test_path)$(psep)func.py file: $(test_path)$(psep)lua_func.lua
func_name: should_not_be_called func_name: should_not_be_called
param: param:
- $(test parameter) - $(test parameter)
- py_func: - lua_func:
name: skipped true name: skipped true
file: $(test_path)$(psep)func.py file: $(test_path)$(psep)lua_func.lua
func_name: checkglobal func_name: checkglobal
skipped: true skipped: true
param: param:
- $(test parameter) - $(test parameter)
- py_func: - lua_func:
name: skipped true name: skipped true
file: $(test_path)$(psep)func.py file: $(test_path)$(psep)lua_func.lua
func_name: checkglobal func_name: checkglobal
skipped: true skipped: true
param: param:
- $(test parameter) - $(test parameter)
- py_func: - lua_func:
name: skipped 1 name: skipped 1
file: $(test_path)$(psep)func.py file: $(test_path)$(psep)lua_func.lua
func_name: checkglobal func_name: checkglobal
skipped: 1 skipped: 1
param: param:
- $(test parameter) - $(test parameter)
- py_func: - lua_func:
name: FunctionItem test name: FunctionItem test
file: $(test_path)$(psep)func.py file: $(test_path)$(psep)lua_func.lua
func_name: ValidationTest func_name: ValidationTest
param: param:
- $(test parameter) - $(test parameter)
@@ -130,54 +118,54 @@
- group: - group:
name: Function result failure name: Function result failure
steps: steps:
- py_func: - lua_func:
name: int failure name: int failure
key: $(test)_FAIL key: $(test)_PASS
file: $(test_path)$(psep)func.py file: $(test_path)$(psep)lua_func.lua
func_name: echo func_name: echo
param: [-1] param: [-1]
- py_func: - lua_func:
name: float failure name: float failure
key: $(test)_FAIL key: $(test)_PASS
file: $(test_path)$(psep)func.py file: $(test_path)$(psep)lua_func.lua
func_name: echo func_name: echo
param: [-1.3] param: [-1.3]
- py_func: - lua_func:
name: String failure name: String failure
key: $(test)_FAIL key: $(test)_PASS
file: $(test_path)$(psep)func.py file: $(test_path)$(psep)lua_func.lua
func_name: echo func_name: echo
param: [ "FAIL" ] param: [ "FAIL" ]
- py_func: - lua_func:
name: Tuple int,str failure name: Tuple int,str failure
key: $(test)_FAIL key: $(test)_PASS
file: $(test_path)$(psep)func.py file: $(test_path)$(psep)lua_func.lua
func_name: tuple_return func_name: tuple_return
param: [ -1, "Got a failure" ] param: [ -1, "Got a failure" ]
- group: - group:
name: Functions result success name: Functions result success
steps: steps:
- py_func: - lua_func:
name: int success name: int success
key: $(test)_PASS key: $(test)_PASS
file: $(test_path)$(psep)func.py file: $(test_path)$(psep)lua_func.lua
func_name: echo func_name: echo
param: [0] param: [0]
- py_func: - lua_func:
name: float success name: float success
key: $(test)_PASS key: $(test)_PASS
file: $(test_path)$(psep)func.py file: $(test_path)$(psep)lua_func.lua
func_name: echo func_name: echo
param: [0.3] param: [0.3]
- py_func: - lua_func:
name: String success name: String success
key: $(test)_PASS key: $(test)_PASS
file: $(test_path)$(psep)func.py file: $(test_path)$(psep)lua_func.lua
func_name: echo func_name: echo
param: [ "Something that is not only strictly FAIL" ] param: [ "Something that is not only strictly FAIL" ]
- py_func: - lua_func:
name: Tuple int,str success name: Tuple int,str success
key: $(test)_PASS key: $(test)_PASS
file: $(test_path)$(psep)func.py file: $(test_path)$(psep)lua_func.lua
func_name: tuple_return func_name: tuple_return
param: [ 0, "OK" ] param: [ 0, "OK" ]

View File

@@ -16,6 +16,9 @@ def checkglobal(param):
assert param=='test parameter' assert param=='test parameter'
return 0 return 0
def checkglobal2():
return tm.gd("py_func test parameter")
def should_not_be_called(param): def should_not_be_called(param):
raise raise

View File

@@ -1,179 +1,191 @@
- let:
name: py_func test constants,
values:
py_func test parameter: test parameter
- lua_func: - py_func:
name: pass lua_func name: pass py_func
key: $(test)_PASS key: $(test)_PASS
file: lua_func.lua file: $(test_path)$(psep)py_func.py
func_name: func_to_be_executed func_name: assertparam
param: param:
- true - true
- lua_func: - py_func:
name: fail lua_func name: fail py_func
key: $(test)_FAIL key: $(test)_FAIL
file: $(test_path)$(psep)lua_func.lua file: $(test_path)$(psep)py_func.py
func_name: assertparam func_name: assertparam
param: param:
- false - false
- lua_func: - py_func:
name: fail lua_func with expected result FAIL name: fail py_func with expected result "FAIL"
key: $(test)_PASS key: $(test)_PASS
file: $(test_path)$(psep)lua_func.lua file: $(test_path)$(psep)py_func.py
func_name: assertparam func_name: assertparam
param: param:
- false - false
expected_result: FAIL expected_result: FAIL
- lua_func: - py_func:
name: pass lua_func with expected result FAIL name: pass py_func with expected result FAIL
key: $(test)_FAIL key: $(test)_FAIL
file: $(test_path)$(psep)lua_func.lua file: $(test_path)$(psep)py_func.py
func_name: assertparam func_name: assertparam
param: param:
- true - true
expected_result: FAIL expected_result: FAIL
- lua_func: - py_func:
name: expected -1 name: expected -1
key: $(test)_PASS key: $(test)_PASS
file: $(test_path)$(psep)lua_func.lua file: $(test_path)$(psep)py_func.py
func_name: echo func_name: echo
param: param:
- -1 - -1
expected_result: -1 expected_result: -1
- lua_func: - py_func:
name: expected eval name: expected eval
key: $(test)_PASS key: $(test)_PASS
file: $(test_path)$(psep)lua_func.lua file: $(test_path)$(psep)py_func.py
func_name: echo func_name: echo
param: param:
- -1 - -1
expected_result: "354848436 - 354848437" expected_result: "354848436 - 354848437"
- lua_func: - py_func:
name: expected table name: expected table
key: $(test)_PASS key: $(test)_PASS
file: $(test_path)$(psep)lua_func.lua file: $(test_path)$(psep)py_func.py
func_name: echo func_name: echo
param: param:
- [-1, a, {toto: tata}] - [-1, a, {toto: tata}]
expected_result: "[-1, 'a', {'toto': 'tata'}]" expected_result: "[-1, 'a', {'toto': 'tata'}]"
- lua_func: - py_func:
name: global param lua_func name: global param py_func
key: $(test)_PASS key: $(test)_PASS
file: $(test_path)$(psep)lua_func.lua file: $(test_path)$(psep)py_func.py
func_name: checkglobal func_name: checkglobal
param: param:
- $(test parameter) - $(py_func test parameter)
- let: - let:
name: python2func name: python2func
key: $(test)_PASS key: $(test)_PASS
values: values:
- py: $(test_path)$(psep)lua_func.lua - py: $(test_path)$(psep)py_func.py
- lua_func: - py_func:
name: global param lua_func name: global param py_func 2
key: $(test)_PASS
file: $(py)
func_name: checkglobal2
expected_result: $(py_func test parameter)
- py_func:
name: global param py_func
key: $(test)_PASS key: $(test)_PASS
file: $(py) file: $(py)
func_name: checkglobal func_name: checkglobal
param: param:
- $(test parameter) - $(py_func test parameter)
- lua_func: - py_func:
name: skipped_checkglobal name: skipped_checkglobal
file: $(test_path)$(psep)lua_func.lua file: $(test_path)$(psep)py_func.py
func_name: should_not_be_called func_name: should_not_be_called
param: param:
- $(test parameter) - $(py_func test parameter)
- lua_func: - py_func:
name: skipped true name: skipped true
file: $(test_path)$(psep)lua_func.lua file: $(test_path)$(psep)py_func.py
func_name: checkglobal func_name: checkglobal
skipped: true skipped: true
param: param:
- $(test parameter) - $(py_func test parameter)
- lua_func: - py_func:
name: skipped true
file: $(test_path)$(psep)lua_func.lua
func_name: checkglobal
skipped: true
param:
- $(test parameter)
- lua_func:
name: skipped 1 name: skipped 1
file: $(test_path)$(psep)lua_func.lua file: $(test_path)$(psep)py_func.py
func_name: checkglobal func_name: checkglobal
skipped: 1 skipped: 1
param: param:
- $(test parameter) - $(py_func test parameter)
- lua_func: - py_func:
name: FunctionItem test name: FunctionItem test
file: $(test_path)$(psep)lua_func.lua file: $(test_path)$(psep)py_func.py
func_name: ValidationTest func_name: ValidationTest
param: param:
- $(test parameter) - $(py_func test parameter)
- group: - group:
name: Function results check name: Function results check
steps: steps:
- group: - group:
name: Function result failure name: Function result 1
steps: steps:
- lua_func: - py_func:
name: int failure name: int failure
key: $(test)_FAIL key: $(test)_PASS
file: $(test_path)$(psep)lua_func.lua file: $(test_path)$(psep)py_func.py
func_name: echo func_name: echo
param: [-1] param: [-1]
- lua_func: expected_result: -1
- py_func:
name: float failure name: float failure
key: $(test)_FAIL key: $(test)_PASS
file: $(test_path)$(psep)lua_func.lua file: $(test_path)$(psep)py_func.py
func_name: echo func_name: echo
param: [-1.3] param: [-1.3]
- lua_func: expected_result: -1.3
- py_func:
name: String failure name: String failure
key: $(test)_FAIL key: $(test)_PASS
file: $(test_path)$(psep)lua_func.lua file: $(test_path)$(psep)py_func.py
func_name: echo func_name: echo
param: [ "FAIL" ] param: [ "FAIL" ]
- lua_func: expected_result: FAIL
- py_func:
name: Tuple int,str failure name: Tuple int,str failure
key: $(test)_FAIL key: $(test)_PASS
file: $(test_path)$(psep)lua_func.lua file: $(test_path)$(psep)py_func.py
func_name: tuple_return func_name: tuple_return
param: [ -1, "Got a failure" ] param: [ -1, "Got a failure" ]
expected_result: [-1, "Got a failure"]
- group: - group:
name: Functions result success name: Functions result 2
steps: steps:
- lua_func: - py_func:
name: int success name: int success
key: $(test)_PASS key: $(test)_PASS
file: $(test_path)$(psep)lua_func.lua file: $(test_path)$(psep)py_func.py
func_name: echo func_name: echo
param: [0] param: [0]
- lua_func: expected_result: 0
- py_func:
name: float success name: float success
key: $(test)_PASS key: $(test)_PASS
file: $(test_path)$(psep)lua_func.lua file: $(test_path)$(psep)py_func.py
func_name: echo func_name: echo
param: [0.3] param: [0.3]
- lua_func: expected_result: 0.3
- py_func:
name: String success name: String success
key: $(test)_PASS key: $(test)_PASS
file: $(test_path)$(psep)lua_func.lua file: $(test_path)$(psep)py_func.py
func_name: echo func_name: echo
param: [ "Something that is not only strictly FAIL" ] param: [ "Something that is not only strictly FAIL" ]
- lua_func: expected_result: Something that is not only strictly FAIL
- py_func:
name: Tuple int,str success name: Tuple int,str success
key: $(test)_PASS key: $(test)_PASS
file: $(test_path)$(psep)lua_func.lua file: $(test_path)$(psep)py_func.py
func_name: tuple_return func_name: tuple_return
param: [ 0, "OK" ] param: [ 0, "OK" ]
expected_result: [0, "OK"]