Merge "Improve package version validation"

This commit is contained in:
Jenkins 2016-08-31 15:13:23 +00:00 committed by Gerrit Code Review
commit 39142bb6fc
3 changed files with 17 additions and 1 deletions

View File

@ -55,6 +55,11 @@ class ManifestValidatorTests(helpers.BaseValidatorTestClass):
self.g = self.mv._valid_type('Shared Library')
self.assertIn('Type is invalid "Shared Library"', next(self.g).message)
def test_incorrect_package_version(self):
self.g = self.mv._valid_version('a1.3')
self.assertIn('Version format should be compatible with SemVer '
'not "a1.3"', next(self.g).message)
def test_wrong_require_type(self):
self.g = self.mv._valid_require([1, 2, 3])
self.assertIn('Require is not a dict type', next(self.g).message)

View File

@ -14,6 +14,8 @@
import os.path
import semantic_version
import six
from muranopkgcheck import error
@ -26,7 +28,7 @@ class ManifestValidator(base.YamlValidator):
'manifest.yaml$')
self.add_checker(self._valid_format, 'Format', False)
self.add_checker(self._valid_string, 'Author', False)
self.add_checker(self._valid_string, 'Version', False)
self.add_checker(self._valid_version, 'Version', False)
self.add_checker(self._valid_fullname, 'FullName')
self.add_checker(self._valid_string, 'Name', False)
self.add_checker(self._valid_classes, 'Classes', False)
@ -71,6 +73,14 @@ class ManifestValidator(base.YamlValidator):
yield error.report.E071('Type is invalid "{0}"'.format(value),
value)
def _valid_version(self, version):
try:
semantic_version.Version.coerce(str(version))
except ValueError:
yield error.report.E071('Version format should be compatible with '
'SemVer not "{0}"'.format(version),
version)
def _valid_logo_ui_existance(self, ast):
if 'Logo' not in ast:
yield self._valid_logo('logo.png')

View File

@ -7,3 +7,4 @@ PyYAML>=3.1.0 # MIT
yaql>=1.1.0 # Apache 2.0 License
six>=1.9.0 # MIT
stevedore>=1.16.0 # Apache-2.0
semantic_version>=2.3.1 # BSD