How to use the mappyfile.loads function in mappyfile

To help you get started, we’ve selected a few mappyfile examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github geographika / mappyfile / tests / test_sample_maps.py View on Github external
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)
github geographika / mappyfile / tests / test_validation.py View on Github external
def test_root_position():
    """
    Check the root objects position is found correctly
    """

    s = """
    MAP
        METADATA
            "wms_title"    "Toronto Landsat 5 TM"
        END
    END
    """

    d = mappyfile.loads(s, include_position=True)
    v = Validator()
    assert d["__position__"]["line"] == 2
    errors = v.validate(d, add_comments=True)
    assert len(errors) == 1
github geographika / mappyfile / tests / test_includes.py View on Github external
def test_includes_no_expand():
    """
    https://github.com/geographika/mappyfile/issues/39
    """
    s = """
    MAP
        INCLUDE "includes/mymapfile.map"
    END
    """

    d = mappyfile.loads(s, expand_includes=False)
    pp = PrettyPrinter(indent=0, newlinechar=" ", quote="'")
    output = pp.pprint(d)

    expected = "MAP INCLUDE 'includes/mymapfile.map' END"
    assert(output == expected)
github geographika / mappyfile / tests / test_utils.py View on Github external
def test_save():

    s = """MAP NAME "TEST" END"""
    d = mappyfile.loads(s)

    output_file = os.path.join(tempfile.mkdtemp(), 'test_mapfile.map')
    mappyfile.save(d, output_file)

    with open(output_file) as fp:
        d = mappyfile.load(fp)

    assert d["name"] == "TEST"
github geographika / mappyfile / tests / test_comments.py View on Github external
def test_metadata_mixed_case_comment():

    txt = """
    METADATA
        'wms_TITLE' 'Title1' # title1
    END
    """

    d = mappyfile.loads(txt, include_comments=True, include_position=False)
    s = mappyfile.dumps(d, indent=0, quote="'", newlinechar="\n")
    expected = """METADATA
'wms_title' 'Title1' # title1
END"""

    assert s == expected
github geographika / mappyfile / tests / test_validation.py View on Github external
NAME "sample"
    LAYER
        NAME "test"
        STATUS DEFAULT
        DATA "SELECT GEOM
        FROM
        TABLE"
        TYPE LINEX
    END
END"""

    p = Parser()
    ast = p.parse(s)
    print(ast)

    d = mappyfile.loads(s, include_position=True)
    v = Validator()
    errors = v.validate(d, add_comments=True)
    print(json.dumps(d, indent=4))
    # print(errors)
    for e in errors:
        print(e)
    assert(len(errors) == 1)
    err = errors[0]
    assert(err["line"] == 9)
    assert(err["column"] == 9)
    print(mappyfile.dumps(d))
github geographika / mappyfile / tests / test_snippets.py View on Github external
def test_single_layer_data():

    s = u"""
    LAYER
        DATA "dataset1"
    END
    """
    jsn = mappyfile.loads(s)
    print(json.dumps(jsn, indent=4))
    jsn["data"][0] = "dataset1"
    print(mappyfile.dumps(jsn))

    print(output(s, schema_name="layer"))
    exp = u"LAYER DATA 'dataset1' END"
    assert(output(s, schema_name="layer") == exp)
github geographika / mappyfile / tests / test_includes.py View on Github external
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)
github geographika / mappyfile / tests / test_pprint.py View on Github external
def test_already_escaped():
    """
    Don't escape an already escaped quote
    """
    s = r'CLASS EXPRESSION "\"Tignish" END'
    ast = mappyfile.loads(s)
    pp = PrettyPrinter(indent=0, quote='"', newlinechar=" ")
    res = pp.pprint(ast)
    exp = r'CLASS EXPRESSION "\"Tignish" END'
    assert(res == exp)

    s = r"CLASS EXPRESSION '\'Tignish' END"
    ast = mappyfile.loads(s)
    pp = PrettyPrinter(indent=0, quote="'", newlinechar=" ")
    res = pp.pprint(ast)
    exp = r"CLASS EXPRESSION '\'Tignish' END"
    assert(res == exp)
github geographika / mappyfile / docs / examples / modifying_values.py View on Github external
layer["name"] = "MyLayer"

print(mappyfile.dumps(mapfile))

# alternatively we can use the Mapfile syntax
# not currently working for CONFIG or METADATA

web = """WEB
        METADATA
            'wms_enable_request' '*'
            'wms_feature_info_mime_type' 'text/html'
            'wms_format' 'image/jpg'
        END
    END"""

web = mappyfile.loads(web)

mapfile["web"] = web
print(mappyfile.dumps(mapfile))

# END OF API EXAMPLE

'''
cfg = """