Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_join():
d = {
"__type__": "layer",
"name": "Joined",
"joins": [{
"__type__": "join",
"name": "table_join"
}]
}
pp = PrettyPrinter(indent=0, quote="'", newlinechar=" ")
d = collections.OrderedDict(sorted(d.items()))
s = pp.pprint(d)
assert(s == "LAYER JOIN NAME 'table_join' END NAME 'Joined' END")
def test_multiple_layers():
d = {
"layers": [{
"name": "Layer1",
"__type__": "layer"
},
{
"name": "Layer2",
"__type__": "layer"
}],
"__type__": "map"
}
pp = PrettyPrinter(indent=0, quote="'", newlinechar=" ")
s = pp.pprint(d)
print(s)
assert(s == "MAP LAYER NAME 'Layer1' END LAYER NAME 'Layer2' END END")
md = {
"MS_ENABLE_MODES": "!*",
"WMS_ENABLE_REQUEST": "*"
}
md = collections.OrderedDict(sorted(md.items()))
d = {
"metadata": md,
"__type__": "map"
}
d = collections.OrderedDict(sorted(d.items()))
pp = PrettyPrinter(indent=0, quote="'", newlinechar=" ")
s = pp.pprint(d)
print(s)
assert(s == "MAP METADATA 'MS_ENABLE_MODES' '!*' 'WMS_ENABLE_REQUEST' '*' END END")
def test_end_comment():
s = "MAP LAYER TYPE POINT NAME 'Test' END END"
ast = mappyfile.loads(s)
pp = PrettyPrinter(indent=4, quote='"', newlinechar="\n", end_comment=True)
res = pp.pprint(ast)
print(res)
exp = """MAP
LAYER
TYPE POINT
NAME "Test"
END # LAYER
END # MAP"""
assert res == exp
def test_two_includes():
s = """
MAP
INCLUDE "include1.txt"
INCLUDE "include2.txt"
END
"""
d = mappyfile.loads(s, expand_includes=False)
logging.debug(json.dumps(d, indent=4))
pp = PrettyPrinter(indent=0, newlinechar=" ", quote="'")
output = pp.pprint(d)
print(output)
expected = "MAP INCLUDE 'include1.txt' INCLUDE 'include2.txt' END"
assert(output == expected)
def main():
parser = Parser(try_ply=False)
transformer = MapfileToDict()
pp = PrettyPrinter()
fld = r"C:\Temp\msautotest"
ignore_list = ["wms_inspire_scenario1.map","wms_inspire_scenario2.map"]
mapfiles = glob.glob(fld + '/**/*.map')
mapfiles = [f for f in mapfiles if '.tmp.' not in f]
mapfiles = [f for f in mapfiles if os.path.basename(f) not in ignore_list]
#mapfiles = [f for f in mapfiles if os.path.basename(f) == 'runtime_sub.map']
for fn in mapfiles:
#print fn
ast = parser.parse_file(fn)
def test_processing():
d = {
"name": "ProcessingLayer",
"processing": ["BANDS=1",
"CONTOUR_ITEM=elevation",
"CONTOUR_INTERVAL=20"],
"__type__": "layer"
}
d = collections.OrderedDict(sorted(d.items()))
pp = PrettyPrinter(indent=0, quote="'", newlinechar=" ")
s = pp.pprint(d)
print(s)
assert(s == "LAYER NAME 'ProcessingLayer' PROCESSING 'BANDS=1' PROCESSING 'CONTOUR_ITEM=elevation' PROCESSING 'CONTOUR_INTERVAL=20' END")
def test_print_boolean():
d = {
"transform": True,
"__type__": "layer"
}
pp = PrettyPrinter(indent=0, quote="'", newlinechar=" ")
s = pp.pprint(d)
print(s)
assert(s == "LAYER TRANSFORM TRUE END")
def output(s):
"""
Parse, transform, and pretty print
the result
"""
p = Parser()
m = MapfileToDict(include_position=True)
# https://stackoverflow.com/questions/900392/getting-the-caller-function-name-inside-another-function-in-python
logging.info(inspect.stack()[1][3])
ast = p.parse(s)
logging.debug(ast.pretty())
d = m.transform(ast)
logging.debug(json.dumps(d, indent=4))
pp = PrettyPrinter(indent=0, newlinechar=" ", quote="'")
s = pp.pprint(d)
logging.debug(s)
return s
def _pprint(d, indent, spacer, quote, newlinechar, end_comment, **kwargs):
pp = PrettyPrinter(indent=indent, spacer=spacer,
quote=quote, newlinechar=newlinechar,
end_comment=end_comment, **kwargs)
return pp.pprint(d)