Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exp_2x1day.build_and_run()
exp_2x1day.force_run()
# Now do a single 2 day run
exp_2day = setup_exp_from_base('1deg_jra55_iaf', '1deg_jra55_iaf_2day')
# Reconfigure
with open(exp_2day.accessom2_config) as f:
nml = f90nml.read(f)
nml['date_manager_nml']['restart_period'] = [0, 0, 172800]
nml.write(exp_2day.accessom2_config, force=True)
# Don't use Redsea fix - this breaks reproducibility
# https://github.com/COSIMA/access-om2/issues/124
with open(exp_2day.ocean_config) as f:
nml = f90nml.read(f)
nml['auscom_ice_nml']['redsea_gulfbay_sfix'] = False
nml.write(exp_2day.ocean_config, force=True)
# Run once.
exp_2day.build_and_run()
# Now compare the output between our two short and one long run.
two_shrt = self.checksums_to_list(exp_2x1day.accessom2_out_000)
two_shrt = two_shrt + self.checksums_to_list(exp_2x1day.accessom2_out_001)
one_long = self.checksums_to_list(exp_2day.accessom2_out_000)
assert len(one_long) > 0
for line in one_long:
if line not in two_shrt:
def test_uppercase(self):
test_nml = f90nml.read('types.nml')
test_nml.uppercase = True
self.assert_write(test_nml, 'types_uppercase.nml')
self.assertRaises(TypeError, setattr, test_nml, 'uppercase', 'xyz')
def test_extern_cmt(self):
test_nml = f90nml.read('extern_cmt.nml')
self.assertEqual(self.extern_cmt_nml, test_nml)
def test_index_syntax(self):
self.assertRaises(ValueError, f90nml.read, 'index_empty.nml')
self.assertRaises(ValueError, f90nml.read, 'index_bad.nml')
self.assertRaises(ValueError, f90nml.read, 'index_bad_start.nml')
self.assertRaises(ValueError, f90nml.read, 'index_empty_end.nml')
self.assertRaises(ValueError, f90nml.read, 'index_bad_end.nml')
self.assertRaises(ValueError, f90nml.read, 'index_empty_stride.nml')
self.assertRaises(ValueError, f90nml.read, 'index_bad_stride.nml')
self.assertRaises(ValueError, f90nml.read, 'index_zero_stride.nml')
def test_print_group(self):
nml = f90nml.read('types.nml')
stdout = StringIO()
print(nml['types_nml'], file=stdout)
stdout.seek(0)
source_str = stdout.read().rstrip('\n')
stdout.close()
target_str = repr(nml['types_nml'])
self.assertEqual(source_str, target_str)
def test_float_format(self):
test_nml = f90nml.read('float.nml')
test_nml.float_format = '.3f'
self.assert_write(test_nml, 'float_format.nml')
self.assertRaises(TypeError, setattr, test_nml, 'float_format', 123)
def test_vector_default_index(self):
test_nml = f90nml.read('vector.nml')
test_nml.default_start_index = 2
self.assertEqual(self.vector_nml, test_nml)
self.assert_write(test_nml, 'vector_default_idx.nml')
def make_config_files():
"""
Create files required for test model
"""
f90nml.namelist.Namelist(data).write(ctrldir/'data', force=True)
def test_groups(self):
d = {'a': {'b': 1.}}
nml = Namelist(d)
key, value = next(nml.groups())
self.assertEqual(key, ('a', 'b'))
self.assertEqual(value, 1.)
def test_f90repr(self):
nml = Namelist()
self.assertEqual(nml._f90repr(1), '1')
self.assertEqual(nml._f90repr(1.), '1.0')
self.assertEqual(nml._f90repr(1+2j), '(1.0, 2.0)')
self.assertEqual(nml._f90repr(True), '.true.')
self.assertEqual(nml._f90repr(False), '.false.')
self.assertEqual(nml._f90repr('abc'), "'abc'")
for ptype in ({}, [], set()):
self.assertRaises(ValueError, nml._f90repr, ptype)