Example #1
0
def test_sequence_schema_initial_pass():
    class RegisterField(SequenceSchema):
        sequence = [ElementSchema('spirit:name',
            validator=KeyName(key_names='fieldKey', level=2))]


    class Register(SequenceSchema):
        initial = InitKeyStore('fieldKey')
        sequence = [ElementSchema('spirit:field', validator=RegisterField())]


    utils.reset_message_counters()
    register_path = '/register-0,'
    field0_path = register_path + '/field-0,field0'
    field1_path = register_path + '/field-1,field1'
    field0_name_path = field0_path + '/name-0,field0'
    field1_name_path = field1_path + '/name-1,field1'
    field0 = Element('spirit:field', path=field0_path,
        value=[Element('spirit:name', path=field0_name_path, value='field0')])
    field1 = Element('spirit:field', path=field1_path,
        value=[Element('spirit:name', path=field1_name_path, value='field1')])
    register = Element('register', path=register_path, value=[field0, field1])
    stores = Stores()
    Register().to_python(register.value, path=register.path,
        stores=stores)
    nose.tools.eq_(utils.error_count, 0)
Example #2
0
def test_match_sequence_extra_keys_fail():
    class Test(SequenceSchema):
        sequence = [name, count, wire]

    value_keys = ['name', 'wire', 'extra_key']
    utils.reset_message_counters()
    actual = Test().match_sequence(value_keys, '/')
    nose.tools.eq_([len(actual), utils.error_count], [2, 1])
Example #3
0
def test_choice_basic_two_extra_fail():
    choice = Choice(options=[
        ElementSchema('either', minOccurs=1),
        ElementSchema('or', minOccurs=1),
    ])
    value_key_set = {'extra', 'or'}
    utils.reset_message_counters()
    choice.match_choice_keys(value_key_set)
    nose.tools.eq_(utils.error_count, 1)
Example #4
0
def test_element_schema_validate_attributes_extra_fail():
    utils.reset_message_counters()
    es = ElementSchema('testable',
                       attributes=ElementSchema(
                           'index', validator=PositiveInteger()))
    element = Element('testable', attributes=dict(index='42', refer='extra'))
    # noinspection PyProtectedMember
    es._validate_attributes(element)
    nose.tools.eq_(utils.error_count, 1)
Example #5
0
def test_element_schema_validate_attributes_extra_fail():
    utils.reset_message_counters()
    es = ElementSchema('testable',
                       attributes=ElementSchema('index',
                                                validator=PositiveInteger()))
    element = Element('testable', attributes=dict(index='42', refer='extra'))
    # noinspection PyProtectedMember
    es._validate_attributes(element)
    nose.tools.eq_(utils.error_count, 1)
Example #6
0
def test_match_sequence_basic_two_last_fail():
    class Test(SequenceSchema):
        sequence = [name,
                    Choice(options=[wire, transaction]),
                    count
                    ]

    value_keys = ['name', 'wire', 'transaction']
    utils.reset_message_counters()
    actual = Test().match_sequence(value_keys, '/')
    nose.tools.eq_([len(actual), utils.error_count], [3, 1])
Example #7
0
def test_match_sequence_unused_choice_pass():
    class Test(SequenceSchema):
        sequence = [name,
                    Choice(options=[drive0, load0]),
                    count
                    ]

    value_keys = ['name', 'count']
    utils.reset_message_counters()
    Test().match_sequence(value_keys, '/')
    nose.tools.eq_(utils.error_count, 0)
Example #8
0
def test_check_key_order_warning_pass():
    utils.reset_message_counters()
    value_keys = ['two', 'one', 'three']

    class Test(SequenceSchema):
        pass

    sequence = [
        ElementSchema('one'),
        ElementSchema('two'),
        ElementSchema('three'),
    ]
    Test().check_key_order(value_keys, sequence, '/')
    nose.tools.eq_(utils.warning_count, 1)
Example #9
0
def test_element_schema_validate_fail():
    utils.reset_message_counters()
    es = ElementSchema('testable', validator=PositiveInteger())
    # noinspection PyProtectedMember
    es._validate(es.validator, 'NaN', es.tag, path='/')
    nose.tools.eq_(utils.error_count, 1)
Example #10
0
def test_warning_pass():
    utils.reset_message_counters()
    utils.warning(logger, 'test_warning_state_None')
    nose.tools.eq_(utils.warning_count, 1)
Example #11
0
def test_warning_max_warnings_0_pass():
    utils.reset_message_counters()
    utils.warning(logger, 'test_warning_maxWarnings_0')
    nose.tools.eq_(utils.warning_count, 1)
Example #12
0
def test_choice_missing_required_first_optional_second_fail():
    choice = Choice(options=[[name, load0], [drive0, load0]])
    value_key_set = {'name', 'drive', 'load'}
    utils.reset_message_counters()
    choice.match_choice_keys(value_key_set)
    nose.tools.eq_(utils.error_count, 1)
Example #13
0
def test_choice_missing_required_fail():
    choice = Choice(options=[name, [drive0, timing]])
    value_key_set = {'drive'}
    utils.reset_message_counters()
    choice.match_choice_keys(value_key_set)
    nose.tools.eq_(utils.error_count, 1)
Example #14
0
def test_error_pass():
    utils.reset_message_counters()
    utils.error(logger, 'test_error_state_None')
    nose.tools.eq_(utils.error_count, 1)
Example #15
0
def test_choice_basic_two_both_fail():
    choice = Choice(options=[either, orValidator])
    value_key_set = {'either', 'or'}
    utils.reset_message_counters()
    choice.match_choice_keys(value_key_set)
    nose.tools.eq_(utils.error_count, 1)
Example #16
0
def test_element_schema_validate_fail():
    utils.reset_message_counters()
    es = ElementSchema('testable', validator=PositiveInteger())
    # noinspection PyProtectedMember
    es._validate(es.validator, 'NaN', es.tag, path='/')
    nose.tools.eq_(utils.error_count, 1)
Example #17
0
def test_message_count_info_pass():
    """Noop
    """
    utils.reset_message_counters()
    utils.message_count_info(logger, 'test_message_count_info_state_None')
Example #18
0
def test_message_count_info_errors_abort():
    utils.reset_message_counters()
    utils.error(logger, 'test_message_count_info_errors_abort')
    utils.message_count_info(logger,
                             'test_message_count_info_errors_abort',
                             abort_on_errors=True)
Example #19
0
def test_message_count_info_no_errors():
    utils.reset_message_counters()
    utils.message_count_info(logger, 'test_message_count_info_no_errors')