コード例 #1
0
ファイル: cli_jsonstat.py プロジェクト: 26fe/jsonstat.py
def validate(args):
    for arg in args:
        if arg.startswith("http"):
            print("download '{}'".format(arg))
            contents = jsonstat.download(arg)
        else:
            print("reading '{}'".format(arg))
            contents = open(arg).read()
        click.echo("validate '{}'".format(arg))
        jsonstat.validate(contents)
コード例 #2
0
ファイル: cli_jsonstat.py プロジェクト: 26fe/jsonstat.py
def validate(args):
    for arg in args:
        if arg.startswith("http"):
            print("download '{}'".format(arg))
            contents = jsonstat.download(arg)
        else:
            print("reading '{}'".format(arg))
            contents = open(arg).read()
        click.echo("validate '{}'".format(arg))
        jsonstat.validate(contents)
コード例 #3
0
def test_validate():
    examples_jsonstat_org_dir = os.path.join(jsonstat._examples_dir,
                                             "www.json-stat.org")

    for filename in os.listdir(examples_jsonstat_org_dir):
        jsonstat_file = os.path.join(examples_jsonstat_org_dir, filename)
        if os.path.isfile(jsonstat_file) and jsonstat_file.endswith(".json"):
            # print("validating {}".format(jsonstat_file))
            with open(jsonstat_file) as f:
                json_string = f.read()
                try:
                    assert jsonstat.validate(
                        json_string), "validating {}".format(jsonstat_file)
                except jsonstat.JsonStatException:
                    pass
コード例 #4
0
    def test_validate(self):
        fixture_jsonstat_org_dir = os.path.join(self.fixture_dir, "www.json-stat.org")

        for filename in os.listdir(fixture_jsonstat_org_dir):
            jsonstat_file = os.path.join(fixture_jsonstat_org_dir, filename)
            if os.path.isfile(jsonstat_file) and jsonstat_file.endswith(".json"):
                # print("validating {}".format(jsonstat_file))
                with open(jsonstat_file) as f:
                    json_string = f.read()
                    try:
                        ret = jsonstat.validate(json_string)
                        msg = "validating {}".format(jsonstat_file)
                        self.assertTrue(ret, msg)
                    except jsonstat.JsonStatException:
                        pass
コード例 #5
0
    def test_collection_complete(self):
        jsonstat_dimension_sex = {
            "label": "sex",
            "category": {"index": {"M": 0, "F": 1, "T": 2}, "label": {"M": "men", "F": "women", "T": "total"}},
        }

        jsonstat_dataset = {"label": "boh", "dimension": {"sex": jsonstat_dimension_sex}}

        jsonstat_collection = {
            "version": "2.0",
            "class": "collection",
            "href": "http://json-stat.org/samples/oecd-canada-col.json",
            "label": "OECD-Canada Sample Collection",
            "updated": "2015-12-24",
            "link": {"item": [jsonstat_dataset]},
        }
        self.assertTrue(self.validate(jsonstat_collection, [self.__schema.collection]))

        self.assertTrue(jsonstat.validate(jsonstat_collection))
コード例 #6
0
def test_collection_complete():
    jsonstat_dimension_sex = {
        "label": "sex",
        "category": {
            "index": {
                "M": 0,
                "F": 1,
                "T": 2
            },
            "label": {
                "M": "men",
                "F": "women",
                "T": "total"
            }
        }
    }

    jsonstat_dataset = {
        "label": "boh",
        "dimension": {
            "sex": jsonstat_dimension_sex
        }
    }

    jsonstat_collection = {
        "version": "2.0",
        "class": "collection",
        "href": "http://json-stat.org/samples/oecd-canada-col.json",
        "label": "OECD-Canada Sample Collection",
        "updated": "2015-12-24",
        "link": {
            "item": [jsonstat_dataset]
        }
    }

    assert validate(jsonstat_collection, [schema.collection])
    assert jsonstat.validate(jsonstat_collection)