From 3ceac0b55fae0138bc87abfaec3d8c823ad23b64 Mon Sep 17 00:00:00 2001
From: Alexander Schlemmer <a.schlemmer@indiscale.com>
Date: Fri, 29 Nov 2024 11:11:09 +0100
Subject: [PATCH] TST(transformers): unit test for transformer to check if
 variable replacement in parameters works

---
 unittests/test_transformers.py | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/unittests/test_transformers.py b/unittests/test_transformers.py
index 0571dbd3..301aab50 100644
--- a/unittests/test_transformers.py
+++ b/unittests/test_transformers.py
@@ -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"
-- 
GitLab