Exemplo n.º 1
0
    def test_root_elements_required(self):
        flexmock(helper).should_receive('get_file').with_args(
            'foo').and_return({})
        errors = Validator().find_errors('foo')
        messages = [e.message for e in errors]

        assert "'id' is a required property" in messages
        assert "'specversion' is a required property" in messages
        assert "'graph' is a required property" in messages
Exemplo n.º 2
0
def main():
    parser = ArgumentParser()
    parser.add_argument('filename', help='File to validate')
    parser.add_argument('-V', '--version',
                        help='Version of the spec to validate against. Latest by default.',
                        default=settings.DEFAULT_VERSION)
    args = parser.parse_args()

    try:
        validator = Validator(version=args.version)
        errors = validator.find_errors(args.filename)
    except exceptions.SchemaError as e:
        print(str(e), file=sys.stderr)
        sys.exit(1)

    if not errors:
        sys.exit(0)

    for error in errors:
        print('{path}: {msg}'.format(path=' > '.join([str(item) for item in error.path]), msg=error.message))
    sys.exit(1)
Exemplo n.º 3
0
    def test_find_errors_fails(self):
        v = Validator()
        with pytest.raises(exceptions.SchemaError) as e:
            v.find_errors('foo/bar/baz/')

        assert 'No such file' in str(e)
Exemplo n.º 4
0
 def test_find_errors(self):
     v = Validator()
     v.find_errors(helper_test.get_fixture('valid_spec.yaml'))
Exemplo n.º 5
0
 def test_validator_initialization(self, args):
     Validator(**args)
Exemplo n.º 6
0
    def test_find_errors_fails(self):
        v = Validator()
        with pytest.raises(exceptions.SchemaError) as e:
            v.find_errors('foo/bar/baz/')

        assert 'No such file' in str(e)
Exemplo n.º 7
0
 def test_find_errors(self):
     v = Validator()
     v.find_errors(helper_test.get_fixture('valid_spec.yaml'))