Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug copying mom6 config files introduced in #373 #381

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions payu/models/mom6.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

# Standard library
import os
import shutil

# Extensions
import f90nml
Expand Down Expand Up @@ -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."""

Expand Down
58 changes: 52 additions & 6 deletions test/models/test_mom6.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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):
Expand Down Expand Up @@ -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'
Loading