Skip to content

Commit cd399d5

Browse files
authored
Add sharp as parameter to be replaced (#442)
* Add sharp as parameter to be replaced * Actualizada la documentación en docs\bdd_integration.rst. Añadido test en toolium\test\utils\test_dataset_replace_param.py
1 parent d8b3244 commit cd399d5

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

docs/bdd_integration.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ See below their values, along with their associated replacement logic (click `he
186186
* :code:`[REPLACE:xxxx::SUBSTRING_TO_BE_REPLACED::SUBSTRING_TO_USE_AS_REPLACEMENT]`: Replaces a substring with another in xxxx string
187187
* :code:`[TITLE:xxxx]`: Applies python's string title() method to xxxx string
188188
* :code:`[ROUND:xxxx::N]`: Rounds given number xxxx to N digits in its fractional part
189+
* :code:`[SHARP]`: Generates a sharp string '#'
189190

190191

191192
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:
@@ -200,7 +201,7 @@ There are also some special tags that allow to use parameter values configured a
200201
* :code:`[FILE:xxxx]`: String with the content of the file in the path xxxx
201202
* :code:`[BASE64:xxxx]`: String with the base64 representation of the file content in the path xxxx
202203

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

205206
.. code:: console
206207

toolium/test/utils/test_dataset_replace_param.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,3 +507,10 @@ def test_replace_param_title():
507507
assert param == "Holahola"
508508
param = replace_param('[TITLE:hOlA]')
509509
assert param == "HOlA"
510+
511+
512+
def test_replace_param_sharp():
513+
param = replace_param('[SHARP]')
514+
assert param == '#'
515+
param = replace_param('hello [SHARP] world')
516+
assert param == 'hello # world'

toolium/utils/dataset.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def _replace_param_replacement(param, language):
187187
"""
188188
Replace param with a new param value.
189189
Available replacements: [EMPTY], [B], [UUID], [RANDOM], [RANDOM_PHONE_NUMBER],
190-
[TIMESTAMP], [DATETIME], [NOW], [TODAY], [ROUND:xxxxx::d]
190+
[TIMESTAMP], [DATETIME], [NOW], [TODAY], [ROUND:xxxxx::d], [SHARP]
191191
192192
:param param: parameter value
193193
:param language: language to configure date format for NOW and TODAY
@@ -208,7 +208,8 @@ def _replace_param_replacement(param, language):
208208
'[DATETIME]': str(datetime.datetime.now(datetime.timezone.utc).strftime(datetime_format)),
209209
'[NOW]': str(datetime.datetime.now(datetime.timezone.utc).strftime(date_format)),
210210
'[TODAY]': str(datetime.datetime.now(datetime.timezone.utc).strftime(date_day_format)),
211-
r'\[ROUND:(.*?)::(\d*)\]': _get_rounded_float_number
211+
r'\[ROUND:(.*?)::(\d*)\]': _get_rounded_float_number,
212+
'[SHARP]': '#'
212213
}
213214

214215
# append date expressions found in param to the replacement dict

0 commit comments

Comments
 (0)