From ba79d227dd2a85f123accb846d8b132a4f739212 Mon Sep 17 00:00:00 2001 From: geographika Date: Tue, 24 Jul 2018 23:21:47 +0200 Subject: [PATCH] Allow single string projections, see #63 --- mappyfile.pyproj | 2 +- mappyfile/pprint.py | 6 +++++- tests/test_pprint.py | 17 +++++++++++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/mappyfile.pyproj b/mappyfile.pyproj index 9b99840..fe59261 100644 --- a/mappyfile.pyproj +++ b/mappyfile.pyproj @@ -11,7 +11,7 @@ mappyfile mappyfile MSBuild|mappyfile3|$(MSBuildProjectFullPath) - tests\mapfiles\profiler.py + tests\test_pprint.py true diff --git a/mappyfile/pprint.py b/mappyfile/pprint.py index e76998f..e675bc0 100644 --- a/mappyfile/pprint.py +++ b/mappyfile/pprint.py @@ -211,7 +211,11 @@ def process_projection(self, key, lst, level): lines = [self.add_start_line(key, level)] - if len(lst) == 1 and lst[0].upper() == "AUTO": + if self.quoter.is_string(lst): + val = self.quoter.add_quotes(lst) + # the value has been manually set to a single string projection + lines.append(u"{}{}".format(self.whitespace(level, 2), val)) + elif len(lst) == 1 and lst[0].upper() == "AUTO": lines.append(u"{}{}".format(self.whitespace(level, 2), "AUTO")) else: for v in lst: diff --git a/tests/test_pprint.py b/tests/test_pprint.py index 497fde8..57a4509 100644 --- a/tests/test_pprint.py +++ b/tests/test_pprint.py @@ -296,6 +296,19 @@ def test_auto_projection(): assert(s == "MAP PROJECTION AUTO END END") + +def test_single_string_projection(): + d = { + "projection": "init=epsg:4326", + "__type__": "map" + } + + pp = PrettyPrinter(indent=0, quote="'", newlinechar=" ") + s = pp.pprint(d) + print(s) + assert(s == "MAP PROJECTION 'init=epsg:4326' END END") + + def test_print_boolean(): d = { "transform": True, @@ -375,6 +388,6 @@ def run_tests(): if __name__ == "__main__": logging.basicConfig(level=logging.INFO) - # test_get_ref_attribute_properties() - run_tests() + test_single_string_projection() + # run_tests() print("Done!")