config: Add option for dumping config schema
This makes it easier to compare changes to the schema in different versions. Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
22fdd59ca4
commit
c12bad295f
@ -4,6 +4,7 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import kobo.conf
|
||||
import os
|
||||
import sys
|
||||
@ -95,8 +96,18 @@ def run(config, topdir, has_old):
|
||||
return errors
|
||||
|
||||
|
||||
class DumpSchemaAction(argparse.Action):
|
||||
def __call__(self, parser, ns, values, option_string=None):
|
||||
json.dump(pungi.checks.make_schema(), sys.stdout,
|
||||
sort_keys=True, indent=4)
|
||||
print('')
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
def main(args=None):
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--dump-schema', nargs=0, action=DumpSchemaAction,
|
||||
help='print JSON Schema of configuration and exit')
|
||||
parser.add_argument('config', metavar='CONFIG',
|
||||
help='configuration file to validate')
|
||||
parser.add_argument('--old-composes', action='store_true',
|
||||
|
@ -31,7 +31,7 @@ outline of the process:
|
||||
3. Extra validation can happen in ``validate()`` method of any phase.
|
||||
|
||||
When a new config option is added, the schema must be updated (see the
|
||||
``_make_schema`` function). The dependencies should be encoded into
|
||||
``make_schema`` function). The dependencies should be encoded into
|
||||
``CONFIG_DEPS`` mapping.
|
||||
"""
|
||||
|
||||
@ -188,7 +188,7 @@ def validate(config):
|
||||
|
||||
Undefined values for which a default value exists will be filled in.
|
||||
"""
|
||||
schema = _make_schema()
|
||||
schema = make_schema()
|
||||
DefaultValidator = _extend_with_default_and_alias(jsonschema.Draft4Validator)
|
||||
validator = DefaultValidator(schema,
|
||||
{'array': (tuple, list),
|
||||
@ -393,7 +393,7 @@ class ConfigOptionError(jsonschema.exceptions.ValidationError):
|
||||
pass
|
||||
|
||||
|
||||
def _make_schema():
|
||||
def make_schema():
|
||||
return {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "Pungi Configuration",
|
||||
|
@ -16,6 +16,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
|
||||
from pungi import checks
|
||||
|
||||
|
||||
class CheckDependenciesTestCase(unittest.TestCase):
|
||||
|
||||
def dont_find(self, paths):
|
||||
@ -195,7 +196,7 @@ class TestSchemaValidator(unittest.TestCase):
|
||||
conf.load_from_string(string)
|
||||
return conf
|
||||
|
||||
@mock.patch('pungi.checks._make_schema')
|
||||
@mock.patch('pungi.checks.make_schema')
|
||||
def test_property(self, make_schema):
|
||||
schema = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
@ -218,7 +219,7 @@ class TestSchemaValidator(unittest.TestCase):
|
||||
self.assertEqual(len(warnings), 0)
|
||||
self.assertEqual(config.get("release_name", None), "dummy product")
|
||||
|
||||
@mock.patch('pungi.checks._make_schema')
|
||||
@mock.patch('pungi.checks.make_schema')
|
||||
def test_alias_property(self, make_schema):
|
||||
schema = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
@ -241,7 +242,7 @@ class TestSchemaValidator(unittest.TestCase):
|
||||
self.assertRegexpMatches(warnings[0], r"^WARNING: Config option 'product_name' is deprecated and now an alias to 'release_name'.*")
|
||||
self.assertEqual(config.get("release_name", None), "dummy product")
|
||||
|
||||
@mock.patch('pungi.checks._make_schema')
|
||||
@mock.patch('pungi.checks.make_schema')
|
||||
def test_required_is_missing(self, make_schema):
|
||||
schema = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
@ -265,7 +266,7 @@ class TestSchemaValidator(unittest.TestCase):
|
||||
self.assertEqual(len(warnings), 1)
|
||||
self.assertIn("WARNING: Unrecognized config option: name.", warnings)
|
||||
|
||||
@mock.patch('pungi.checks._make_schema')
|
||||
@mock.patch('pungi.checks.make_schema')
|
||||
def test_required_is_in_alias(self, make_schema):
|
||||
schema = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
@ -289,7 +290,7 @@ class TestSchemaValidator(unittest.TestCase):
|
||||
self.assertRegexpMatches(warnings[0], r"^WARNING: Config option 'product_name' is deprecated and now an alias to 'release_name'.*")
|
||||
self.assertEqual(config.get("release_name", None), "dummy product")
|
||||
|
||||
@mock.patch('pungi.checks._make_schema')
|
||||
@mock.patch('pungi.checks.make_schema')
|
||||
def test_redundant_alias(self, make_schema):
|
||||
schema = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
@ -315,7 +316,7 @@ class TestSchemaValidator(unittest.TestCase):
|
||||
self.assertRegexpMatches(warnings[0], r"^WARNING: Config option 'product_name' is deprecated and now an alias to 'release_name'.*")
|
||||
self.assertEqual(config.get("release_name", None), "dummy product")
|
||||
|
||||
@mock.patch('pungi.checks._make_schema')
|
||||
@mock.patch('pungi.checks.make_schema')
|
||||
def test_properties_in_deep(self, make_schema):
|
||||
schema = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
@ -356,7 +357,7 @@ class TestSchemaValidator(unittest.TestCase):
|
||||
self.assertEqual(config.get("release_name", None), "dummy product")
|
||||
self.assertEqual(config.get("foophase", {}).get("repo", None), "http://www.exampe.com/os")
|
||||
|
||||
@mock.patch('pungi.checks._make_schema')
|
||||
@mock.patch('pungi.checks.make_schema')
|
||||
def test_append_option(self, make_schema):
|
||||
schema = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
@ -396,7 +397,7 @@ class TestSchemaValidator(unittest.TestCase):
|
||||
self.assertEqual(config.get("release_name", None), "dummy product")
|
||||
self.assertEqual(config.get("repo", None), ["http://url/to/repo", "Server"])
|
||||
|
||||
@mock.patch('pungi.checks._make_schema')
|
||||
@mock.patch('pungi.checks.make_schema')
|
||||
def test_append_to_nonexist_option(self, make_schema):
|
||||
schema = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
@ -435,7 +436,7 @@ class TestSchemaValidator(unittest.TestCase):
|
||||
self.assertEqual(config.get("release_name", None), "dummy product")
|
||||
self.assertEqual(config.get("repo", None), ["http://url/to/repo", "Server"])
|
||||
|
||||
@mock.patch('pungi.checks._make_schema')
|
||||
@mock.patch('pungi.checks.make_schema')
|
||||
def test_multiple_appends(self, make_schema):
|
||||
schema = {
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
@ -480,7 +481,7 @@ class TestSchemaValidator(unittest.TestCase):
|
||||
self.assertEqual(config.get("release_name", None), "dummy product")
|
||||
self.assertEqual(config.get("repo", None), ["http://url/to/repo", "Server", "Client"])
|
||||
|
||||
@mock.patch('pungi.checks._make_schema')
|
||||
@mock.patch('pungi.checks.make_schema')
|
||||
def test_anyof_validator_not_raise_our_warnings_as_error(self, make_schema):
|
||||
# https://pagure.io/pungi/issue/598
|
||||
schema = {
|
||||
|
Loading…
Reference in New Issue
Block a user