Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/bdd_integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ See below their values, along with their associated replacement logic (click `he
* :code:`[REPLACE:xxxx::SUBSTRING_TO_BE_REPLACED::SUBSTRING_TO_USE_AS_REPLACEMENT]`: Replaces a substring with another in xxxx string
* :code:`[TITLE:xxxx]`: Applies python's string title() method to xxxx string
* :code:`[ROUND:xxxx::N]`: Rounds given number xxxx to N digits in its fractional part
* :code:`[SHARP]`: Generates a sharp string '#'


There are also some special tags that allow to use parameter values configured at different sources defined by the `map_param <https://toolium.readthedocs.io/en/latest/toolium.utils.html#toolium.utils.dataset.map_param>`_ method:
Expand All @@ -200,7 +201,7 @@ There are also some special tags that allow to use parameter values configured a
* :code:`[FILE:xxxx]`: String with the content of the file in the path xxxx
* :code:`[BASE64:xxxx]`: String with the base64 representation of the file content in the path xxxx

In order to apply the string replacements in your code, import and call the corresponding function. E.g.::
In order to apply the string replacements in your code, import and call the corresponding function. E.g.:

.. code:: console

Expand Down
7 changes: 7 additions & 0 deletions toolium/test/utils/test_dataset_replace_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,3 +507,10 @@ def test_replace_param_title():
assert param == "Holahola"
param = replace_param('[TITLE:hOlA]')
assert param == "HOlA"


def test_replace_param_sharp():
param = replace_param('[SHARP]')
assert param == '#'
param = replace_param('hello [SHARP] world')
assert param == 'hello # world'
5 changes: 3 additions & 2 deletions toolium/utils/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def _replace_param_replacement(param, language):
"""
Replace param with a new param value.
Available replacements: [EMPTY], [B], [UUID], [RANDOM], [RANDOM_PHONE_NUMBER],
[TIMESTAMP], [DATETIME], [NOW], [TODAY], [ROUND:xxxxx::d]
[TIMESTAMP], [DATETIME], [NOW], [TODAY], [ROUND:xxxxx::d], [SHARP]

:param param: parameter value
:param language: language to configure date format for NOW and TODAY
Expand All @@ -208,7 +208,8 @@ def _replace_param_replacement(param, language):
'[DATETIME]': str(datetime.datetime.now(datetime.timezone.utc).strftime(datetime_format)),
'[NOW]': str(datetime.datetime.now(datetime.timezone.utc).strftime(date_format)),
'[TODAY]': str(datetime.datetime.now(datetime.timezone.utc).strftime(date_day_format)),
r'\[ROUND:(.*?)::(\d*)\]': _get_rounded_float_number
r'\[ROUND:(.*?)::(\d*)\]': _get_rounded_float_number,
'[SHARP]': '#'
}

# append date expressions found in param to the replacement dict
Expand Down
Loading