Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wxflow/yaml_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def vanilla_yaml(ctx):
"""
Transform an input object of complex type as a plain type
"""
if isinstance(ctx, AttrDict):
if isinstance(ctx, dict):
return {kk: vanilla_yaml(vv) for kk, vv in ctx.items()}
elif isinstance(ctx, list):
return [vanilla_yaml(vv) for vv in ctx]
Expand Down
32 changes: 32 additions & 0 deletions tests/test_yaml_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import pytest

from wxflow import YAMLFile, parse_j2yaml, save_as_yaml
from wxflow.yaml_file import vanilla_yaml
from wxflow.attrdict import AttrDict

host_yaml = """
host:
Expand Down Expand Up @@ -77,3 +79,33 @@ def test_yaml_file_with_j2templates(tmp_path, create_template):
yaml_in = YAMLFile(path=yaml_out)

assert yaml_in == conf


def test_vanilla_yaml_with_regular_dict():
"""Test that vanilla_yaml processes regular dictionaries, not just AttrDict"""
test_datetime = datetime(2024, 1, 1, 12, 0, 0)

# Test with regular dict containing datetime
dict_data = {'key': test_datetime}
result = vanilla_yaml(dict_data)
assert result == {'key': '2024-01-01T12:00:00Z'}

# Test with nested regular dict
nested_dict = {'outer': {'inner': test_datetime}}
result = vanilla_yaml(nested_dict)
assert result == {'outer': {'inner': '2024-01-01T12:00:00Z'}}

# Test with AttrDict still works
attrdict_data = AttrDict({'key': test_datetime})
result = vanilla_yaml(attrdict_data)
assert result == {'key': '2024-01-01T12:00:00Z'}

# Test with mixed AttrDict and regular dict
mixed = AttrDict({'attr': {'regular': test_datetime}})
result = vanilla_yaml(mixed)
assert result == {'attr': {'regular': '2024-01-01T12:00:00Z'}}

# Test with list containing dicts with datetime
list_data = [{'key': test_datetime}, {'another': test_datetime}]
result = vanilla_yaml(list_data)
assert result == [{'key': '2024-01-01T12:00:00Z'}, {'another': '2024-01-01T12:00:00Z'}]
Loading