removed support of xml and json config.

Changed the evaluation pattern to $|x|.
This commit is contained in:
2026-01-04 15:10:11 +01:00
parent 5a86e498d2
commit 0459c9ff27
19 changed files with 37 additions and 129 deletions

View File

@@ -1,4 +0,0 @@
<?xml version="1.0" ?>
<root>
<parameter name="func_param" value="param"/>
</root>

View File

@@ -0,0 +1 @@
func_param: param

View File

@@ -2,10 +2,8 @@
#
config_file:
- param.xml
- param.yaml
- param.json
- $(test_directory)/dummy/param_func.xml
- $(test_directory)/dummy/param_func.yaml
main:
name: Test Sample number one

View File

@@ -1,4 +0,0 @@
{
"global_loop_param_list": [["one", "two", "three"],[1, 2, 3]]
}

View File

@@ -1,9 +0,0 @@
<?xml version="1.0" ?>
<root>
<!-- ****************************************************************************
Test configuration
**************************************************************************** -->
<parameter name="windows_prompt" value=">"/>
<parameter name="linux_prompt" value="$"/>
<parameter name="sequence" value="tm.tum"/>
</root>

View File

@@ -2,7 +2,12 @@
#****************************************************************************
# Test configuration
#**************************************************************************** -->
windows_prompt: >
linux_prompt: $
sequence: tm.tum
# loops parameters
global_loop_param_list: [["one", "two", "three"], [1, 2, 3]]
global_loop_param_txt: ['one', 'two', 'three']
global_loop_param_num: [1, 2, 3]

View File

@@ -34,7 +34,7 @@ sequences of tests can be called interactively.
:caption: call a test in terminal mode
$ testium -m
Configuration file loaded: /my/execution/path/param.xml
Configuration file loaded: /my/execution/path/param.yaml
[...]
================================================================================
====== Test configuration

View File

@@ -195,8 +195,8 @@ Export attribute
key:
- GID-1510554_step_1
report:
reported_list: @| random.sample(range(0,20), k=10) |
reported_float: @| math.sqrt(float(1)) |
reported_list: $| random.sample(range(0,20), k=10) |
reported_float: $| math.sqrt(float(1)) |
reported_str: This is my reported sentence

View File

@@ -39,7 +39,7 @@ Configuration files
A configuration file can be specified in the `.tum` file or by the command line.
This configuration file is optional and must be a YAML file.
The type of file is recognized by the file name extension `.yaml`.
The configuration files must have the `.yaml` or `.yml` file name extension.
During the test script loading process, the values defined in these configuration files
are added to the global variables and are then accessible from the test items and scripts
@@ -63,7 +63,7 @@ The parameter file can be specified in the `.tum` file root:
parameter1: value1
parameter2: 1234
parameter3: @| 12.34 * 2 |
parameter3: $| 12.34 * 2 |
parameter4:
- $(parameter1)
- $(parameter3)
@@ -106,8 +106,11 @@ Another possible usage of the global variables is to share persistent data betwe
A library allowing python functions to access global variables is available from the
python scripts. See details in section :ref:`helper library<sec_python_helper_library>`.
Apart from the value obtained from the param.xml file, the global varibles entries
contains also built-in specific value, and test item specific values.
Apart from the value obtained from the default `param.yaml` or defined configuration files,
the global variables entries contains also
* built-in specific value (see :ref:`below<sec_global_variables_builtin>`),
* values returned by test items.
.. _sec_global_variables_builtin:
@@ -202,7 +205,7 @@ The variable substitution is recursive and checks all the occurrences of the
``$(x)`` pattern in a string.
It is also possible to perform evaluation of python substrings during parameters passing.
It is done by using the ``@| expr |`` pattern in a string.
It is done by using the ``$| expr |`` pattern in a string.
`expr` may then be a correct python expression.
Below are illustrated simple and more complicated cases of expansion and evaluation depending on
@@ -215,10 +218,10 @@ their pattern.
name: Dynamic variables expansion
key: $(test)_PASS
values:
- expanse_select: @|"$(expanse_select)".replace("o", "a")|
- expanse_select: $|"$(expanse_select)".replace("o", "a")|
- expanse_index: $(expanse_index_$(expanse_select))
- expanse_table: $(expanse_table_$(expanse_select))
- expanse_eval: @|$(expanse_index) == 1|
- expanse_eval: $|$(expanse_index) == 1|
Test Items
--------------------

