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_pattern():
s = """
STYLE
PATTERN 10 1 50 50 1 50 1 1 END
END
"""
p = Parser()
ast = p.parse(s)
t = MapfileToDict()
d = t.transform(ast)
print(json.dumps(d, indent=4))
assert(len(d["pattern"]) == 4)
assert(len(d["pattern"][0]) == 2)
assert(d["pattern"][0][0] == 10)
def test_token_positions():
s = """
MAP
SIZE 600 600
LAYER
NAME "Test"
TYPE POLYGON
END
END
"""
p = Parser()
ast = p.parse(s)
t = MapfileToDict()
d = t.transform(ast)
print(json.dumps(d, indent=4))
p = Parser()
m = MapfileToDict()
ast = p.parse(s)
d = m.transform(ast)
print(json.dumps(d, indent=4))
def test_empty_config_directive():
"""
Check that a config dict can be added directly without
needing to create a new dict separately
"""
s = """
MAP
NAME 'ConfigMap'
END
"""
p = Parser()
ast = p.parse(s)
t = MapfileToDict()
d = t.transform(ast)
d["config"]["ms_errorfile"] = "stderr"
print(json.dumps(d, indent=4))
assert(d["config"]["ms_errorfile"] == "stderr")
assert(d["config"]["MS_ERRORFILE"] == "stderr")
def test_metadata():
s = """
MAP
METADATA
"wms_enable_request" "*"
"MS_ENABLE_MODES" "!*"
END
END
"""
p = Parser()
ast = p.parse(s)
t = MapfileToDict()
d = t.transform(ast)
print(json.dumps(d, indent=4))
assert(d["metadata"]["wms_enable_request"] == "*")
assert(d["metadata"]["MS_ENABLE_MODES"] == "!*")
assert(d["metadata"]["wms_ENABLE_request"] == "*")
assert(d["metadata"]["MS_enable_MODES"] == "!*")
DEBUG on
NAME Test
shapepath "test/path"
LAYER
CLASSITEM "Test"
CLASS
EXPRESSION "Field"
STYLE
SIZE [sizefield]
END
END
END
END
"""
p = Parser()
m = MapfileToDict()
ast = p.parse(s)
d = m.transform(ast)
print(d)
logging.debug(json.dumps(d, indent=4))
pp = PrettyPrinter(indent=4, quote="'", newlinechar="\n")
res = pp.pprint(d)
print(res)
s = """
MAP
PROJECTION
"proj=utm"
"ellps=GRS80"
"datum=NAD83"
"zone=15"
"units=m"
"north"
"no_defs"
END
END
"""
p = Parser()
ast = p.parse(s)
t = MapfileToDict()
d = t.transform(ast)
print(json.dumps(d, indent=4))
assert(len(d["projection"]) == 7)
def output(s, include_position=True, schema_name="map"):
"""
Parse, transform, validate, and pretty print
the result
"""
p = Parser()
m = MapfileToDict(include_position=include_position)
ast = p.parse(s)
logging.debug(ast.pretty())
d = m.transform(ast)
logging.debug(json.dumps(d, indent=4))
v = Validator()
errors = v.validate(d, schema_name=schema_name)
logging.error(errors)
pp = PrettyPrinter(indent=0, newlinechar=" ", quote="'")
s = pp.pprint(d)
logging.debug(s)
assert(len(errors) == 0)
return s
def test_cstyle_comment():
s = """
MAP
/*
C-style comment 1
*/
NAME "Test"
END
"""
d = mappyfile.loads(s, include_comments=True, include_position=False)
p = Parser(include_comments=True)
m = MapfileToDict(include_position=False, include_comments=True)
ast = p.parse(s)
print(p._comments)
print(ast.pretty())
d = m.transform(ast) # transform the rest
print(json.dumps(d, indent=4))
pp = PrettyPrinter(indent=0, quote="'", newlinechar="\n")
s = pp.pprint(d)
print(s)
assert len(p._comments) == 1
def test_includes():
p = Parser()
ast = p.parse_file('./tests/samples/include1.map')
m = MapfileToDict()
d = (m.transform(ast)) # works
print(mappyfile.dumps(d))
def test_auto_projection():
s = """
MAP
PROJECTION
AUTO
END
END
"""
p = Parser()
ast = p.parse(s)
t = MapfileToDict()
d = t.transform(ast)
print(json.dumps(d, indent=4))
assert(len(d["projection"]) == 1)