How to use the mappyfile.validator.Validator 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_validation.py View on Github external
def test_version_warnings():

    s = """MAP
    NAME "sample"
    LAYER
        NAME "test"
        TYPE LINE
        CLASS
            #MADEUP True
            COLOR 0 0 0
        END
    END
END"""

    d = mappyfile.loads(s, include_position=False)
    v = Validator()
    errors = v.validate(d, add_comments=True, version=8.0)
    print(errors)
    assert len(errors) == 1
github geographika / mappyfile / tests / test_validation.py View on Github external
def test_add_comments():
    s = """
    MAP
        IMAGECOLOR 'FF00FF'
        LAYER
            EXTENT 0 0 0
            TYPE POLYGON
        END
    END
    """
    d = to_dict(s)
    v = Validator()
    errors = v.validate(d, add_comments=True)

    print(len(errors))
    print(json.dumps(d, indent=4))

    for error in errors:
        print(error)

    pp = PrettyPrinter(indent=4, quote='"')  # expected

    res = pp.pprint(d)
    print(res)
github geographika / mappyfile / tests / test_sample_maps.py View on Github external
def test_all_maps():

    sample_dir = os.path.join(os.path.dirname(__file__), "sample_maps")

    p = Parser(expand_includes=False)
    m = MapfileToDict(include_position=True)
    v = Validator()

    failing_maps = []

    for fn in os.listdir(sample_dir):
        print(fn)
        try:
            ast = p.parse_file(os.path.join(sample_dir, fn))
            d = m.transform(ast)
            errors = v.validate(d)
            try:
                assert(len(errors) == 0)
            except AssertionError as ex:
                logging.warning("Validation errors in %s ", fn)
                logging.error(ex)
                logging.warning(errors)
        except (BaseException, UnexpectedToken) as ex:
github geographika / mappyfile / tests / test_validation.py View on Github external
FONTSET "../etc/fonts.txt"
    WEB
        IMAGEPATH "/ms4w/tmp/ms_tmp/"
        IMAGEURL "/ms_tmp/"
    END
    LAYER
        NAME "global-raster"
        TYPE RASTER
        STATUS DEFAULT
        DATA "bluemarble.gif"
    END
END"""

    d = mappyfile.loads(s, include_position=True)
    # print(json.dumps(d, indent=4))
    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) == 2)
    print(mappyfile.dumps(d))
github geographika / mappyfile / tests / test_validation.py View on Github external
def test_get_versioned_schema():

    validator = Validator()
    jsn = validator.get_versioned_schema(7.6)
    # print(json.dumps(jsn, indent=4))
    assert "defresolution" in jsn["properties"].keys()
github geographika / mappyfile / tests / test_snippets.py View on Github external
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)

    # 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))
    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
github geographika / mappyfile / tests / test_validation.py View on Github external
def test_cluster_validation():

    s = u"""
    MAP
        LAYER
            CLUSTER
                MAXDISTANCE 50
                REGION "ELLIPSE"
            END
        END
    END
    """

    d = mappyfile.loads(s, include_position=True)
    v = Validator()
    assert d["__position__"]["line"] == 2
    errors = v.validate(d, add_comments=True)
    print(mappyfile.dumps(d))
    assert len(errors) == 0
github geographika / mappyfile / tests / test_symbolset.py View on Github external
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
github geographika / mappyfile / tests / test_validation.py View on Github external
def test_property_versioning():

    properties = {
      "force": {
      "oneOf": [
        {"type": "boolean"},
        {
          "enum": ["group"],
          "metadata": {
            "minVersion": 6.2
          }
        }]
      }
    }

    v = Validator()
    assert "enum" in properties["force"]["oneOf"][1].keys()
    assert len(properties["force"]["oneOf"]) == 2
    properties = v.get_versioned_properties(properties, 6.0)
    print(json.dumps(properties, indent=4))
    assert len(properties["force"]["oneOf"]) == 1