Binary file not shown.

View File

@@ -143,7 +143,7 @@ class TestItem:
f"'{self.cmd()}' test item named '{self.name()}':\nskipped expresion can only be a static expression as it is evaluated during loading of TUM : {s}",
self.seqFilename(),
)
# This allow disabling test item directly by using its name inside param.xml file
# This allow disabling test item directly by using its name inside param.yaml file
elif self._name in tm.gd("skipped_test_item", []):
self.skipped = True
else:

View File

@@ -1,6 +1,5 @@
import sys
import traceback
from functools import wraps
from random import randint
from interpreter.utils.tum_except import ETUMSyntaxError

View File

@@ -313,12 +313,12 @@ def _preprocess_string(value, parent=None):
def _eval_param(value):
"""This function parses a string value to check if patterns corresponding
to @|xxx| exists.
to $|xxx| exists.
When this kind of pattern is found, an attempt to evaluate its
content is done.
If it is not evaluable, not replaced.
"""
return _parse_and_process("@|", "|", value, evaluate)
return _parse_and_process("$|", "|", value, evaluate)
def _process_recursively(func, param_value, *fparams):

View File

@@ -5,7 +5,6 @@ from socket import gethostname
import ast
import json
import yaml
import xml.etree.ElementTree as ET
import copy
import yaml
@@ -78,7 +77,7 @@ def _locate_config_files(test_dir, config_files, silent=False):
ret = []
pf = []
if len(config_files) == 0:
for p in ['param.xml', 'param.yaml', 'param.json']:
for p in ['param.yaml', 'param.yml']:
param_filename = os.path.join(test_dir, p)
if os.path.exists(param_filename):
pf.append(param_filename)
@@ -210,55 +209,6 @@ def load_test(test_file, test_dir, cmdline_pfs, cmdline_defs):
return test_dict, new_pfs
def xmltodict(xml_param_file, silent=True):
""" return a dictionnarie of parameter from xml file.
"""
tag = 'parameter'
returned_dict = {}
returned_str_dict = {}
xml_tree = ET.parse(xml_param_file)
xml_root = xml_tree.getroot()
xml_params = xml_root.findall(tag)
for param in xml_params:
name = param.get('name', '')
if name != '':
v = param.get('value', None)
if v is None:
v = param.get('str', '')
v = v.replace("\\n", "\n")
v = v.replace("\\r", "\r")
v = v.replace("\\t", "\t")
returned_str_dict[name] = v
else:
v = v.replace("\\n", "\n")
v = v.replace("\\r", "\r")
v = v.replace("\\t", "\t")
returned_dict[name] = v
# reinitializes the global dict values with the xml file content
globdict.global_dict.update(returned_str_dict)
globdict.global_dict.update(returned_dict)
for i in range(10):
for key, val in returned_dict.items():
val = expanse(val)
returned_dict.update({key: val})
globdict.global_dict.update(returned_dict)
if not silent:
if not tm.debug_enabled():
tm.print_info(f"\"{xml_param_file}\" loaded.")
else:
tm.print_debug(f"\"{xml_param_file}\" loading:")
for k, v in returned_str_dict.items():
tm.print_debug(f" {k}: {v}")
for k, v in returned_dict.items():
tm.print_debug(f" {k}: {v}")
tm.print_debug(f"done.")
def yamltodict(param_file, silent=True):
# load of the file
with open(param_file, 'r') as fd:
@@ -290,33 +240,6 @@ def yamltodict(param_file, silent=True):
globdict.global_dict.update(dp)
def jsontodict(param_file, silent=True):
with open(param_file, 'r') as fd:
s = fd.read()
dp = json.loads(s)
# update the global dict with raw data
globdict.global_dict.update(dp)
# Apply variables expansion
for i in range(10):
for key, val in dp.items():
val = expanse(val)
dp.update({key: val})
if not silent:
if not tm.debug_enabled():
tm.print_info(f"\"{param_file}\" loaded.")
else:
tm.print_debug(f"\"{param_file}\" loading:")
for k, v in dp.items():
tm.print_debug(f" {k}: {v}")
tm.print_debug(f"done.")
# Finalize the global dict update
globdict.global_dict.update(dp)
def _feed_gd_with_params(param_file, silent=True):
test_dir = tm.gd('test_directory')
# param files pre-processing
@@ -340,15 +263,11 @@ def _feed_gd_with_params(param_file, silent=True):
raise ETUMSyntaxError(f'Parameter file "{pf}" not found')
ext = os.path.splitext(pf)[1]
if ext == '.xml':
xmltodict(pf, silent)
elif ext == '.json':
jsontodict(pf, silent)
elif ext == '.yaml':
if (ext == '.yaml') or (ext == '.yml'):
yamltodict(pf, silent)
else:
raise ETUMSyntaxError(
'config files must be "*.xml", "*.yaml" or "*.json"')
'config files must be "*.yaml" or "*.yml"')
def set_standard_gd_keys(test_name, test_dir, test_file, config_files):

