mirror of https://github.com/ARMmbed/mbed-os.git
Fix test errors produced by JSON schema after rebase
- Modified the expected error code in some of the test cases. The error message is now issued by the JSON validator. - Stop validation code being called if no application configuration is given to validate. - Change test mock code to check for specific calls, instead of number of calls. - Derive absolute paths for JSON schema files before loading them, which seems to work better with the URI path resolution of the schema parser.pull/5022/head
parent
7010010ffc
commit
b1ea3881be
|
@ -16,7 +16,9 @@ limitations under the License.
|
|||
"""
|
||||
|
||||
from copy import deepcopy
|
||||
from six import moves
|
||||
import json
|
||||
import six
|
||||
import os
|
||||
from os.path import dirname, abspath, exists, join, isabs
|
||||
import sys
|
||||
|
@ -407,18 +409,23 @@ class Config(object):
|
|||
ConfigException("Could not parse mbed app configuration from %s"
|
||||
% self.app_config_location))
|
||||
|
||||
# Validate the format of the JSON file based on the schema_app.json
|
||||
schema_root = os.path.dirname(__file__)
|
||||
schema_path = os.path.join(schema_root, "schema_app.json")
|
||||
schema_file = json_file_to_dict(schema_path)
|
||||
|
||||
resolver = RefResolver("file://{}/".format(schema_root), schema_file)
|
||||
validator = Draft4Validator(schema_file, resolver=resolver)
|
||||
if self.app_config_location is not None:
|
||||
# Validate the format of the JSON file based on schema_app.json
|
||||
schema_root = os.path.dirname(os.path.abspath(__file__))
|
||||
schema_path = os.path.join(schema_root, "schema_app.json")
|
||||
schema = json_file_to_dict(schema_path)
|
||||
|
||||
errors = sorted(validator.iter_errors(self.app_config_data))
|
||||
url = moves.urllib.request.pathname2url(schema_path)
|
||||
uri = moves.urllib_parse.urljoin("file://", url)
|
||||
|
||||
if errors:
|
||||
raise ConfigException(",".join(x.message for x in errors))
|
||||
resolver = RefResolver(uri, schema)
|
||||
validator = Draft4Validator(schema, resolver=resolver)
|
||||
|
||||
errors = sorted(validator.iter_errors(self.app_config_data))
|
||||
|
||||
if errors:
|
||||
raise ConfigException(",".join(x.message for x in errors))
|
||||
|
||||
# Update the list of targets with the ones defined in the application
|
||||
# config, if applicable
|
||||
|
@ -470,12 +477,14 @@ class Config(object):
|
|||
continue
|
||||
|
||||
# Validate the format of the JSON file based on the schema_lib.json
|
||||
schema_root = os.path.dirname(__file__)
|
||||
schema_root = os.path.dirname(os.path.abspath(__file__))
|
||||
schema_path = os.path.join(schema_root, "schema_lib.json")
|
||||
schema_file = json_file_to_dict(schema_path)
|
||||
|
||||
resolver = RefResolver("file://{}/".format(schema_root),
|
||||
schema_file)
|
||||
url = moves.urllib.request.pathname2url(schema_path)
|
||||
uri = moves.urllib_parse.urljoin("file://", url)
|
||||
|
||||
resolver = RefResolver(uri, schema_file)
|
||||
validator = Draft4Validator(schema_file, resolver=resolver)
|
||||
|
||||
errors = sorted(validator.iter_errors(cfg))
|
||||
|
|
|
@ -53,7 +53,8 @@
|
|||
"type": [
|
||||
"integer",
|
||||
"string",
|
||||
"boolean"
|
||||
"boolean",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"required": {
|
||||
|
@ -70,7 +71,8 @@
|
|||
"type": [
|
||||
"string",
|
||||
"integer",
|
||||
"boolean"
|
||||
"boolean",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"config_parameter_base": {
|
||||
|
@ -90,4 +92,4 @@
|
|||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,16 +5,16 @@
|
|||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"$ref": "file:definitions.json#/name_definition"
|
||||
"$ref": "definitions.json#/name_definition"
|
||||
},
|
||||
"config": {
|
||||
"$ref": "file:definitions.json#/config_definition"
|
||||
"$ref": "definitions.json#/config_definition"
|
||||
},
|
||||
"target_overrides": {
|
||||
"$ref": "file:definitions.json#/target_overrides_definition"
|
||||
"$ref": "definitions.json#/target_overrides_definition"
|
||||
},
|
||||
"macros": {
|
||||
"$ref": "file:definitions.json#/macro_definition"
|
||||
"$ref": "definitions.json#/macro_definition"
|
||||
},
|
||||
"artifact_name": {
|
||||
"type": "string"
|
||||
|
|
|
@ -5,16 +5,16 @@
|
|||
"type": "object",
|
||||
"properties": {
|
||||
"name": {
|
||||
"$ref": "file:definitions.json#/name_definition"
|
||||
"$ref": "definitions.json#/name_definition"
|
||||
},
|
||||
"config": {
|
||||
"$ref": "file:definitions.json#/config_definition"
|
||||
"$ref": "definitions.json#/config_definition"
|
||||
},
|
||||
"target_overrides": {
|
||||
"$ref": "file:definitions.json#/target_overrides_definition"
|
||||
"$ref": "definitions.json#/target_overrides_definition"
|
||||
},
|
||||
"macros": {
|
||||
"$ref": "file:definitions.json#/macro_definition"
|
||||
"$ref": "definitions.json#/macro_definition"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
|
|
@ -108,7 +108,8 @@ def test_init_app_config(target):
|
|||
|
||||
config = Config(target, app_config=app_config)
|
||||
|
||||
mock_json_file_to_dict.assert_called_with(app_config)
|
||||
mock_json_file_to_dict.assert_any_call("app_config")
|
||||
|
||||
assert config.app_config_data == mock_return
|
||||
|
||||
|
||||
|
@ -149,7 +150,7 @@ def test_init_no_app_config_with_dir(target):
|
|||
config = Config(target, [directory])
|
||||
|
||||
mock_isfile.assert_called_with(path)
|
||||
mock_json_file_to_dict.assert_called_once_with(path)
|
||||
mock_json_file_to_dict.assert_any_call(path)
|
||||
assert config.app_config_data == mock_return
|
||||
|
||||
|
||||
|
@ -171,5 +172,5 @@ def test_init_override_app_config(target):
|
|||
|
||||
config = Config(target, [directory], app_config=app_config)
|
||||
|
||||
mock_json_file_to_dict.assert_called_once_with(app_config)
|
||||
mock_json_file_to_dict.assert_any_call(app_config)
|
||||
assert config.app_config_data == mock_return
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"K64F": {
|
||||
"exception_msg": "Unknown key(s)"
|
||||
"exception_msg": "Additional properties are not allowed ('unknown_key' was unexpected)"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"K64F": {
|
||||
"exception_msg": "Unknown key(s)"
|
||||
"exception_msg": "Additional properties are not allowed ('unknown_key' was unexpected)"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue