Skip to content
Snippets Groups Projects
Commit 3ceac0b5 authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

TST(transformers): unit test for transformer to check if variable replacement in parameters works

parent d637644c
No related branches found
No related tags found
2 merge requests!217TST: Make NamedTemporaryFiles Windows-compatible,!204Allow variable replacement in parameters of transformer functions
Pipeline #58360 passed
......@@ -30,17 +30,14 @@ See: https://gitlab.indiscale.com/caosdb/src/caosdb-crawler/-/issues/107
import importlib
from pathlib import Path
from unittest.mock import MagicMock, Mock, patch
from unittest.mock import Mock
import linkahead as db
import pytest
import yaml
from pytest import raises
from caoscrawler.converters import Converter, ListElementConverter
from caoscrawler.scanner import create_transformer_registry, scan_directory
from caoscrawler.stores import GeneralStore
from caoscrawler.transformer_functions import replace, split
from caoscrawler.transformer_functions import replace
from pytest import raises
UNITTESTDIR = Path(__file__).parent
......@@ -163,3 +160,23 @@ def test_empty_functions_list(converter_registry):
conv.apply_transformers(values, transformer_functions)
assert values['b'] == "16_45"
def test_replace_variables():
vals = GeneralStore()
vals["test"] = "with"
vals["a"] = "str_without_replacement"
conv = Mock()
conv.definition = {}
conv.definition["transform"] = {
"test": {
"in": "$a",
"out": "$a",
"functions": [
{"replace": {
"remove": "without",
"insert": "$test"
}}
]}}
Converter.apply_transformers(conv, vals, {"replace": replace})
assert vals["a"] == "str_with_replacement"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment