Merge "Accept null description in manifest"
This commit is contained in:
commit
06d929f7e2
|
@ -17,6 +17,7 @@ import mock
|
|||
|
||||
from muranopkgcheck.tests import test_validator_helpers as helpers
|
||||
from muranopkgcheck.validators import manifest
|
||||
from muranopkgcheck import yaml_loader
|
||||
|
||||
|
||||
class ManifestValidatorTests(helpers.BaseValidatorTestClass):
|
||||
|
@ -31,6 +32,17 @@ class ManifestValidatorTests(helpers.BaseValidatorTestClass):
|
|||
def test_format_as_number(self):
|
||||
self.g = self.mv._valid_format(1.3)
|
||||
|
||||
def test_description(self):
|
||||
self.g = self.mv._valid_description(yaml_loader.YamlNull())
|
||||
|
||||
def test_description_string(self):
|
||||
self.g = self.mv._valid_description("lalal")
|
||||
|
||||
def test_description_number(self):
|
||||
self.g = self.mv._valid_description(1.3)
|
||||
self.assertIn('Value is not valid string "1.3"',
|
||||
next(self.g).message)
|
||||
|
||||
def test_wrong_format(self):
|
||||
self.g = self.mv._valid_format('0.9')
|
||||
self.assertIn('Not supported format version "0.9"',
|
||||
|
|
|
@ -55,7 +55,7 @@ class BaseValidator(object):
|
|||
pass
|
||||
|
||||
def _valid_string(self, value):
|
||||
if not isinstance(value, (int, float, bool, six.string_types)):
|
||||
if not isinstance(value, six.string_types):
|
||||
yield error.report.E040('Value is not a string "{0}"'
|
||||
.format(value),
|
||||
value)
|
||||
|
|
|
@ -20,6 +20,7 @@ import six
|
|||
|
||||
from muranopkgcheck import error
|
||||
from muranopkgcheck.validators import base
|
||||
from muranopkgcheck import yaml_loader
|
||||
|
||||
|
||||
class ManifestValidator(base.YamlValidator):
|
||||
|
@ -35,11 +36,17 @@ class ManifestValidator(base.YamlValidator):
|
|||
self.add_checker(self._valid_tags, 'Tags', False)
|
||||
self.add_checker(self._valid_require, 'Require', False)
|
||||
self.add_checker(self._valid_type, 'Type')
|
||||
self.add_checker(self._valid_string, 'Description')
|
||||
self.add_checker(self._valid_description, 'Description')
|
||||
self.add_checker(self._valid_ui, 'UI', False)
|
||||
self.add_checker(self._valid_logo, 'Logo', False)
|
||||
self.add_checker(self._valid_logo_ui_existance)
|
||||
|
||||
def _valid_description(self, desc):
|
||||
if not isinstance(desc, six.string_types) and\
|
||||
not isinstance(desc, yaml_loader.YamlNull):
|
||||
yield error.report.E030('Value is not valid string "{0}"'
|
||||
.format(desc), desc)
|
||||
|
||||
def _valid_format(self, value):
|
||||
format_ = str(value).split('/', 1)
|
||||
if len(format_) > 1:
|
||||
|
|
|
@ -35,7 +35,8 @@ class YamlMetadata(object):
|
|||
|
||||
|
||||
class YamlObject(object):
|
||||
pass
|
||||
def __init__(self, value=None):
|
||||
self.value = value
|
||||
|
||||
|
||||
class YamlMapping(YamlObject, dict):
|
||||
|
@ -50,6 +51,11 @@ class YamlString(YamlObject, six.text_type):
|
|||
pass
|
||||
|
||||
|
||||
class YamlNull(YamlObject):
|
||||
def __str__(self):
|
||||
return 'null'
|
||||
|
||||
|
||||
BaseLoader = getattr(yaml, 'CSafeLoader', yaml.SafeLoader)
|
||||
|
||||
|
||||
|
@ -74,6 +80,11 @@ class YamlLoader(BaseLoader):
|
|||
data.update(value)
|
||||
data.__yaml_meta__ = node.start_mark
|
||||
|
||||
def construct_yaml_null(self, node):
|
||||
value = YamlNull(node)
|
||||
value.__yaml_meta__ = node.start_mark
|
||||
return value
|
||||
|
||||
YamlLoader.add_constructor(
|
||||
u'tag:yaml.org,2002:seq',
|
||||
YamlLoader.construct_yaml_seq)
|
||||
|
@ -85,3 +96,7 @@ YamlLoader.add_constructor(
|
|||
YamlLoader.add_constructor(
|
||||
u'tag:yaml.org,2002:map',
|
||||
YamlLoader.construct_yaml_map)
|
||||
|
||||
YamlLoader.add_constructor(
|
||||
u'tag:yaml.org,2002:null',
|
||||
YamlLoader.construct_yaml_null)
|
||||
|
|
Loading…
Reference in New Issue