CZ-NIC/yangson

incorrect raw_value() for EmptyType

Closed this issue · 3 comments

Adding the following pytest to tests/test_model.py:

def test_empty_raw_value(data_model, instance):
    ir = data_model.parse_resource_id("/test:contA/listA=C0FFEE,true/contD/contE")
    expected = {'leafJ': [None], 'leafP': 10}
    rv = instance.goto(ir).raw_value()
    assert(rv == expected)

And running the following command:

pytest -sxvvk test_empty_raw_value

Produces the output:

>       assert(rv == expected)
E       AssertionError: assert {'leafJ': (None,), 'leafP': 10} == {'leafJ': [None], 'leafP': 10}
E         Common items:
E         {'leafP': 10}
E         Differing items:
E         {'leafJ': (None,)} != {'leafJ': [None]}
E         Full diff:
E         - {'leafJ': [None], 'leafP': 10}
E         ?           ^    -
E         + {'leafJ': (None,), 'leafP': 10}
E         ?           ^     ++

Actually, the cooked empty value is the tuple (None,), not list. See class EmptyType and also docstring for from_raw. Is it a problem?

Fixed and test added, thanks.