audeering / audobject

Generic Python interface for serializing objects to YAML
https://audeering.github.io/audobject/
Other
1 stars 0 forks source link

Do not encode value with resolver if it is None #62

Closed frankenjoe closed 1 year ago

frankenjoe commented 1 year ago

Fixes #61 and adds a test for it.

codecov[bot] commented 1 year ago

Codecov Report

Merging #62 (71500bc) into master (e95d5c7) will not change coverage. The diff coverage is 100.0%.

Impacted Files Coverage Δ
audobject/core/object.py 100.0% <100.0%> (ø)
hagenw commented 1 year ago

I wasn't sure what to expect for the other resolvers and added the following test cases.

For FilePath:

    yaml_path = os.path.join(root, 'yaml', 'none.yaml')
    o = ObjectWithFile(None)
    o.to_yaml(yaml_path, include_version=False)
    o2 = audobject.from_yaml(yaml_path)
    assert o == o2

and for Function:

    o_none = ObjectWithFunction(None)

    path = os.path.join(tmpdir, 'none.yaml')
    o_none.to_yaml(path, include_version=False)
    o_none_2 = audobject.from_yaml(path)

    assert o_none == o_none_2
    assert o_none.to_yaml_s(include_version=False) == \
           o_none_2.to_yaml_s(include_version=False)

Both tests passed. Is it obvious that they should pass or would it make sense to include them as well?

frankenjoe commented 1 year ago

Is it obvious that they should pass or would it make sense to include them as well?

Now we only call a resolver if the value that needs to be encoded is not None. So I would say it's obvious.