def test_SchemaSection_validate_unexpected_ignored(dictionary, generic_dictionary, string_io, simple_schema_content, simple_section_content): simple_section_content['sub']['abc'] = 10 schema_section = SchemaSection(dictionary=generic_dictionary, init=simple_schema_content, unexpected_option_validator=Ignore()) section = Section(dictionary=dictionary, init=simple_section_content) validation = schema_section.validate(section) assert not validation assert section['sub'].has_option('abc') assert section['sub']['abc'] == 10
def test_SchemaSection_validate_unexpected(dictionary, generic_dictionary, string_io, simple_schema_content, simple_section_content): simple_section_content['sub']['abc'] = 10 schema_section = SchemaSection(dictionary=generic_dictionary, init=simple_schema_content) section = Section(dictionary=dictionary, init=simple_section_content) validation = schema_section.validate(section) assert isinstance(validation, Validation) assert validation assert len(validation) == 1 assert len(validation['sub']) == 1 assert isinstance(validation['sub']['abc'], UnexpectedOptionError)
def test_SchemaSection_validate_invalid_option(dictionary, generic_dictionary, string_io, simple_schema_content, simple_section_content): simple_section_content['sub']['subsub']['ssx'] = "delta" schema_section = SchemaSection(dictionary=generic_dictionary, init=simple_schema_content) section = Section(dictionary=dictionary, init=simple_section_content) validation = schema_section.validate(section) assert isinstance(validation, Validation) assert validation assert len(validation) == 1 assert len(validation['sub']) == 1 assert len(validation['sub']['subsub']) == 1 assert isinstance(validation['sub']['subsub']['ssx'], InvalidChoiceError)
def test_SchemaSection_validate_unexpected_sub_removed(dictionary, generic_dictionary, string_io, simple_schema_content, simple_section_content): simple_section_content['sub']['ssub'] = {'abc': 10} schema_section = SchemaSection(dictionary=generic_dictionary, init=simple_schema_content, unexpected_option_validator=Remove()) section = Section(dictionary=dictionary, init=simple_section_content) assert section['sub'].has_section('ssub') assert section['sub']['ssub'].has_option('abc') assert section['sub']['ssub']['abc'] == 10 validation = schema_section.validate(section) assert not validation assert section['sub'].has_section('ssub') assert not section['sub']['ssub'].has_option('abc')
def test_SchemaSection_validate_0(dictionary, generic_dictionary, string_io, simple_schema_content, simple_section_content): schema_section = SchemaSection(dictionary=generic_dictionary, init=simple_schema_content) section = Section(dictionary=dictionary, init=simple_section_content) validation = schema_section.validate(section) assert isinstance(validation, Validation) assert not validation
def test_SchemaSection_err(generic_dictionary, string_io, simple_schema_content): init = simple_schema_content init['a'] = 2 with pytest.raises(TypeError) as exc_info: schema_section = SchemaSection(dictionary=generic_dictionary, init=init)
def test_SchemaSection_init(dictionary, string_io, simple_schema_content): schema_section = SchemaSection(dictionary=dictionary, init=simple_schema_content) schema_section.dump() schema_section.dump(stream=string_io) assert string_io.getvalue() == """\
def test_SchemaSection_create(generic_dictionary, string_io): schema_section = SchemaSection(dictionary=generic_dictionary) schema_section.dump(stream=string_io) assert string_io.getvalue() == ""