Skip to content

Commit

Permalink
make dictionarykeyread read as string by default
Browse files Browse the repository at this point in the history
  • Loading branch information
jgstew committed Sep 29, 2023
1 parent d6a8f77 commit 7d95b00
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
4 changes: 2 additions & 2 deletions SharedProcessors/AssertInputContainsString.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class AssertInputContainsString(Processor): # pylint: disable=invalid-name
def main(self):
"""Execution starts here"""

input_string = self.env.get("input_string")
assert_string = self.env.get("assert_string")
input_string = str(self.env.get("input_string"))
assert_string = str(self.env.get("assert_string"))
raise_error = bool(self.env.get("raise_error", True))

self.output(f"`{input_string}` must contain `{assert_string}`", 2)
Expand Down
9 changes: 9 additions & 0 deletions SharedProcessors/DictionaryKeyRead.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class DictionaryKeyRead(Processor):
"required": True,
"description": "Name of the output variable to store the value.",
},
"output_string": {
"required": False,
"default": True,
"description": "Make the value read a string.",
},
}
output_variables = {}
__doc__ = description
Expand All @@ -54,10 +59,14 @@ def main(self):
dictionary_key = self.env.get("dictionary_key", None)
# get name of variable to store output:
output_variable = self.env.get("output_variable", None)
# get if the output should be a string:
output_string = self.env.get("output_string", True)

value = self.read_dictionary_key(input_dictionary, dictionary_key)

if value is not None:
if output_string:
value = str(value)
self.output(
f"Read '{dictionary_key}' from dictionary '{input_dictionary_name}': {value}"
)
Expand Down
28 changes: 26 additions & 2 deletions Test-Recipes/DictionaryKeyRead.test.recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ Identifier: com.github.jgstew.test.DictionaryKeyRead
Input:
NAME: DictionaryKeyReadTest
DisplayName: DictionaryKeyRead
Template_version: "0.0.0"
Template_version: 1.2.3
Template_example: "example value"
Template_float: 1.2
Template_int: 1
MinimumVersion: "2.3"
Process:
- Processor: com.github.jgstew.SharedProcessors/TemplateDictionaryAppendInput
Expand All @@ -19,4 +21,26 @@ Process:
- Processor: com.github.jgstew.SharedProcessors/AssertInputContainsString
Arguments:
input_string: "%version%"
assert_string: "0.0.0"
assert_string: "1.2.3"

- Processor: com.github.jgstew.SharedProcessors/DictionaryKeyRead
Arguments:
input_dictionary: template_dictionary
dictionary_key: float
output_variable: float

- Processor: com.github.jgstew.SharedProcessors/AssertInputContainsString
Arguments:
input_string: "%float%"
assert_string: 1.2

- Processor: com.github.jgstew.SharedProcessors/DictionaryKeyRead
Arguments:
input_dictionary: template_dictionary
dictionary_key: int
output_variable: int

- Processor: com.github.jgstew.SharedProcessors/AssertInputContainsString
Arguments:
input_string: "%int%"
assert_string: 1

0 comments on commit 7d95b00

Please sign in to comment.