View File

@@ -138,7 +138,7 @@
- py_func:
name: Return True expect False but no_fail expansed
no_fail: @| bool(0) == False |
no_fail: $| bool(0) == False |
key: $(test)_PASS
file: $(test_path)$(psep)results$(psep)results.py
func_name: echo
@@ -147,7 +147,7 @@
- py_func:
name: Return True expect False but no_fail expansed (must fail)
no_fail: @| bool(1) == False |
no_fail: $| bool(1) == False |
key: $(test)_FAIL
file: $(test_path)$(psep)results$(psep)results.py
func_name: echo

View File

@@ -9,4 +9,4 @@ expanse_index_blo: 1
expanse_index: $(expanse_index_$(expanse_select))
expanse_table: $(expanse_table_$(expanse_select))
expanse_eval: @|$(expanse_index) == 1|
expanse_eval: $|$(expanse_index) == 1|

View File

@@ -10,10 +10,10 @@
name: Dynamic variables expansion
key: $(test)_PASS
values:
- expanse_select: @|"$(expanse_select)".replace("o", "a")|
- expanse_select: $|"$(expanse_select)".replace("o", "a")|
- expanse_index: $(expanse_index_$(expanse_select))
- expanse_table: $(expanse_table_$(expanse_select))
- expanse_eval: @|$(expanse_index) == 1|
- expanse_eval: $|$(expanse_index) == 1|
- check:
name: Check variables expansion is correct (PASS)
@@ -33,7 +33,7 @@
- var4: blo
- expanse_var_bla: 3
- expanse_blo_var: 5
- expanse_complex: @|@|$(expanse_$(var2)_$(var3))*6| + @|4*$($(var1)_$(var4)_$(var2))||
- expanse_complex: $|$|$(expanse_$(var2)_$(var3))*6| + $|4*$($(var1)_$(var4)_$(var2))||
- check:
name: Check complex variables expansion is correct (PASS)
@@ -50,10 +50,10 @@
- expanse_var_2: 6
- expanse_object:
[
{ a: $(expanse_var_2), $(expanse_key): @|2**3| },
{ a: $(expanse_var_2), $(expanse_key): $|2**3| },
{
'@|"bla".replace("a", "o")|':
[@|$(expanse_var)*$(expanse_var_2)|, 25],
'$|"bla".replace("a", "o")|':
[$|$(expanse_var)*$(expanse_var_2)|, 25],
},
]

View File

@@ -1,5 +1,5 @@
# All sub directory in items are evaluated as a list
items: @| [os.path.basename(f.path) for f in os.scandir(os.path.join(r"$(test_directory)", "items")) if f.is_dir()] |
items: $| [os.path.basename(f.path) for f in os.scandir(os.path.join(r"$(test_directory)", "items")) if f.is_dir()] |
# - common
# - check
# - console