Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changes
development (main)
------------------

-
- Fix dump functions failing to write nested `Configuration` instances in TOML format.

0.17.1 (2025-10-15)
-------------------
Expand Down
1 change: 1 addition & 0 deletions confidence/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def loads(self, string: str) -> typing.Any:
return tomlkit.value(string)

def dumps(self, value: typing.Any) -> str:
value = unwrap(value)
try:
# attempt to dump the value as TOML document
return tomlkit.dumps(value)
Expand Down
17 changes: 15 additions & 2 deletions tests/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest

from confidence import Configuration, unwrap
from confidence.formats import JSON, TOML, YAML


Expand All @@ -16,12 +17,24 @@ def test_singular_value_roundtrip(format, value):


@pytest.mark.parametrize('format', (JSON, TOML, YAML, YAML(suffix='.conf', encoding='utf-32')))
@pytest.mark.parametrize('value', ([], {}, [1, 2, 'a'], {'a': 1, 'b': 42.0, 'c': {'d': 'str'}, 'e': [{'g': True}]}))
@pytest.mark.parametrize(
'value',
(
[],
{},
[1, 2, 'a'],
{'a': 1, 'b': 42.0, 'c': {'d': 'str'}, 'e': [{'g': True}]},
# nested configuration object should get unwrapped before serialization
Configuration({'a.b.c': 42}),
# serialization should not be trying to resolve references, this one would cause a recursion error if it does
Configuration({'a.b': [1, 2, '${a}']}),
),
)
def test_multiple_values_roundtrip(format, value, tmp_path):
fname = tmp_path / f'config{format.suffix}'

format.dumpf(value, fname)
assert format.loadf(fname) == value
assert format.loadf(fname) == unwrap(value)


def test_edit_format():
Expand Down