Skip to content

Commit

Permalink
docstrings #166
Browse files Browse the repository at this point in the history
  • Loading branch information
JavierCladellas committed Dec 13, 2024
1 parent c74dc05 commit b886aba
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/configtest/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class SampleModel(BaseModel):
nested: dict

class TestTemplateProcessor:
"""Tests for the TemplateProcessor class"""

@pytest.mark.parametrize( "nested_json, parent_key, separator, expected",[
# Case 1: Simple flat dictionary with default separator ('.')
({"key1": "value1", "key2": "value2"}, "", ".", {"key1": "value1", "key2": "value2"}),
Expand Down Expand Up @@ -58,6 +60,8 @@ class TestTemplateProcessor:
({"level1": {"level2": {"level3": "value"}}}, "", "|", {"level1|level2|level3": "value"})
])
def test_flattenDict(self, nested_json, expected,separator,parent_key):
"""Tests for the flattenDict method of the TemplateProcessor class.
It compares a the result of the function for a given nested_json to the corresponding expected result, for a variaty of separators and parent keys """
result = TemplateProcessor.flattenDict(nested_json,parent_key=parent_key,separator=separator)
assert result == expected

Expand Down Expand Up @@ -119,6 +123,10 @@ def test_flattenDict(self, nested_json, expected,separator,parent_key):
("This is a circular placeholder: {{a.{{a}}}}",{"a": "{{a}}"},"This is a circular placeholder: {{a.{{a}}}}")
])
def test_replacePlaceholders(self, target, flattened_source, expected, monkeypatch):
"""Tests for the replacePlaceholders method of the TemplateProcessor class.
It compares a the result of the function for a given target and flattened source to see if placeholders where correctly replaced.
"""

processor = TemplateProcessor()
if "$HOME" in expected:
monkeypatch.setenv("HOME", "/home/user")
Expand Down Expand Up @@ -149,6 +157,9 @@ def test_replacePlaceholders(self, target, flattened_source, expected, monkeypat
]
)
def test_recursiveReplace(self,input_data, flattened_source, expected_output):
"""Tests for the recursiveReplace method of the TemplateProcessor class.
It compares a the result of the function for a given target and flattened source to see if placeholders where correctly replaced for dictionaries
"""
processor = TemplateProcessor()
result = processor.recursiveReplace(input_data, flattened_source)
assert result == expected_output
Expand Down

0 comments on commit b886aba

Please sign in to comment.