From b124edc67777bbf56506c17b6406ec30fb9aa8cd Mon Sep 17 00:00:00 2001 From: Stephen Jacob Date: Thu, 10 Oct 2024 10:34:16 -0700 Subject: [PATCH] fix: trailing_commas: fix tests & only when indent set Make the `trailing_commas` flag do what it says: Only apply when pretty printing (`indent is not None`). Fix all remaining `test_simpleion.py` failures. --- amazon/ion/writer_text.py | 2 +- tests/test_simpleion.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/amazon/ion/writer_text.py b/amazon/ion/writer_text.py index 2027db85..4d19856a 100644 --- a/amazon/ion/writer_text.py +++ b/amazon/ion/writer_text.py @@ -369,7 +369,7 @@ def _raw_writer_coroutine(depth=0, container_event=None, whence=None, indent=Non ion_event, self = (yield transition) delegate = self - if has_written_values and (trailing_commas or not ion_event.event_type.ends_container): + if has_written_values and ((indent and trailing_commas) or not ion_event.event_type.ends_container): # TODO This will always emit a delimiter for containers--should make it not do that. # Write the delimiter for the next value. if depth == 0: diff --git a/tests/test_simpleion.py b/tests/test_simpleion.py index 55bf16f2..972c3c8c 100644 --- a/tests/test_simpleion.py +++ b/tests/test_simpleion.py @@ -675,13 +675,13 @@ class PrettyPrintParams(NamedTuple): indent=None, trailing_commas=True, # not pretty print exact_text="$ion_1_0 [a,b,chair::2008-08-08T]"), PrettyPrintParams(ion_text='[apple, {roof: false}]', indent='\t', trailing_commas=True, - exact_text="$ion_1_0\n[\n\tapple,\n\t{\n\t\troof: false,\n\t}\n]"), + exact_text="$ion_1_0\n[\n\tapple,\n\t{\n\t\troof: false,\n\t},\n]"), PrettyPrintParams(ion_text='[apple, "banana", {roof: false}]', indent='\t', trailing_commas=True, - exact_text="$ion_1_0\n[\n\tapple,\n\t\"banana\",\n\t{\n\t\troof: false,\n\t}\n]"), + exact_text="$ion_1_0\n[\n\tapple,\n\t\"banana\",\n\t{\n\t\troof: false,\n\t},\n]"), PrettyPrintParams(ion_text='[apple, {roof: false, walls:4, door: wood::large::true}]', indent='\t', trailing_commas=True, regexes=["\\A\\$ion_1_0\n\\[\n\tapple,\n\t\\{", "\n\t\tdoor: wood::large::true,\n", - "\n\t\troof: false,\n", "\n\t\twalls: 4,\n", "\n\t\\}\n\\]\\Z"]) + "\n\t\troof: false,\n", "\n\t\twalls: 4,\n", "\n\t\\},\n\\]\\Z"]) ) def test_pretty_print(p): if c_ext: