forked from platformio/platformio-core
DataModel: capture exceptions from failed models in non-strict mode
This commit is contained in:
@ -209,7 +209,12 @@ class DataModel(object):
|
|||||||
raise DataFieldException(
|
raise DataFieldException(
|
||||||
field, "Value `%s` should be type of dictionary" % v
|
field, "Value `%s` should be type of dictionary" % v
|
||||||
)
|
)
|
||||||
result.append(data_type(**v))
|
m = data_type(**v)
|
||||||
|
me = m.get_exceptions()
|
||||||
|
if not me:
|
||||||
|
result.append(m)
|
||||||
|
else:
|
||||||
|
self._exceptions |= set(me)
|
||||||
except DataFieldException as e:
|
except DataFieldException as e:
|
||||||
self._exceptions.add(e)
|
self._exceptions.add(e)
|
||||||
if isinstance(self, StrictDataModel):
|
if isinstance(self, StrictDataModel):
|
||||||
@ -235,7 +240,12 @@ class DataModel(object):
|
|||||||
raise DataFieldException(
|
raise DataFieldException(
|
||||||
field, "Value `%s` should be type of dictionary" % v
|
field, "Value `%s` should be type of dictionary" % v
|
||||||
)
|
)
|
||||||
result[k] = data_type(**v)
|
m = data_type(**v)
|
||||||
|
me = m.get_exceptions()
|
||||||
|
if not me:
|
||||||
|
result[k] = m
|
||||||
|
else:
|
||||||
|
self._exceptions |= set(me)
|
||||||
except DataFieldException as e:
|
except DataFieldException as e:
|
||||||
self._exceptions.add(e)
|
self._exceptions.add(e)
|
||||||
if isinstance(self, StrictDataModel):
|
if isinstance(self, StrictDataModel):
|
||||||
@ -246,8 +256,6 @@ class DataModel(object):
|
|||||||
assert isinstance(other, DataModel)
|
assert isinstance(other, DataModel)
|
||||||
if self.get_field_names() != other.get_field_names():
|
if self.get_field_names() != other.get_field_names():
|
||||||
return False
|
return False
|
||||||
if len(self.get_exceptions()) != len(other.get_exceptions()):
|
|
||||||
return False
|
|
||||||
return self.as_dict() == other.as_dict()
|
return self.as_dict() == other.as_dict()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
@ -265,7 +265,7 @@ def test_library_json_model():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def library_properties_model():
|
def test_library_properties_model():
|
||||||
contents = """
|
contents = """
|
||||||
name=U8glib
|
name=U8glib
|
||||||
version=1.19.1
|
version=1.19.1
|
||||||
@ -315,6 +315,58 @@ architectures=avr,sam
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Broken fields
|
||||||
|
contents = """
|
||||||
|
name=Mozzi
|
||||||
|
version=1.0.3
|
||||||
|
author=Tim Barrass and contributors as documented in source, and at https://github.com/sensorium/Mozzi/graphs/contributors
|
||||||
|
maintainer=Tim Barrass <faveflave@gmail.com>
|
||||||
|
sentence=Sound synthesis library for Arduino
|
||||||
|
paragraph=With Mozzi, you can construct sounds using familiar synthesis units like oscillators, delays, filters and envelopes.
|
||||||
|
category=Signal Input/Output
|
||||||
|
url=https://sensorium.github.io/Mozzi/
|
||||||
|
architectures=*
|
||||||
|
dot_a_linkage=false
|
||||||
|
includes=MozziGuts.h
|
||||||
|
"""
|
||||||
|
data = parser.ManifestParserFactory.new(
|
||||||
|
contents,
|
||||||
|
parser.ManifestFileType.LIBRARY_PROPERTIES,
|
||||||
|
remote_url=(
|
||||||
|
"https://raw.githubusercontent.com/sensorium/Mozzi/"
|
||||||
|
"master/library.properties"
|
||||||
|
),
|
||||||
|
).as_dict()
|
||||||
|
m = model.ManifestModel(**data)
|
||||||
|
assert m.get_exceptions()
|
||||||
|
assert m == model.ManifestModel(
|
||||||
|
**{
|
||||||
|
"name": "Mozzi",
|
||||||
|
"version": "1.0.3",
|
||||||
|
"description": (
|
||||||
|
"Sound synthesis library for Arduino. With Mozzi, you can construct "
|
||||||
|
"sounds using familiar synthesis units like oscillators, delays, "
|
||||||
|
"filters and envelopes."
|
||||||
|
),
|
||||||
|
"repository": {"url": "https://github.com/sensorium/Mozzi", "type": "git"},
|
||||||
|
"platforms": ["*"],
|
||||||
|
"frameworks": ["arduino"],
|
||||||
|
"export": {
|
||||||
|
"exclude": ["extras", "docs", "tests", "test", "*.doxyfile", "*.pdf"],
|
||||||
|
"include": None,
|
||||||
|
},
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"maintainer": True,
|
||||||
|
"email": "faveflave@gmail.com",
|
||||||
|
"name": "Tim Barrass",
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"keywords": ["signal", "input", "output"],
|
||||||
|
"homepage": "https://sensorium.github.io/Mozzi/",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_platform_json_model():
|
def test_platform_json_model():
|
||||||
contents = """
|
contents = """
|
||||||
|
Reference in New Issue
Block a user