Commit 44901c89 authored by Martin Claus's avatar Martin Claus

Full code coverage

parent dc77c8b5
Pipeline #1896 passed with stage
in 47 seconds
......@@ -165,12 +165,13 @@ def parse_namelist_string(in_string):
if match:
pname = match.group(1)
index = match.group(3)
if index is not None: # index assignment
try: # index assignment
index = int(index)
if pname not in nml:
nml[pname] = DictClass()
else:
except TypeError: # index is None
nml[pname] = []
continue
continue # pragma no cover
if re.match(namlistend, item):
continue
......
......@@ -150,7 +150,7 @@ def test_val_conversion(string, val):
@pytest.mark.parametrize(
"string",
["&nml3 val1=34, val2=35 &end",
"&nml3 val1=34 val2=35 &end",
"&nml3 val1 = 34 val2 = 35 &end",
"&nml3\nval1=34\nval2=35\n&end",
]
)
......@@ -215,15 +215,31 @@ def test_var_array(string, arr):
assert type(a) == type(b)
@pytest.mark.parametrize("string", ["&nml {} /"])
@pytest.mark.parametrize("d", [{1: 'lalal', 2: 35},])
def test_index_assignment(string, 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(string, val1, d):
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():
val_str += "val({}) = {} ".format(k, v)
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"]
print(nml_string)
print (repr(nml), d)
assert nml["val"] == d
@pytest.mark.parametrize("string", ["&nml val= {}, val2='lsl'/"])
......
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