def test_validator_add_extension(self): validator = SchemaValidator(schema=StringSchema()) sub_validator = SchemaValidator(schema=BooleanSchema()) validator.add_extension('name', sub_validator) assert validator._extension_cache == {'name': sub_validator} validator = SchemaValidator(schema=StringSchema()) validator.add_extension('name', schema=BooleanSchema()) assert 'name' in validator._extension_cache assert isinstance(validator._extension_cache['name'], SchemaValidator)
def test_validator_add_extension_errors(self): validator = SchemaValidator(schema=StringSchema()) sub_validator = SchemaValidator(schema=BooleanSchema()) with pytest.raises(ValueError) as info: validator.add_extension('name') assert info.value.args[0] == 'A validator or schema must be specified.' with pytest.raises(ValueError) as info: validator.add_extension('name', validator=sub_validator, schema=BooleanSchema(), url='a-url') assert info.value.args[ 0] == 'Only one form of validator may be specified.' with pytest.raises(ValueError) as info: validator.add_extension('name', validator=sub_validator, schema=BooleanSchema()) assert info.value.args[ 0] == 'Only one form of validator may be specified.' with pytest.raises(ValueError) as info: validator.add_extension('name', schema=BooleanSchema(), url='a-url') assert info.value.args[ 0] == 'Only one form of validator may be specified.' with pytest.raises(ValueError) as info: validator.add_extension('name', validator=sub_validator, url='a-url') assert info.value.args[ 0] == 'Only one form of validator may be specified.'
""" This file provides all our needed config support. """ from pathlib import Path from typing import Dict, Any, List from builder.schema import StringSchema, ObjectSchema, BooleanSchema, OneOfSchema, ArraySchema from builder.schema_validator import SchemaValidator _version_schema = StringSchema().format("semver") _full_dependency_schema = ObjectSchema()\ .properties( location=StringSchema().enum('remote', 'local', 'project'), group=StringSchema().min_length(1), name=StringSchema().min_length(1), classifier=StringSchema().min_length(1), ignore_transients=BooleanSchema(), version=_version_schema, scope=OneOfSchema( StringSchema().min_length(1), ArraySchema().items(StringSchema().min_length(1)) ) )\ .required('location', 'version', 'scope')\ .additional_properties(False) _spec_dependency_schema = ObjectSchema()\ .properties( spec=StringSchema().min_length(1), classifier=StringSchema().min_length(1), ignore_transients=BooleanSchema(), scope=OneOfSchema(
def test_validator_construction_from_schema(self): validator = SchemaValidator(schema=StringSchema()) assert isinstance(validator._schema, dict) assert validator._schema == {"type": "string"}
(2, dict(enum=[1, 2, 3]), None), (3, dict(enum=[1, 2, 3]), None), (None, dict(enum=[1, None, 3]), None), (None, dict(enum=[1, 'null', 3]), None), ('null', dict(enum=[1, None, 3]), None), ('null', dict(enum=[1, 'null', 3]), None), (0, dict(enum=[1, 2, 3]), _em('enum', 'it is not one of [1, 2, 3].')), (None, dict(enum=[1, 2, 3]), _em('enum', 'it is not one of [1, 2, 3].')), ('null', dict(enum=[1, 2, 3]), _em('enum', 'it is not one of [1, 2, 3].')), # const constraint tests. (7, EmptySchema().const(7), None), (8, EmptySchema().const(7), _em('const', 'the value 8 is not 7.')), # String constraints tests. ('string', StringSchema(min_length=6), None), ('bobby', StringSchema(min_length=6), _em('minLength', 'the string is shorter than 6.')), ('string', StringSchema(max_length=6), None), ('string2', StringSchema(max_length=6), _em('maxLength', 'the string is longer than 6.')), ('good', StringSchema(pattern=r'^go'), None), ('bad', StringSchema(pattern=r'^go'), _em('pattern', "it does not match the '^go' pattern.")), ('1.2.3.4', StringSchema(str_format='ipv4'), None), ('1.2.3', StringSchema(str_format='ipv4'), _em('format', 'it does not follow the ipv4 format.')), # Number constraints tests. (7, IntegerSchema(minimum=5), None), (5, IntegerSchema(minimum=5, exclusive_minimum=True), None),
from typing import Sequence, Optional, Dict, Union, Any, MutableMapping, Mapping, List import yaml from builder.models import DependencySet, DependencyContext from builder.config import dependency_schema, conflict_schema, ConflictSet, Configuration, file_condition_schema from builder.schema import ArraySchema, ObjectSchema, OneOfSchema, StringSchema from builder.schema_validator import SchemaValidator from builder.task_module import get_language_module, ModuleSet from builder.utils import global_options _schema = ObjectSchema() \ .properties( info=ObjectSchema() .properties( name=StringSchema().pattern('[a-zA-Z0-9-_]+'), title=StringSchema().min_length(1), version=StringSchema().format('semver'), languages=OneOfSchema( StringSchema().min_length(1), ArraySchema().items(StringSchema().min_length(1)) ) ) .additional_properties(False), dependencies=ObjectSchema() .additional_properties(dependency_schema), conflicts=ObjectSchema() .additional_properties(conflict_schema), conditions=ObjectSchema() .properties( files=ObjectSchema()
""" from builder.schema import EmptySchema, BooleanSchema, IntegerSchema, NumberSchema, StringSchema, Schema, \ ObjectSchema, ArraySchema, AllOfSchema, AnyOfSchema, OneOfSchema, NotSchema, RefSchema _creation_test_cases = [ # Basic schema stuff. (EmptySchema(), {}), (EmptySchema().enum(1, 2, 3), { 'enum': [1, 2, 3] }), (EmptySchema().const('word'), { 'const': 'word' }), (EmptySchema().if_then_else(BooleanSchema(), then_schema=IntegerSchema(), else_schema=StringSchema()), { 'if': { "type": "boolean" }, 'then': { "type": "integer" }, 'else': { "type": "string" }, }), (EmptySchema().ref('#/path/to/thing'), { '$ref': '#/path/to/thing' }), (EmptySchema().add_definition('port', IntegerSchema(minimum=1, maximum=65535)), {
from ..models import Task, Language from builder.utils import end from .java import JavaConfiguration, get_javac_version, java_clean, java_version, PackageConfiguration, \ TestingConfiguration from .init import init_java_project from .version_check import check_dependency_versions from .compile import java_compile from .doc import java_doc from .package import java_package from .resolver import resolve, project_to_dist_dir from .test import compile_tests, run_tests _configuration_schema = ObjectSchema()\ .properties( type=StringSchema().enum('library', 'application').default('library'), source=StringSchema().min_length(1).default('src'), build=StringSchema().min_length(1).default('build'), code_source=StringSchema().min_length(1).default('code'), code_resources=StringSchema().min_length(1).default('resources'), code_target=StringSchema().min_length(1).default('code/classes'), code_doc=StringSchema().min_length(1).default('code/javadoc'), tests_source=StringSchema().min_length(1).default('tests'), test_resources=StringSchema().min_length(1).default('test_resources'), tests_target=StringSchema().min_length(1).default('tests/classes'), dist=StringSchema().min_length(1).default('dist'), app_target=StringSchema().min_length(1).default('app'), lib_target=StringSchema().min_length(1).default('lib') )\ .additional_properties(False)