diff --git a/python/res/fm/templating/template_render.py b/python/res/fm/templating/template_render.py index a8f9e8e7d4..6e52ddb227 100644 --- a/python/res/fm/templating/template_render.py +++ b/python/res/fm/templating/template_render.py @@ -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) diff --git a/tests/res/fm/test_templating.py b/tests/res/fm/test_templating.py index 06cb58f2ef..94fd3caafc 100644 --- a/tests/res/fm/test_templating.py +++ b/tests/res/fm/test_templating.py @@ -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}, @@ -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: