Commit b3a5d90e authored by Martin Claus's avatar Martin Claus

Added test for stringification

parent 44901c89
Pipeline #1897 failed with stage
in 46 seconds
......@@ -242,6 +242,33 @@ def test_index_assignment(string, val1, d):
print (repr(nml), d)
assert nml["val"] == d
@pytest.mark.parametrize("string", ["&nml {} /", "&nml {} val2=34 /"])
@pytest.mark.parametrize("val1", ["lala", "((1 + 2) + 3)", 3, 3.0, 3e6, ".T."])
@pytest.mark.parametrize("d", [{1: None, 2: 35},{1: None}])
def test_index_assignment_to_str(string, d, val1):
val_str = ""
try:
int(eval(val1))
is_expression = True
except:
is_expression = False
is_bool = (val1 == ".T.")
d[1] = val1
for k, v in d.items():
if is_expression | is_bool:
val_str += "val({}) = {} ".format(k, v)
else:
val_str += "val({}) = {} ".format(k, repr(v))
if is_expression:
d[1] = eval(d[1])
if is_bool:
d[1] = (val1 == ".T.")
nml_string = string.format(val_str)
nml = namelist.parse_namelist_string(nml_string)["nml"]
assert nml_string == str(nml)
@pytest.mark.parametrize("string", ["&nml val= {}, val2='lsl'/"])
@pytest.mark.parametrize("op", ["+", "-", "/", "*", "**"])
@pytest.mark.parametrize(
......
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