Skip to content

Commit

Permalink
fix rendering of values after multiline keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Ken Kundert authored and Ken Kundert committed Apr 27, 2024
1 parent 32c63bc commit 8698be4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
6 changes: 4 additions & 2 deletions nestedtext/nestedtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -1534,12 +1534,14 @@ def render_dict_item(self, key, value, keys, values):
)
if multiline_key_required:
key = "\n".join(": "+l if l else ":" for l in key.split("\n"))
if self.is_a_dict(value) or self.is_a_list(value):
return key + self.render_value(value, keys, values)
if is_str(value):
# force use of multiline value with multiline keys
value = convert_returns(value)
return key + "\n" + add_leader(value, self.indent*" " + "> ")
else:
return key + self.render_value(value, keys, values)
value = self.render_value(value, keys, values)
return key + "\n" + add_leader(value, self.indent*" " + "> ")
else:
return add_prefix(key + ":", self.render_value(value, keys, values))

Expand Down
24 changes: 24 additions & 0 deletions tests/test_nestedtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from inform import Error, Info, render, indent, join, dedent
from quantiphy import Quantity
import subprocess
import json

test_api = Path(__file__).parent / 'official_tests' / 'api'
import sys; sys.path.append(str(test_api))
Expand Down Expand Up @@ -2057,4 +2058,27 @@ def test_file_descriptors(tmp_path):
assert results.stderr == b""
assert results.returncode == 0

# test_andyde {{{2
def test_andyde(tmp_path):
data_python = {
"http://www.kde.org/standards/kcfg/1.0}kcfgfile": None,
"http://www.kde.org/standards/kcfg/1.0}group": {
"http://www.kde.org/standards/kcfg/1.0}entry": [
{"{http://www.kde.org/standards/kcfg/1.0}default": 250},
{"{http://www.kde.org/standards/kcfg/1.0}default": "krunner,yakuake"}
]
}
}
data_after_round_trip = {
"http://www.kde.org/standards/kcfg/1.0}kcfgfile": "",
"http://www.kde.org/standards/kcfg/1.0}group": {
"http://www.kde.org/standards/kcfg/1.0}entry": [
{"{http://www.kde.org/standards/kcfg/1.0}default": "250"},
{"{http://www.kde.org/standards/kcfg/1.0}default": "krunner,yakuake"}
]
}
}
data_as_nt = nt.dumps(data_python)
assert nt.loads(data_as_nt) == data_after_round_trip

# vim: fdm=marker

0 comments on commit 8698be4

Please sign in to comment.