Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

Commit

Permalink
Make template_render only load gen_kw export if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
markusdregi committed Mar 22, 2021
1 parent 551af6f commit 06365ba
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
6 changes: 5 additions & 1 deletion python/res/fm/templating/template_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ def render_template(input_files, template_file, output_file):
if isinstance(input_files, str) and input_files:
input_files = (input_files,)

all_input_files = (DEFAULT_GEN_KW_EXPORT_NAME + ".json",)
all_input_files = ()

gen_kw_export_path = DEFAULT_GEN_KW_EXPORT_NAME + ".json"
if os.path.isfile(gen_kw_export_path):
all_input_files += (gen_kw_export_path,)

if input_files:
all_input_files += tuple(input_files)
Expand Down
39 changes: 39 additions & 0 deletions tests/res/fm/test_templating.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ class TemplatingTest(ResTest):
+ "OTH_TEST {{third.key1.subkey1}}"
)

mulitple_input_template_no_param = (
"FILENAME\n"
+ "F1 {{not_the_standard_parameters.key1.subkey1}}\n"
+ "OTH {{second.key1.subkey2}}\n"
+ "OTH_TEST {{third.key1.subkey1}}"
)

default_parameters = {
"key1": {"subkey1": 1999.22, "subkey2": 200},
"key2": {"subkey1": 300},
Expand Down Expand Up @@ -139,6 +146,38 @@ def test_template_multiple_input(self):

self.assertEqual(parameter_file.read(), expected_output)

@tmpdir()
def test_no_parameters_json(self):
with open("template", "w") as template_file:
template_file.write(self.mulitple_input_template_no_param)

with open("not_the_standard_parameters.json", "w") as json_file:
json_file.write(json.dumps(self.default_parameters))

with open("second.json", "w") as json_file:
parameters = {"key1": {"subkey2": 1400}}
json.dump(parameters, json_file)
with open("third.json", "w") as json_file:
parameters = {
"key1": {
"subkey1": 3000.22,
}
}
json.dump(parameters, json_file)

render_template(
["second.json", "third.json", "not_the_standard_parameters.json"],
"template",
"out_file",
)

with open("out_file", "r") as parameter_file:
expected_output = (
"FILENAME\n" + "F1 1999.22\n" + "OTH 1400\n" + "OTH_TEST 3000.22"
)

self.assertEqual(parameter_file.read(), expected_output)

@tmpdir()
def test_template_executable(self):
with TestAreaContext("templating") as tac:
Expand Down

0 comments on commit 06365ba

Please sign in to comment.