diff --git a/CHANGES.txt b/CHANGES.txt index 178510ce023c6b12b1a22e26d68948fb3780981a..03f59c974fbb3cea169bd3c76ba9be691bc8962a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -14,6 +14,14 @@ Global * TODO: Porting to python3 +Version 1.1.1rc2 +================ + +Configuration +------------- + +* Fixed job config corruption while formatting native variables in another job + Version 1.1.1rc1 ================ diff --git a/mkexp b/mkexp index 9b4d0a1402181a1baa205560a5311227700330ac..09f8082400ccb1b7ce1302ad73dee9801b1a2eee 100755 --- a/mkexp +++ b/mkexp @@ -534,8 +534,8 @@ for subjob, subconfig in jobs_config.iteritems(): # Prepare namelists for inclusion in scripts var_format = job_config['JOB'].get('.var_format', '${%s}') var_list = set() - del job_config['jobs'] - job_config['jobs'] = jobs_config + job_config['jobs'] = {} + job_config['jobs'].merge(jobs_config.dict()) job_config.walk(format_vars, log=var_list, fmt=var_format) job_config['VARIABLES_'] = var_list for namelist, groups in job_config['namelists'].iteritems(): diff --git a/test.py b/test.py index 4203e4e088404929364114a0aa5c83f2469d952e..58de4f19a3b6e18d3ba7a7e08a8a0af7a5f72dfd 100644 --- a/test.py +++ b/test.py @@ -210,44 +210,6 @@ class ContentTestCase(MkexpSimpleTestCase): self.assertIn("key1 = local", result) self.assertIn("key2 = global", result) - def test_var_statement(self): - exp_id = "test_var_statement" - job_id = "job" - writeconfig(exp_id, """ - EXP_TYPE = - GLOBAL1 = 123$${VAR1}456 - GLOBAL2 = $${VAR2}$${VAR3} - GLOBAL3 = 1, $${VAR2}, 3 - GLOBAL${FOUR} = 4 - [namelists] - [[namelist]] - [[[group]]] - key = abc$${var}def - [jobs] - [["""+job_id+"""]] - .var_format = <<<%s>>> - """) - writetemplate(exp_id, job_id, """ - GLOBAL1=%{GLOBAL1} - GLOBAL2=%{GLOBAL2} - GLOBAL3='%{GLOBAL3|join(" ")}' - GLOBAL4=%{context("GLOBAL<<<FOUR>>>")} - %{NAMELIST} - """) - expected = align(""" - GLOBAL1=123<<<VAR1>>>456 - GLOBAL2=<<<VAR2>>><<<VAR3>>> - GLOBAL3='1 <<<VAR2>>> 3' - GLOBAL4=4 - &group - key = 'abc<<<var>>>def' - / - """) - ignore = output(script("mkexp "+exp_id+".config")) - result = readfile(join("test", "experiments", exp_id, exp_id+"."+job_id)) - result = align(result) - self.assertMultiLineEqual(expected, result) - def test_var_list_in_context(self): exp_id = "test_var_list_in_context" job_id = "job" @@ -1201,6 +1163,75 @@ class JobSiblingsTestCase(MkexpSimpleTestCase): result = align(result) self.assertMultiLineEqual(expected, result) +class NativeVariableTestCase(MkexpSimpleTestCase): + + def test_var_statement(self): + exp_id = "test_var_statement" + job_id = "job" + writeconfig(exp_id, """ + EXP_TYPE = + GLOBAL1 = 123$${VAR1}456 + GLOBAL2 = $${VAR2}$${VAR3} + GLOBAL3 = 1, $${VAR2}, 3 + GLOBAL${FOUR} = 4 + [namelists] + [[namelist]] + [[[group]]] + key = abc$${var}def + [jobs] + [["""+job_id+"""]] + .var_format = <<<%s>>> + """) + writetemplate(exp_id, job_id, """ + GLOBAL1=%{GLOBAL1} + GLOBAL2=%{GLOBAL2} + GLOBAL3='%{GLOBAL3|join(" ")}' + GLOBAL4=%{context("GLOBAL<<<FOUR>>>")} + %{NAMELIST} + """) + expected = align(""" + GLOBAL1=123<<<VAR1>>>456 + GLOBAL2=<<<VAR2>>><<<VAR3>>> + GLOBAL3='1 <<<VAR2>>> 3' + GLOBAL4=4 + &group + key = 'abc<<<var>>>def' + / + """) + ignore = output(script("mkexp "+exp_id+".config")) + result = readfile(join("test", "experiments", exp_id, exp_id+"."+job_id)) + result = align(result) + self.assertMultiLineEqual(expected, result) + + def test_var_separation(self): + exp_id = "test_var_separation" + writeconfig(exp_id, """ + EXP_TYPE = + [jobs] + use_native_var = $${native_var} + [[job1]] + .var_format = <<<%s>>> + [[job2]] + """) + writetemplate(exp_id, "job1", """ + %{JOB.use_native_var} + """) + writetemplate(exp_id, "job2", """ + %{JOB.use_native_var} + """) + expected1 = align(""" + <<<native_var>>> + """) + expected2 = align(""" + ${native_var} + """) + ignore = output(script("mkexp "+exp_id+".config")) + result1 = readfile(join("test", "experiments", exp_id, exp_id+".job1")) + result2 = readfile(join("test", "experiments", exp_id, exp_id+".job2")) + result1 = align(result1) + result2 = align(result2) + self.assertMultiLineEqual(expected1, result1) + self.assertMultiLineEqual(expected2, result2) if __name__ == '__main__': unittest.main()