示例#1
0
def test_validate_float_max():
    goods = [
        PseudoSection('', '0', maxi=0.0),
        PseudoSection('', '0.1', maxi=0.1),
        PseudoSection('', '-0.1', maxi=-0.1),
        PseudoSection('', '-0.1', maxi=0.1),
    ]
    bads = [
        PseudoSection('', '0.10000000001', maxi=0.1),
    ]
    for sec in bads:
        valid, reason = con._validate_float(sec, sec.key, maximum=sec.maxi)
        assert not valid, '{} should not have been a valid '\
            'float'.format(sec.value)
    for sec in goods:
        valid, reason = con._validate_float(sec, sec.key, maximum=sec.maxi)
        assert valid, '{} should have been a valid float, but '\
            'got: {}'.format(sec.value, reason)
示例#2
0
def test_validate_float_simple():
    bads = [
        PseudoSection('', 'NotAFloat'),
    ]
    goods = [
        PseudoSection('', '0'),
        PseudoSection('', '1'), PseudoSection('', '-1'),
        PseudoSection('', '-0.1'), PseudoSection('', '0.1'),
        PseudoSection('', '100000000'), PseudoSection('', '-1000000000'),
        PseudoSection('', '+0'), PseudoSection('', '-0'),
    ]
    for sec in bads:
        valid, reason = con._validate_float(sec, sec.key)
        assert not valid, '{} should not have been a valid '\
            'float'.format(sec.value)
    for sec in goods:
        valid, reason = con._validate_float(sec, sec.key)
        assert valid, '{} should have been a valid float, but '\
            'got: {}'.format(sec.value, reason)