Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_comment_alt(self):
parser = f90nml.Parser()
parser.comment_tokens = '#'
test_nml = parser.read('comment_alt.nml')
self.assertEqual(self.comment_alt_nml, test_nml)
def test_global_index(self):
parser = f90nml.Parser()
parser.global_start_index = 1
test_nml = parser.read('global_index.nml')
self.assertEqual(self.global_index_nml, test_nml)
def test_parser_property_invalid(self):
parser = f90nml.Parser()
self.assertRaises(TypeError, setattr, parser, 'comment_tokens', 123)
self.assertRaises(TypeError, setattr, parser,
'default_start_index', 'abc')
self.assertRaises(TypeError, setattr, parser, 'sparse_arrays', 'abc')
self.assertRaises(TypeError, setattr, parser,
'global_start_index', 'abc')
self.assertRaises(TypeError, setattr, parser, 'row_major', 'abc')
self.assertRaises(TypeError, setattr, parser, 'strict_logical', 'abc')
def test_rowmaj_multidim(self):
parser = f90nml.Parser()
parser.row_major = True
test_nml = parser.read('multidim.nml')
self.assertEqual(self.md_rowmaj_nml, test_nml)
def test_parser_default_index(self):
parser = f90nml.Parser()
parser.default_start_index = 1
test_nml = parser.read('default_index.nml')
self.assertEqual(self.default_one_index_nml, test_nml)
parser.default_start_index = 0
test_nml = parser.read('default_index.nml')
self.assertEqual(self.default_zero_index_nml, test_nml)
def test_logical_repr(self):
parser = f90nml.Parser()
parser.strict_logical = False
test_nml = parser.read('logical.nml')
test_nml.true_repr = 'T'
test_nml.false_repr = 'F'
self.assertEqual(test_nml.false_repr, test_nml.logical_repr[0])
self.assertEqual(test_nml.true_repr, test_nml.logical_repr[1])
self.assert_write(test_nml, 'logical_repr.nml')
test_nml.logical_repr = 'F', 'T'
self.assert_write(test_nml, 'logical_repr.nml')
self.assertRaises(TypeError, setattr, test_nml, 'true_repr', 123)
self.assertRaises(TypeError, setattr, test_nml, 'false_repr', 123)
self.assertRaises(ValueError, setattr, test_nml, 'true_repr', 'xyz')
self.assertRaises(ValueError, setattr, test_nml, 'false_repr', 'xyz')
def test_dense_arrays(self):
parser = f90nml.Parser()
test_nml = parser.read('sparse_array.nml')
self.assertEqual(self.dense_array_nml, test_nml)
def test_sparse_arrays(self):
parser = f90nml.Parser()
parser.sparse_arrays = True
test_nml = parser.read('sparse_array.nml')
self.assertEqual(self.sparse_array_nml, test_nml)
def read_namelist(fname):
"""
MITgcm has some additional requirements when reading namelists, so
isolate the logic to this routine
"""
# MITgcm strips shell-style (#) comments from its namelists
nml_parser = f90nml.Parser()
nml_parser.comment_tokens += '#'
return nml_parser.read(fname)