示例#1
0
def test_validator_rejection_number3_length(
        val, first_invalid_ind, validator_number3: InfoArrayValidator):
    with pytest.raises(ValueError) as validation_failure:
        validator_number3.validate_coerce(val)

    assert ('The prop[%d] property of parent must be in the range [0, 1]' %
            first_invalid_ind in str(validation_failure.value))
示例#2
0
def test_validator_rejection_number3_length(
        val, validator_number3: InfoArrayValidator):
    with pytest.raises(ValueError) as validation_failure:
        validator_number3.validate_coerce(val)

    assert 'must be a list or tuple of length 3.' in str(
        validation_failure.value)
示例#3
0
def test_validator_rejection_number3_length(
        val, first_invalid_ind, validator_number3_free: InfoArrayValidator):
    with pytest.raises(ValueError) as validation_failure:
        validator_number3_free.validate_coerce(val)

    assert (
        "Invalid value of type {typ} received for the 'prop[{first_invalid_ind}]' property of parent"
        .format(typ=type_str(val[first_invalid_ind]),
                first_invalid_ind=first_invalid_ind)) in str(
                    validation_failure.value)
示例#4
0
def validator_any2():
    return InfoArrayValidator('prop',
                              'parent',
                              items=[{
                                  'valType': 'any'
                              }, {
                                  'valType': 'any'
                              }])
def validator_number_free_1d():
    return InfoArrayValidator('prop',
                              'parent',
                              items={
                                  'valType': 'number',
                                  'min': 0,
                                  'max': 1
                              },
                              free_length=True,
                              dimensions=1)
def validator_number2_12d():
    return InfoArrayValidator('prop',
                              'parent',
                              items=[{
                                  'valType': 'number',
                                  'min': 0,
                                  'max': 1
                              }, {
                                  'valType': 'number',
                                  'min': 0,
                                  'max': 1
                              }],
                              free_length=True,
                              dimensions='1-2')
示例#7
0
def validator_number3():
    return InfoArrayValidator('prop',
                              'parent',
                              items=[{
                                  'valType': 'number',
                                  'min': 0,
                                  'max': 1
                              }, {
                                  'valType': 'number',
                                  'min': 0,
                                  'max': 1
                              }, {
                                  'valType': 'number',
                                  'min': 0,
                                  'max': 1
                              }])
示例#8
0
def validator_number3_free():
    return InfoArrayValidator('prop',
                              'parent',
                              items=[{
                                  'valType': 'number',
                                  'min': 0,
                                  'max': 1
                              }, {
                                  'valType': 'number',
                                  'min': 0,
                                  'max': 1
                              }, {
                                  'valType': 'number',
                                  'min': 0,
                                  'max': 1
                              }],
                              free_length=True)
示例#9
0
def test_validator_acceptance_number3(val,
                                      validator_number3: InfoArrayValidator):
    coerce_val = validator_number3.validate_coerce(val)
    assert coerce_val == list(val)
    assert validator_number3.present(coerce_val) == tuple(val)
示例#10
0
def test_validator_rejection_any2_length(val,
                                         validator_any2: InfoArrayValidator):
    with pytest.raises(ValueError) as validation_failure:
        validator_any2.validate_coerce(val)

    assert 'Invalid value' in str(validation_failure.value)
示例#11
0
def test_validator_rejection_any2_type(val,
                                       validator_any2: InfoArrayValidator):
    with pytest.raises(ValueError) as validation_failure:
        validator_any2.validate_coerce(val)

    assert 'must be a list or tuple.' in str(validation_failure.value)
示例#12
0
def test_validator_acceptance_any2(val, validator_any2: InfoArrayValidator):
    coerce_val = validator_any2.validate_coerce(val)
    assert coerce_val == list(val)
    assert validator_any2.present(coerce_val) == tuple(val)
示例#13
0
def test_validator_rejection_any2_type(
        val, validator_number3_free: InfoArrayValidator):
    with pytest.raises(ValueError) as validation_failure:
        validator_number3_free.validate_coerce(val)

    assert 'Invalid value' in str(validation_failure.value)
def validator_any3_free():
    return InfoArrayValidator('prop', 'parent', items=[
        {'valType': 'any'},
        {'valType': 'any'},
        {'valType': 'any'}], free_length=True)