From 535136757017b604df783430f96305ba79387179 Mon Sep 17 00:00:00 2001 From: sethg Date: Tue, 14 Jul 2020 09:21:39 +0200 Subject: [PATCH] Quote connectionoptions values --- mappyfile/pprint.py | 4 ++-- tests/test_pprint.py | 21 ++++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/mappyfile/pprint.py b/mappyfile/pprint.py index bd9f619..d8d6b06 100644 --- a/mappyfile/pprint.py +++ b/mappyfile/pprint.py @@ -320,7 +320,7 @@ def pprint(self, composites): for composite in composites: type_ = composite["__type__"] - if type_ in ("metadata", "validation"): + if type_ in ("metadata", "validation", "connectionoptions"): # types are being parsed directly, and not as an attr of a parent lines += self.process_key_dict(type_, composite, level=0) else: @@ -504,7 +504,7 @@ def _format(self, composite, level=0): lines += self._format(v, level + 1) elif attr == "pattern": lines += self.format_pair_list(attr, value, level) - elif attr in ("metadata", "validation", "values"): + elif attr in ("metadata", "validation", "values", "connectionoptions"): # metadata and values are also composites # but will be processed here lines += self.process_key_dict(attr, value, level) diff --git a/tests/test_pprint.py b/tests/test_pprint.py index a00f46a..315a9c4 100644 --- a/tests/test_pprint.py +++ b/tests/test_pprint.py @@ -208,6 +208,25 @@ def test_metadata(): assert(s == "MAP METADATA 'MS_ENABLE_MODES' '!*' 'WMS_ENABLE_REQUEST' '*' END END") +def test_connectionoptions(): + + values = { + "FLATTEN_NESTED_ATTRIBUTES": "YES" + } + + d = { + "connectionoptions": values, + "__type__": "layer" + } + + d = collections.OrderedDict(sorted(d.items())) + + pp = PrettyPrinter(indent=0, quote="'", newlinechar=" ") + s = pp.pprint(d) + print(s) + assert(s == "LAYER CONNECTIONOPTIONS 'FLATTEN_NESTED_ATTRIBUTES' 'YES' END END") + + def test_config(): cd = { @@ -418,6 +437,6 @@ def run_tests(): if __name__ == "__main__": logging.basicConfig(level=logging.INFO) - test_join() + test_connectionoptions() # run_tests() print("Done!")