From f0cdbb22e726bf1b506710ac3db005b3e8187073 Mon Sep 17 00:00:00 2001 From: Jo Basevi Date: Wed, 8 Nov 2023 14:53:57 +1100 Subject: [PATCH] Fix bug in mom6 driver introduced in #373 and added another test for mom6 setup --- payu/models/mom6.py | 9 ++++--- test/models/test_mom6.py | 58 +++++++++++++++++++++++++++++++++++----- 2 files changed, 57 insertions(+), 10 deletions(-) diff --git a/payu/models/mom6.py b/payu/models/mom6.py index 188153e8..6479ef34 100644 --- a/payu/models/mom6.py +++ b/payu/models/mom6.py @@ -10,7 +10,6 @@ # Standard library import os -import shutil # Extensions import f90nml @@ -67,12 +66,14 @@ def setup(self): # FMS initialisation super(Mom6, self).setup() - self.init_config() - - # Add parameter files to config files and copy files over to work path + # Add parameter files to config files mom6_add_parameter_files(self) + + # Copy configuration files over to work path self.setup_configuration_files() + self.init_config() + def init_config(self): """Patch input.nml as a new or restart run.""" diff --git a/test/models/test_mom6.py b/test/models/test_mom6.py index ebf5afcb..6e18b380 100644 --- a/test/models/test_mom6.py +++ b/test/models/test_mom6.py @@ -9,16 +9,11 @@ from test.common import cd from test.common import tmpdir, ctrldir, labdir, expt_workdir -from test.common import config as config_orig from test.common import write_config -from test.common import make_random_file, make_inputs +from test.common import make_random_file, make_inputs, make_exe verbose = True -# Global config -config = copy.deepcopy(config_orig) -config["model"] = "mom6" - def setup_module(module): """ @@ -42,7 +37,14 @@ def setup_module(module): except Exception as e: print(e) + config = { + 'laboratory': 'lab', + 'jobname': 'testrun', + 'model': 'mom6', + 'exe': 'test.exe' + } write_config(config) + make_exe() def teardown_module(module): @@ -118,3 +120,47 @@ def test_mom6_add_parameter_files(input_nml, # Tidy up input.nml os.remove(input_nml_fp) + + +def test_setup(): + input_nml = { + "MOM_input_nml": { + "input_filename": 'F', + "parameter_filename": ["MOM_input", "MOM_override"] + }, + "SIS_input_nml": { + "parameter_filename": "SIS_input" + } + } + + expected_files_added = {'input.nml', 'diag_table', + 'MOM_input', 'MOM_override', 'SIS_input'} + + # Create config files in control directory + for file in expected_files_added: + if file != 'input.nml': + filename = os.path.join(ctrldir, file) + make_random_file(filename, 8) + + # Create config.nml + input_nml_fp = os.path.join(ctrldir, 'input.nml') + f90nml.write(input_nml, input_nml_fp) + + with cd(ctrldir): + lab = payu.laboratory.Laboratory(lab_path=str(labdir)) + expt = payu.experiment.Experiment(lab, reproduce=False) + model = expt.models[0] + + # Function to test + model.setup() + + # Check config files are moved to model's work path + work_path_files = os.listdir(model.work_path) + for file in expected_files_added: + assert file in work_path_files + + # Check input.nml was patched as new run + work_input_fpath = os.path.join(model.work_path, 'input.nml') + input_nml = f90nml.read(work_input_fpath) + assert input_nml['MOM_input_nml']['input_filename'] == 'n' + assert input_nml['SIS_input_nml']['input_filename'] == 'n'