Commit 4b65beaf authored by Martin Claus's avatar Martin Claus

Changed container to `OrderedDict`

parent 1ed4f0a9
Pipeline #1889 passed with stage
in 43 seconds
......@@ -146,7 +146,7 @@ def parse_namelist_string(in_string):
Returns
-------
:obj:`List` of :obj:`Namelist`
:obj:`dict` of :obj:`Namelist`
"""
retlist = []
......@@ -194,7 +194,8 @@ def parse_namelist_string(in_string):
for k, v in nml.items():
if len(v) == 1:
nml[k] = v[0]
return retlist
ret_dict = DictClass(zip([nml.name for nml in retlist], retlist))
return ret_dict
def _tokenize(text):
......
......@@ -31,7 +31,7 @@ def test_tokenize(string, res):
]
)
def test_parse_string(string):
nml = namelist.parse_namelist_string(string)[0]
nml = namelist.parse_namelist_string(string)["nml"]
assert nml.name == "nml"
......@@ -46,7 +46,7 @@ def test_parse_string(string):
)
def test_parse_file(string):
f = io.StringIO(string)
nml = namelist.parse_namelist_file(f)[0]
nml = namelist.parse_namelist_file(f)["nml"]
assert nml.name == "nml"
......@@ -61,7 +61,7 @@ def test_parse_file(string):
]
)
def test_string_out(string):
nml = namelist.parse_namelist_string(string)[0]
nml = namelist.parse_namelist_string(string)["nml"]
assert str(nml) == string
......@@ -86,7 +86,7 @@ def test_string_out_linebreak(string, arr):
arr_string = arr_string[lnbrk:]
assert_string = string.format(assert_arr_string)
nml = namelist.parse_namelist_string(nml_string)[0]
nml = namelist.parse_namelist_string(nml_string)["nml"]
print(str(nml), assert_string)
assert str(nml) == assert_string
......@@ -103,7 +103,7 @@ def test_string_out_linebreak(string, arr):
]
)
def test_repr(string):
nml = namelist.parse_namelist_string(string)[0]
nml = namelist.parse_namelist_string(string)["nml"]
nml_copy = eval(repr(nml))
assert nml == nml_copy
assert nml.name == nml_copy.name
......@@ -118,7 +118,7 @@ def test_repr(string):
)
def test_has_name(name):
nml_string = "&{} /".format(name)
nml = namelist.parse_namelist_string(nml_string)[0]
nml = namelist.parse_namelist_string(nml_string)[name]
assert nml.has_name(name)
......@@ -129,7 +129,7 @@ def test_has_name(name):
]
)
def test_match_name_val(string):
nml = namelist.parse_namelist_string(string)[0]
nml = namelist.parse_namelist_string(string)["nml2"]
assert nml.name == "nml2"
assert nml["val"] == 34
......@@ -141,7 +141,7 @@ def test_match_name_val(string):
]
)
def test_val_conversion(string, val):
nml = namelist.parse_namelist_string(string)[0]
nml = namelist.parse_namelist_string(string)["nml2"]
assert nml.name == "nml2"
assert nml["val"] == val
assert type(nml["val"]) == type(val)
......@@ -155,7 +155,7 @@ def test_val_conversion(string, val):
]
)
def test_match_multiple_name_val(string):
nml = namelist.parse_namelist_string(string)[0]
nml = namelist.parse_namelist_string(string)["nml3"]
assert nml.name == "nml3"
assert nml["val1"] == 34
assert nml["val2"] == 35
......@@ -174,7 +174,7 @@ def test_match_multiple_name_val(string):
]
)
def test_var_bool(string, val):
nml = namelist.parse_namelist_string(string)[0]
nml = namelist.parse_namelist_string(string)["nml"]
assert nml["val"] is val
......@@ -188,7 +188,7 @@ def test_var_bool(string, val):
]
)
def test_var_string(string, val):
nml = namelist.parse_namelist_string(string)[0]
nml = namelist.parse_namelist_string(string)["nml"]
assert nml["val"] == val
......@@ -201,7 +201,7 @@ def test_var_string(string, val):
)
def test_var_array(string, arr):
nml_string = string.format(",".join([str(a) for a in arr]))
nml = namelist.parse_namelist_string(nml_string)[0]
nml = namelist.parse_namelist_string(nml_string)["nml"]
# do elementwise identity check to also check types
for a, b in zip(nml["val"], arr):
......@@ -209,7 +209,7 @@ def test_var_array(string, arr):
assert type(a) == type(b)
nml_string = string.format(" , ".join([str(a) for a in arr]))
nml = namelist.parse_namelist_string(nml_string)[0]
nml = namelist.parse_namelist_string(nml_string)["nml"]
for a, b in zip(nml["val"], arr):
assert a == b
assert type(a) == type(b)
......@@ -229,5 +229,5 @@ def test_var_array(string, arr):
)
def test_var_expression(string, op, expression):
nml_string = string.format(expression.format(op))
nml = namelist.parse_namelist_string(nml_string)[0]
nml = namelist.parse_namelist_string(nml_string)["nml"]
assert nml["val"] == eval(expression.format(op))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment